PersistenceManager is responsible for
managing the JDO identities of the persistent objects in its cache.
The following methods allow you to interact with the management
of JDO identities.
public Class getObjectIdClass (Class pcClass);
public Object newObjectIdInstance (Class pcClass, Object pkOrString);
This method is used to re-create JDO identity objects from the string
returned by their
method, or, in the case of single field identity, from the primary key
value. Given a persistence-capable class and a JDO
identity string or primary key object, the method constructs a JDO
identity object. Using the
method described below, this identity object can then be
employed to obtain the corresponding persistent instance.
Kodo also allows you to pass the primary key value of datastore identity instance into this method to create a datastore identity object.
public Object getObjectId (Object pc);
public Object getObjectById (Object oid, boolean validate); public Object getObjectById (Object oid);
These methods returns the persistent instance corresponding to the given JDO identity object. If the instance is already cached, the cached version is returned. Otherwise, a new instance is constructed, and may or may not be loaded with data from the datastore.
validate parameter of the method
true, the JDO implementation will throw a
if the datastore record for the given JDO identity does not exist.
Otherwise, the implementation may return a cached object without
validating it. The implementation might return a
hollow instance even when no cached object exists, and an exception
will not be thrown until you attempt to access one of the object's
Invoking the method version without a
parameter is equivalent to using a
public Object getObjectsById (Object oids, boolean validate); public Object getObjectsById (Object oids); public Collection getObjectsById (Collection oids, boolean validate); public Collection getObjectsById (Collection oids);
These method are exactly equivalent to the singular
getObjectById methods, but acts on an array or collection
of identity objects. They may be more efficient than calling the
singular method for each identity object.
public Object getObjectById (Class pcClass, Object pkOrString);
This is a convenience method equivalent to using
newObjectIdInstance to construct an identity object with
Object, then calling
with that identity object and a
true. The code below
demonstrates this equivalence.
PersistenceManager pm = ...; Object pkValue = ...; Object oid = pm.newObjectIdInstance (Magazine.class, pkValue); Magazine mag1 = (Magazine) pm.getObjectById (oid, true); Magazine mag2 = (Magazine) pm.getObjectById (Magazine.class, pkValue); assertTrue (mag1 == mag2);