JDOHelper
java.lang.Object
∟ javax.jdo.JDOHelper
- Implemented Interfaces:
Constants
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.
- Since:
- JDO 1.0
Public Constructors
- Since:
- JDO 2.1
Public Static Methods
- Return:
- the thread-safe singleton JDOHelper
- Since:
- JDO 2.1
Persistent instances of PersistenceCapable
classes have a JDO identity managed by the PersistenceManager
. This method returns a copy of the ObjectId that represents the JDO identity.
Transient instances and instances of classes that do not implement PersistenceCapable
return null
.
The ObjectId may be serialized and later restored, and used with a PersistenceManager
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 a PersistenceManager
from any JDO implementation that supports the PersistenceCapable
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.
- Return:
- a copy of the ObjectId of the parameter instance as of the beginning of the transaction.
- See Also:
PersistenceManager.getObjectId(Object pc)
PersistenceCapable()
PersistenceManager.getObjectById(Object oid,boolean validate)
- Since:
- JDO 1.0
- Parameters:
pcs
- the persistence-capable instances
- Return:
- the object ids of the parameters
- See Also:
getObjectId(Object pc)
getObjectIds(Object[] pcs)
- Since:
- JDO 2.0
- Parameters:
pcs
- the persistence-capable instances
- Return:
- the object ids of the parameters
- See Also:
getObjectId(Object pc)
getObjectIds(Collection pcs)
- Since:
- JDO 2.0
- Parameters:
pc
- The object
- Return:
- The object state
- Since:
- JDO 2.1
PersistenceManager
. Transient non-transactional instances and instances of classes that do not implement PersistenceCapable
return null
.
- Parameters:
pc
- thePersistenceCapable
instance.
- Return:
- the
PersistenceManager
associated with the parameter instance.
- See Also:
PersistenceCapable()
- Since:
- JDO 1.0
- Parameters:
pmfClassLoader
- the ClassLoader used to load resources and classes
- Return:
- the anonymous
PersistenceManagerFactory
.
- See Also:
getPersistenceManagerFactory
- Since:
- JDO 2.1
Thread.currentThread().getContextClassLoader()
as the loader
argument. - Parameters:
propsFile
- the file containing the Properties
- Return:
- the PersistenceManagerFactory
- Since:
- JDO 2.0
loader
. Any IOException
s or FileNotFoundException
s thrown during resource loading will be wrapped in a JDOFatalUserException. - Parameters:
propsFile
- the file containing the Propertiesloader
- the class loader to use to load thePersistenceManagerFactory
class
- Return:
- the PersistenceManagerFactory
- Since:
- JDO 2.0
Thread.currentThread().getContextClassLoader()
as the loader
argument. - Parameters:
stream
- the stream containing the Properties
- Return:
- the PersistenceManagerFactory
- Since:
- JDO 2.0
loader
. Any IOException
s thrown during resource loading will be wrapped in a JDOFatalUserException. - Parameters:
stream
- the stream containing the Propertiesloader
- the class loader to use to load thePersistenceManagerFactory
class
- Return:
- the PersistenceManagerFactory
- Since:
- JDO 2.0
- Parameters:
props
- aProperties
instance with properties of thePersistenceManagerFactory
.
- Return:
- the
PersistenceManagerFactory
.
- See Also:
getPersistenceManagerFactory
- Since:
- JDO 1.0
- Parameters:
props
- aMap
with properties of thePersistenceManagerFactory
.pmfClassLoader
- the class loader used to load thePersistenceManagerFactory
class
- Return:
- the
PersistenceManagerFactory
.
- See Also:
getPersistenceManagerFactory
- Since:
- JDO 1.0
- See Also:
getPersistenceManagerFactory
- Since:
- JDO 2.1
- See Also:
getPersistenceManagerFactory
- Since:
- JDO 2.1
"javax.jdo.PersistenceManagerFactoryClass"
"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",
"javax.jdo.option.PersistenceUnitName".
"javax.jdo.option.DetachAllOnCommit".
"javax.jdo.option.CopyOnAttach".
"javax.jdo.option.TransactionType".
"javax.jdo.option.ServerTimeZoneID".
"javax.jdo.option.Name".
and properties of the form javax.jdo.option.InstanceLifecycleListener.{listenerClass}[=[{pcClasses}]]
where {listenerClass}
is the fully qualified name of a class that implements javax.jdo.listener.InstanceLifecycleListener, and {pcClasses}
is an optional comma- or whitespace-delimited list of persistence-capable classes to be observed; the absence of a value for a property of this form means that instances of all persistence-capable classes will be observed by an instance of the given listener class. 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 JDOFatalUserException
thrown by the method.
The returned PersistenceManagerFactory
is not configurable (the setXXX
methods will throw an exception). This method loads the properties found at name
, if any, via resourceLoader
, and creates a PersistenceManagerFactory with pmfLoader
. Any exceptions thrown during resource loading will be wrapped in a JDOFatalUserException. If multiple PMFs with the requested name are found, a JDOFatalUserException is thrown.
- Parameters:
overrides
- a Map containing properties that override properties defined in any resources loaded according to the "name" parametername
- interpreted as the name of the resource containing the PMF properties, the name of the PMF, or the persistence unit name, in that order; if name is null, blank or whitespace, it is interpreted as indicating the anonymous {@link PersistenceManagerFactory} .resourceLoader
- the class loader to use to load properties file resources; must be non-null ifname
is non-null or blankpmfLoader
- the class loader to use to load the {@link PersistenceManagerFactory} orjavax.persistence.EntityManagerFactory
classes
- Return:
- the {@link PersistenceManagerFactory} with properties in the given resource, with the given name, or with the given persitence unit name
- Since:
- JDO 2.1
- See Also:
getPersistenceManagerFactory
- Since:
- JDO 2.1
- See Also:
getPersistenceManagerFactory
- Since:
- JDO 1.0
- See Also:
getPersistenceManagerFactory
- Since:
- JDO 2.0
- Parameters:
pc
- thePersistenceCapable
instance.
- Return:
- a copy of the ObjectId of the parameter instance as modified in this transaction.
- See Also:
PersistenceCapable()
PersistenceManager.getObjectById(Object oid,boolean validate)
- Since:
- JDO 1.0
- Parameters:
pc
- the instance
- Return:
- the version of the instance
- Since:
- JDO 2.0
true
. Transient instances and instances of classes that do not implement PersistenceCapable
return false
.
- Parameters:
pc
- thePersistenceCapable
instance.
- Return:
-
true
if the parameter instance was deleted in the current transaction.
- See Also:
PersistenceManager.deletePersistent(Object pc)
PersistenceCapable()
- Since:
- JDO 1.0
Transient instances return false.
- Parameters:
pc
- the instance
- Return:
-
true
if this instance is detached.
- See Also:
PersistenceCapable()
- Since:
- JDO 2.0
true
. Transient instances and instances of classes that do not implement PersistenceCapable
return false
.
- Parameters:
pc
- thePersistenceCapable
instance.
- Return:
-
true
if the parameter instance has been modified in the current transaction.
- See Also:
javax.jdo.spi.StateManager.makeDirty(PersistenceCapable pc,String fieldName)
PersistenceCapable()
- Since:
- JDO 1.0
true
. Transient instances and instances of classes that do not implement PersistenceCapable
return false
.
- Parameters:
pc
- thePersistenceCapable
instance.
- Return:
-
true
if the parameter instance was made persistent in the current transaction.
- See Also:
PersistenceManager.makePersistent(Object pc)
PersistenceCapable()
- Since:
- JDO 1.0
true
. Transient instances and instances of classes that do not implement PersistenceCapable
return false
.
- Parameters:
pc
- thePersistenceCapable
instance.
- Return:
-
true
if the parameter instance is persistent.
- See Also:
PersistenceManager.makePersistent(Object pc)
PersistenceCapable()
- Since:
- JDO 1.0
Transient instances and instances of classes that do not implement PersistenceCapable
return false
.
- Parameters:
pc
- thePersistenceCapable
instance.
- Return:
-
true
if the parameter instance is transactional.
- See Also:
PersistenceCapable()
- Since:
- JDO 1.0
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 implement PersistenceCapable
ignore this method.
- Parameters:
pc
- thePersistenceCapable
instance.fieldName
- the name of the field to be marked dirty.
- See Also:
PersistenceCapable(String fieldName)
- Since:
- JDO 1.0