Chapter 1: Basic Concepts in JDO


Overview

Java Data Objects (JDO) defines six interfaces, one helper class, and an inheritance tree of exception classes that application programmers use. For most of these interfaces and classes, the Unified Modeling Language (UML) diagrams presented here will be quite small. Although small, JDO is conceptually interconnected. As a result, application programmers need to understand the implications of its options and operations.

JDO shifts the perspective that application programmers have of an object's persistent state and how to handle it. Application programmers are used to working with datastore interfaces like JDBC where the task is to move state between memory objects and the database. In contrast, JDO provides a persistence service that hides the datastore service. JDO also hides much of the code that activates persistence. Some basic operations of persistence are still exposed. These include beginning transactions, committing transactions, inserting new objects, and deleting preexisting objects. When using JDO, application programs are designed and coded to interact with a persistence service for objects rather than a datastore service for object state.

JDO is small, and the general idea of how it works is simple. JDO uses the toolkit pattern. For the most part, the specification defines interfaces, while the JDO implementations provide classes that implement these interfaces. Figure 1-1 shows the application's view of JDO. This figure shows five (of the six) interfaces that JDO defines for applications: PersistenceManagerFactory, PersistenceManager, Query, Transaction, and InstanceCallbacks. It also shows the PersistenceCapable interface, which is one of the interfaces that JDO defines for the implementation's use rather than the application's use.

click to expand
Figure 1-1: The application's view of JDO

Application programmers create application data classes to model the persistent state and persistent relationships of the entities in the business domain. Application data classes are ordinary Java classes that contain some amount of state and may or may not contain a good deal of behavior. Application data objects are instances of application data classes.

Before application data objects can interact with JDO, they must implement the PersistenceCapable interface. The process of making an application data class implement the PersistenceCapable interface is called enhancement. JDO implementations provide a tool, usually called the enhancer, to enhance application data classes. The tool might create or modify source code files, or it might create or modify compiled class files. However it works, the enhancer has the responsibility to add the code that implements the PersistenceCapable interface. JDO manages the objects of enhanced application data classes through the PersistenceCapable interface.

Most JDO implementations opt to perform byte-code enhancement of the compiled class files. The byte-code enhancers accept as input the compiled class files created by compiling the source files for unenhanced application data classes. They produce as output modified class files whose classes, because of the modifications, implement the PersistenceCapable interface. Byte-code enhancement adds an extra step to the build process.

The enhancer does more than simply add the code that implements the PersistenceCapable interface. It also adds code that enables the objects of application data classes to use the JDO persistence service. It may even add code to classes that are not application data classes if these classes have access to the persistent fields of application data classes. Chapter 5 describes enhancement and the effects it has on application data classes and other application classes.

JDO divides the application's persistence code into two separate areas of concern. In the first area, the application controls the basic operations of persistence. To do this, the application gets a persistence manager factory and from that obtains a persistence manager. The application uses the persistence manager to perform life cycle tasks such as inserting and deleting persistent objects. From the persistence manager, the application obtains query objects to perform queries and the transaction object to control transactions. The PersistenceManagerFactory interface is described in Chapter 6, and the PersistenceManager interface is described in Chapter 3. Queries are covered in Chapter 2, and transactions are covered in Chapter 4.

In the second area of concern, the application defines application data classes. Their primary purpose is to hold persistent state and to model persistent relationships, but they may also define any behavior that is required. The application's designers and programmers can, for the most part, design and code the application data classes just as if persistence were not an issue. In particular, these classes do not derive from any JDO-defined class. The enhancer integrates the application data classes with JDO by inserting all the code required for them to implement the PersistenceCapable interface and to otherwise interact with the JDO persistence service.




Using and Understanding Java Data Objects
Using and Understanding Java Data Objects
ISBN: 1590590430
EAN: 2147483647
Year: 2005
Pages: 156
Authors: David Ezzio

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net