Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
Object
javax.jdo.JDOHelper
public class JDOHelper
extends Object
PersistenceCapable
instances without declaring them to be
PersistenceCapable
.
It is also used to acquire a PersistenceManagerFactory
via
various methods.
This helper class defines static methods that allow a JDO-aware
application to examine the runtime state of instances. For example,
an application can discover whether the instance is persistent,
transactional, dirty, new, deleted, or detached; and to get its associated
PersistenceManager
if it has one.
Method Summary | |
static Object |
|
static Collection |
|
static Object[] |
|
static PersistenceManager |
|
static PersistenceManagerFactory |
|
static PersistenceManagerFactory |
|
static PersistenceManagerFactory |
|
static PersistenceManagerFactory |
|
static PersistenceManagerFactory |
|
static PersistenceManagerFactory |
|
static PersistenceManagerFactory |
|
static PersistenceManagerFactory |
|
static PersistenceManagerFactory |
|
static PersistenceManagerFactory |
|
static PersistenceManagerFactory |
|
static Object |
|
static Object |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static boolean |
|
static void |
|
public static Object getObjectId(Object pc)
Return a copy of the JDO identity associated with the parameter instance. Persistent instances ofPersistenceCapable
classes have a JDO identity managed by thePersistenceManager
. This method returns a copy of the ObjectId that represents the JDO identity. Transient instances and instances of classes that do not implementPersistenceCapable
returnnull
. The ObjectId may be serialized and later restored, and used with aPersistenceManager
from the same JDO implementation to locate a persistent instance with the same data store identity. If the JDO identity is managed by the application, then the ObjectId may be used with aPersistenceManager
from any JDO implementation that supports thePersistenceCapable
class. If the JDO identity is not managed by the application or the data store, then the ObjectId returned is only valid within the current transaction.
- Parameters:
pc
- the PersistenceCapable instance.
- Returns:
- a copy of the ObjectId of the parameter instance as of the beginning of the transaction.
- See Also:
PersistenceManager.getObjectId(Object pc)
,PersistenceCapable.jdoGetObjectId()
,PersistenceManager.getObjectById(Object oid, boolean validate)
public static Collection getObjectIds(Collection pcs)
Get object ids for a collection of instances. For each instance in the parameter, the getObjectId method is called. This method returns one identity instance for each element in the parameter. The order of iteration of the returned Collection exactly matches the order of iteration of the parameter Collection.
- Parameters:
pcs
- the persistence-capable instances
- Returns:
- the object ids of the parameters
- Since:
- 2.0
- See Also:
getObjectId(Object pc)
,getObjectIds(Object[] pcs)
public static Object[] getObjectIds(Object[] pcs)
Get object ids for an array of instances. For each instance in the parameter, the getObjectId method is called. This method returns one identity instance for each element in the parameter. The order of instances of the returned array exactly matches the order of instances of the parameter array.
- Parameters:
pcs
- the persistence-capable instances
- Returns:
- the object ids of the parameters
- Since:
- 2.0
- See Also:
getObjectId(Object pc)
,getObjectIds(Collection pcs)
public static PersistenceManager getPersistenceManager(Object pc)
Return the associatedPersistenceManager
if there is one. Transactional and persistent instances return the associatedPersistenceManager
. Transient non-transactional instances and instances of classes that do not implementPersistenceCapable
returnnull
.
- Parameters:
pc
- thePersistenceCapable
instance.
- Returns:
- the
PersistenceManager
associated with the parameter instance.
public static PersistenceManagerFactory getPersistenceManagerFactory(File propsFile)
Returns aPersistenceManagerFactory
configured based on the properties stored in the file atpropsFile
. This method is equivalent to invokinggetPersistenceManagerFactory(File,ClassLoader)
withThread.currentThread().getContextClassLoader()
as theloader
argument.
- Parameters:
propsFile
- the file containing the Properties
- Returns:
- the PersistenceManagerFactory
- Since:
- 2.0
public static PersistenceManagerFactory getPersistenceManagerFactory(File propsFile, ClassLoader loader)
Returns aPersistenceManagerFactory
configured based on the properties stored in the file atpropsFile
. Creates aPersistenceManagerFactory
withloader
. AnyIOException
s orFileNotFoundException
s thrown during resource loading will be wrapped in aJDOFatalUserException
.
- Parameters:
propsFile
- the file containing the Propertiesloader
- the class loader to use to load thePersistenceManagerFactory
class
- Returns:
- the PersistenceManagerFactory
- Since:
- 2.0
public static PersistenceManagerFactory getPersistenceManagerFactory(InputStream stream)
Returns aPersistenceManagerFactory
configured based on the Properties stored in the input stream atstream
. This method is equivalent to invokinggetPersistenceManagerFactory(InputStream,ClassLoader)
withThread.currentThread().getContextClassLoader()
as theloader
argument.
- Parameters:
stream
- the stream containing the Properties
- Returns:
- the PersistenceManagerFactory
- Since:
- 2.0
public static PersistenceManagerFactory getPersistenceManagerFactory(InputStream stream, ClassLoader loader)
Returns aPersistenceManagerFactory
configured based on the Properties stored in the input stream atstream
. Creates aPersistenceManagerFactory
withloader
. AnyIOException
s thrown during resource loading will be wrapped in aJDOFatalUserException
.
- Parameters:
stream
- the stream containing the Propertiesloader
- the class loader to use to load thePersistenceManagerFactory
class
- Returns:
- the PersistenceManagerFactory
- Since:
- 2.0
public static PersistenceManagerFactory getPersistenceManagerFactory(Map props)
Get aPersistenceManagerFactory
based on aProperties
instance, using the current thread's context class loader to locate thePersistenceManagerFactory
class.
- Parameters:
props
- aProperties
instance with properties of thePersistenceManagerFactory
.
- Returns:
- the
PersistenceManagerFactory
.
public static PersistenceManagerFactory getPersistenceManagerFactory(Map props, ClassLoader cl)
Get aPersistenceManagerFactory
based on aProperties
instance and a class loader. The following are standard key values:"javax.jdo.PersistenceManagerFactoryClass"
JDO implementations are permitted to define key values of their own. Any key values not recognized by the implementation must be ignored. Key values that are recognized but not supported by an implementation must result in a
"javax.jdo.option.Optimistic",
"javax.jdo.option.RetainValues",
"javax.jdo.option.RestoreValues",
"javax.jdo.option.IgnoreCache",
"javax.jdo.option.NontransactionalRead",
"javax.jdo.option.NontransactionalWrite",
"javax.jdo.option.Multithreaded",
"javax.jdo.option.ConnectionUserName",
"javax.jdo.option.ConnectionPassword",
"javax.jdo.option.ConnectionURL",
"javax.jdo.option.ConnectionFactoryName",
"javax.jdo.option.ConnectionFactory2Name",
"javax.jdo.option.Mapping",
"javax.jdo.mapping.Catalog",
"javax.jdo.mapping.Schema".JDOFatalUserException
thrown by the method. The returnedPersistenceManagerFactory
is not configurable (thesetXXX
methods will throw an exception). JDO implementations might manage a map of instantiatedPersistenceManagerFactory
instances based on specified property key values, and return a previously instantiatedPersistenceManagerFactory
instance. In this case, the properties of the returned instance must exactly match the requested properties.
- Parameters:
props
- aProperties
instance with properties of thePersistenceManagerFactory
.cl
- the class loader to use to load thePersistenceManagerFactory
class
- Returns:
- the
PersistenceManagerFactory
.
public static PersistenceManagerFactory getPersistenceManagerFactory(String propsResource)
Returns aPersistenceManagerFactory
configured based on the properties stored in the resource atpropsResource
. This method is equivalent to invokinggetPersistenceManagerFactory(String,ClassLoader)
withThread.currentThread().getContextClassLoader()
as theloader
argument.
- Parameters:
propsResource
- the resource containing the Properties
- Returns:
- the PersistenceManagerFactory
- Since:
- 2.0
public static PersistenceManagerFactory getPersistenceManagerFactory(String propsResource, ClassLoader loader)
Returns aPersistenceManagerFactory
configured based on the properties stored in the resource atpropsResource
. Loads the resource vialoader
, and creates aPersistenceManagerFactory
withloader
. AnyIOException
s thrown during resource loading will be wrapped in aJDOFatalUserException
.
- Parameters:
propsResource
- the resource containing the Propertiesloader
- the class loader to use to load both the propsResource and thePersistenceManagerFactory
class
- Returns:
- the PersistenceManagerFactory
- Since:
- 2.0
public static PersistenceManagerFactory getPersistenceManagerFactory(String propsResource, ClassLoader propsLoader, ClassLoader pmfLoader)
Returns aPersistenceManagerFactory
configured based on the properties stored in the resource atpropsResource
. Loads the Properties viapropsLoader
, and creates aPersistenceManagerFactory
withpmfLoader
. AnyIOException
s thrown during resource loading will be wrapped in aJDOFatalUserException
.
- Parameters:
propsResource
- the resource containing the PropertiespropsLoader
- the class loader to use to load the propsResourcepmfLoader
- the class loader to use to load thePersistenceManagerFactory
class
- Returns:
- the PersistenceManagerFactory
- Since:
- 2.0
public static PersistenceManagerFactory getPersistenceManagerFactory(String jndiLocation, Context context)
Returns aPersistenceManagerFactory
at the JNDI location specified byjndiLocation
in the contextcontext
. Ifcontext
isnull
,new InitialContext()
will be used. This method is equivalent to invokinggetPersistenceManagerFactory(String,Context,ClassLoader)
withThread.currentThread().getContextClassLoader()
as theloader
argument.
- Parameters:
jndiLocation
- the JNDI location containing the PersistenceManagerFactorycontext
- the context in which to find the named PersistenceManagerFactory
- Returns:
- the PersistenceManagerFactory
- Since:
- 2.0
public static PersistenceManagerFactory getPersistenceManagerFactory(String jndiLocation, Context context, ClassLoader loader)
Returns aPersistenceManagerFactory
at the JNDI location specified byjndiLocation
in the contextcontext
. Ifcontext
isnull
,new InitialContext()
will be used. Creates aPersistenceManagerFactory
withloader
. AnyNamingException
s thrown will be wrapped in aJDOFatalUserException
.
- Parameters:
jndiLocation
- the JNDI location containing the PersistenceManagerFactorycontext
- the context in which to find the named PersistenceManagerFactoryloader
- the class loader to use to load thePersistenceManagerFactory
class
- Returns:
- the PersistenceManagerFactory
- Since:
- 2.0
public static Object getTransactionalObjectId(Object pc)
Return a copy of the JDO identity associated with the parameter instance.
- Parameters:
pc
- thePersistenceCapable
instance.
- Returns:
- a copy of the ObjectId of the parameter instance as modified in this transaction.
- See Also:
PersistenceCapable.jdoGetTransactionalObjectId()
,PersistenceManager.getObjectById(Object oid, boolean validate)
public static Object getVersion(Object pc)
Return the version of the instance.
- Parameters:
pc
- the instance
- Returns:
- the version of the instance
- Since:
- 2.0
public static boolean isDeleted(Object pc)
Tests whether the parameter instance has been deleted. Instances that have been deleted in the current transaction returntrue
. Transient instances and instances of classes that do not implementPersistenceCapable
returnfalse
.
- Parameters:
pc
- thePersistenceCapable
instance.
- Returns:
true
if the parameter instance was deleted in the current transaction.
- See Also:
PersistenceManager.deletePersistent(Object pc)
,PersistenceCapable.jdoIsDeleted()
public static boolean isDetached(Object pc)
Tests whether the parameter instance has been detached. Instances that have been detached return true. Transient instances return false.
- Parameters:
pc
- the instance
- Returns:
true
if this instance is detached.
- Since:
- 2.0
- See Also:
PersistenceCapable.jdoIsDetached()
public static boolean isDirty(Object pc)
Tests whether the parameter instance is dirty. Instances that have been modified, deleted, or newly made persistent in the current transaction returntrue
. Transient instances and instances of classes that do not implementPersistenceCapable
returnfalse
.
- Parameters:
pc
- thePersistenceCapable
instance.
- Returns:
true
if the parameter instance has been modified in the current transaction.
- See Also:
javax.jdo.spi.StateManager.makeDirty(PersistenceCapable pc, String fieldName)
,PersistenceCapable.jdoIsDirty()
public static boolean isNew(Object pc)
Tests whether the parameter instance has been newly made persistent. Instances that have been made persistent in the current transaction returntrue
. Transient instances and instances of classes that do not implementPersistenceCapable
returnfalse
.
- Parameters:
pc
- thePersistenceCapable
instance.
- Returns:
true
if the parameter instance was made persistent in the current transaction.
- See Also:
PersistenceManager.makePersistent(Object pc)
,PersistenceCapable.jdoIsNew()
public static boolean isPersistent(Object pc)
Tests whether the parameter instance is persistent. Instances that represent persistent objects in the data store returntrue
. Transient instances and instances of classes that do not implementPersistenceCapable
returnfalse
.
- Parameters:
pc
- thePersistenceCapable
instance.
- Returns:
true
if the parameter instance is persistent.
- See Also:
PersistenceManager.makePersistent(Object pc)
,PersistenceCapable.jdoIsPersistent()
public static boolean isTransactional(Object pc)
Tests whether the parameter instance is transactional. Instances whose state is associated with the current transaction return true. Transient instances and instances of classes that do not implementPersistenceCapable
returnfalse
.
- Parameters:
pc
- thePersistenceCapable
instance.
- Returns:
true
if the parameter instance is transactional.
public static void makeDirty(Object pc, String fieldName)
Explicitly mark the parameter instance and field dirty. Normally,PersistenceCapable
classes are able to detect changes made to their fields. However, if a reference to an array is given to a method outside the class, and the array is modified, then the persistent instance is not aware of the change. This API allows the application to notify the instance that a change was made to a field. Transient instances and instances of classes that do not implementPersistenceCapable
ignore this method.
- Parameters:
pc
- thePersistenceCapable
instance.fieldName
- the name of the field to be marked dirty.
- See Also:
PersistenceCapable.jdoMakeDirty(String fieldName)