JPOX
JPOX
 Project  |  Ver 1.1  |  Ver 1.2  |  JDO  |  JPA  |  Guides  |  Tools
1.1 | Preparation | O/R Mapping | Runtime | Extensions | Developer
Development
Testing
JPOX Design : Second Class Objects

JPOX supports objects to be persisted as either First-Class (FCO) or Second-Class (SCO) objects. A second class is an object that has no identity of its own.

Persistence Process

When a user makes a class PersistenceCapable and tries to persist an object of that type any fields that are second-class objects and that are mutable need to be intercepted so that JPOX can pass any updates to the internals of the object through to the datastore. Let's take an example, a user has a class that has a Collection field. When an object of this class is persisted, the following process is followed.

  • PersistenceManager.makePersistent called to persist the object.
  • StateManager.makePersistent called for the object, which generates an InsertRequest for the object.
  • InsertRequest generates an INSERT statement and tries to populate the values to be inserted.
  • "Mapping".postInsert is called for all mappings of all fields in the class of the object. This allows JPOX time to persist any related objects. In our example this means that it now will persist to the datastore the contents of the collection (since it isn't typically stored in the same table as the main object). This step terminates by replacing the java.util.Collection in the field of the object with a proxy wrapper org.jpox.sco.Collection that can intercept any updates to the Collection thereafter while within the transaction.
Proxy Wrappers

When an object that has a mutable SCO field is enlisted in a transaction it's mutable SCO fields will be replaced by proxy wrappers for their java types. This means that JPOX can detect any further updates to the underlying internals of the object. For example, we have an object with a Collection field, and it is enlisted in a transaction. We then call add() on the Collection. This is then detected by our proxy wrapper class and we can also persist the added collection element direct to the datastore.