Chapter 6. JDOHelper

6.1. Persistence-Capable Operations
6.2. Lifecycle Operations
6.3. PersistenceManagerFactory Construction

Kodo includes the KodoJDOHelper helper class to provide additional utility methods.

Applications use the JDOHelper for three types of operations: persistence-capable operations, lifecycle operations, and PersistenceManagerFactory construction. We investigate each below.

6.1. Persistence-Capable Operations

public static void makeDirty (Object pc, String fieldName);
public static Object getObjectId (Object pc);
public static Object getVersion (Object pc);
public static PersistenceManager getPersistenceManager (Object pc);

We have already seen the first two persistence-capable operations, makeDirty and getObjectId. Given a persistence-capable object and the name of the field that has been modified, the makeDirty method notifies the JDO implementation that the field's value has changed so that it can write the new value to the datastore. JDO usually tracks field modifications automatically; the only time you are required to use this method is when you assign a new value to some index of a persistent array.

The getObjectId method returns the JDO identity object for the persistence-capable instance given as an argument. If the given instance is not persistent, this method returns null.


Under some settings, your JDO implementation may have to insert a newly-persisted object into the datastore before it can determine the object's JDO identity. Thus, calling JDOHelper.getObjectId on an object that has been made persistent in the current transaction might cause the PersistenceManager to flush. Flushing is described in Chapter 8, PersistenceManager.

The getVersion method returns the version object of the given persistence-capable instance. Version objects are used to ensure that concurrent optimistic transactions don't overwrite each other's changes. For more information on optimistic transactions, see Section 9.1, “Transaction Types”. Standard JDO versioning strategies are discussed in Section 15.10, “Version”.

If the argument to getVersion is not persistent or does not have a version, the method returns null.

The final persistence-capable operation, getPersistenceManager, is self-explanatory. It simply returns the PersistenceManager that is managing the persistence-capable object supplied as an argument. If the argument is a transient object, meaning it is not managed by a PersistenceManager, null is returned.


Skip navigation bar   Back to Top