Class JDOHelper
- java.lang.Object
-
- javax.jdo.JDOHelper
-
- All Implemented Interfaces:
Constants
public class JDOHelper extends java.lang.Object implements Constants
This class can be used by a JDO-aware application to call the JDO behavior ofPersistenceCapableinstances without declaring them to bePersistenceCapable.It is also used to acquire a
PersistenceManagerFactoryvia 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
PersistenceManagerif it has one.- Version:
- 2.1
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.util.MapATTRIBUTE_PROPERTY_XREFA mapping from jdoconfig.xsd element attributes to PMF properties.(package private) static JDOImplHelper.StateInterrogationObjectReturngetObjectIdThe stateless instance used for handling non-binary-compatible implementations of getObjectId.(package private) static JDOImplHelper.StateInterrogationObjectReturngetPersistenceManagerThe stateless instance used for handling non-binary-compatible implementations of getPersistenceManager.(package private) static JDOImplHelper.StateInterrogationObjectReturngetTransactionalObjectIdThe stateless instance used for handling non-binary-compatible implementations of getTransactionalObjectId.(package private) static JDOImplHelper.StateInterrogationObjectReturngetVersionThe stateless instance used for handling non-binary-compatible implementations of getVersion.private static JDOImplHelperimplHelperThe JDOImplHelper instance used for handling non-binary-compatible implementations.private static JDOHelperinstanceThe singleton instance of JDOHelper.(package private) static JDOImplHelper.StateInterrogationBooleanReturnisDeletedThe stateless instance used for handling non-binary-compatible implementations of isDeleted.(package private) static JDOImplHelper.StateInterrogationBooleanReturnisDetachedThe stateless instance used for handling non-binary-compatible implementations of isDetached.(package private) static JDOImplHelper.StateInterrogationBooleanReturnisDirtyThe stateless instance used for handling non-binary-compatible implementations of isDirty.(package private) static JDOImplHelper.StateInterrogationBooleanReturnisNewThe stateless instance used for handling non-binary-compatible implementations of isNew.(package private) static JDOImplHelper.StateInterrogationBooleanReturnisPersistentThe stateless instance used for handling non-binary-compatible implementations of isPersistent.(package private) static JDOImplHelper.StateInterrogationBooleanReturnisTransactionalThe stateless instance used for handling non-binary-compatible implementations of isTransactional.private static I18NHelpermsgThe Internationalization message helper.-
Fields inherited from interface javax.jdo.Constants
ANONYMOUS_PERSISTENCE_MANAGER_FACTORY_NAME, ELEMENT_INSTANCE_LIFECYCLE_LISTENER, ELEMENT_PERSISTENCE_MANAGER_FACTORY, ELEMENT_PROPERTY, INSTANCE_LIFECYCLE_LISTENER_ATTRIBUTE_CLASSES, INSTANCE_LIFECYCLE_LISTENER_ATTRIBUTE_LISTENER, JDO_DTD_RESOURCE, JDO_XSD_NS, JDO_XSD_RESOURCE, JDOCONFIG_DTD_RESOURCE, JDOCONFIG_RESOURCE_NAME, JDOCONFIG_XSD_NS, JDOCONFIG_XSD_RESOURCE, JDOQUERY_DTD_RESOURCE, JDOQUERY_XSD_NS, JDOQUERY_XSD_RESOURCE, JTA, NONCONFIGURABLE_PROPERTY_VENDOR_NAME, NONCONFIGURABLE_PROPERTY_VERSION_NUMBER, OPTION_APPLICATION_IDENTITY, OPTION_ARRAY, OPTION_ARRAYLIST, OPTION_BINARY_COMPATIBILITY, OPTION_CHANGE_APPLICATION_IDENTITY, OPTION_DATASTORE_IDENTITY, OPTION_GET_DATASTORE_CONNECTION, OPTION_GET_JDBC_CONNECTION, OPTION_LINKEDLIST, OPTION_MAPPING_HETEROGENEOUS_INTERFACE_TYPE, OPTION_MAPPING_HETEROGENEOUS_OBJECT_TYPE, OPTION_MAPPING_JOINED_TABLE_PER_CLASS, OPTION_MAPPING_JOINED_TABLE_PER_CONCRETE_CLASS, OPTION_MAPPING_NON_JOINED_TABLE_PER_CONCRETE_CLASS, OPTION_MAPPING_RELATION_SUBCLASS_TABLE, OPTION_NONDURABLE_IDENTITY, OPTION_NONTRANSACTIONAL_READ, OPTION_NONTRANSACTIONAL_WRITE, OPTION_NULL_COLLECTION, OPTION_OPTIMISTIC, OPTION_PREDIRTY_EVENT, OPTION_QUERY_SQL, OPTION_RETAIN_VALUES, OPTION_TRANSACTIONAL_TRANSIENT, OPTION_TREEMAP, OPTION_TREESET, OPTION_UNCONSTRAINED_QUERY_VARIABLES, OPTION_VECTOR, OPTION_VERSION_DATETIME, OPTION_VERSION_STATE_IMAGE, ORM_DTD_RESOURCE, ORM_XSD_NS, ORM_XSD_RESOURCE, PMF_ATTRIBUTE_CLASS, PMF_ATTRIBUTE_CONNECTION_DRIVER_NAME, PMF_ATTRIBUTE_CONNECTION_FACTORY_NAME, PMF_ATTRIBUTE_CONNECTION_FACTORY2_NAME, PMF_ATTRIBUTE_CONNECTION_PASSWORD, PMF_ATTRIBUTE_CONNECTION_URL, PMF_ATTRIBUTE_CONNECTION_USER_NAME, PMF_ATTRIBUTE_COPY_ON_ATTACH, PMF_ATTRIBUTE_DETACH_ALL_ON_COMMIT, PMF_ATTRIBUTE_IGNORE_CACHE, PMF_ATTRIBUTE_MAPPING, PMF_ATTRIBUTE_MULTITHREADED, PMF_ATTRIBUTE_NAME, PMF_ATTRIBUTE_NONTRANSACTIONAL_READ, PMF_ATTRIBUTE_NONTRANSACTIONAL_WRITE, PMF_ATTRIBUTE_OPTIMISTIC, PMF_ATTRIBUTE_PERSISTENCE_UNIT_NAME, PMF_ATTRIBUTE_READONLY, PMF_ATTRIBUTE_RESTORE_VALUES, PMF_ATTRIBUTE_RETAIN_VALUES, PMF_ATTRIBUTE_SERVER_TIME_ZONE_ID, PROPERTY_ATTRIBUTE_NAME, PROPERTY_ATTRIBUTE_VALUE, PROPERTY_CONNECTION_DRIVER_NAME, PROPERTY_CONNECTION_FACTORY_NAME, PROPERTY_CONNECTION_FACTORY2_NAME, PROPERTY_CONNECTION_PASSWORD, PROPERTY_CONNECTION_URL, PROPERTY_CONNECTION_USER_NAME, PROPERTY_COPY_ON_ATTACH, PROPERTY_DETACH_ALL_ON_COMMIT, PROPERTY_IGNORE_CACHE, PROPERTY_INSTANCE_LIFECYCLE_LISTENER, PROPERTY_MAPPING, PROPERTY_MAPPING_CATALOG, PROPERTY_MAPPING_SCHEMA, PROPERTY_MULTITHREADED, PROPERTY_NAME, PROPERTY_NONTRANSACTIONAL_READ, PROPERTY_NONTRANSACTIONAL_WRITE, PROPERTY_OPTIMISTIC, PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS, PROPERTY_PERSISTENCE_UNIT_NAME, PROPERTY_PREFIX_INSTANCE_LIFECYCLE_LISTENER, PROPERTY_READONLY, PROPERTY_RESTORE_VALUES, PROPERTY_RETAIN_VALUES, PROPERTY_SERVER_TIME_ZONE_ID, PROPERTY_SPI_RESOURCE_NAME, PROPERTY_TRANSACTION_ISOLATION_LEVEL, PROPERTY_TRANSACTION_ISOLATION_LEVEL_READ_COMMITTED, PROPERTY_TRANSACTION_ISOLATION_LEVEL_READ_UNCOMMITTED, PROPERTY_TRANSACTION_ISOLATION_LEVEL_REPEATABLE_READ, PROPERTY_TRANSACTION_ISOLATION_LEVEL_SERIALIZABLE, PROPERTY_TRANSACTION_ISOLATION_LEVEL_SNAPSHOT, RESOURCE_LOCAL, SERVICE_LOOKUP_PMF_RESOURCE_NAME, TX_READ_COMMITTED, TX_READ_UNCOMMITTED, TX_REPEATABLE_READ, TX_SERIALIZABLE, TX_SNAPSHOT
-
-
Constructor Summary
Constructors Constructor Description JDOHelper()Some applications might prefer to use instance methods instead of static methods.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static java.util.MapcreateAttributePropertyXref()Creates a map from jdoconfig.xsd element attributes to PMF properties.private static java.lang.ClassforName(java.lang.String name, boolean init, java.lang.ClassLoader loader)Get the named class.protected static java.lang.StringgetClassNameFromURL(java.net.URL url)Get a class name from a URL.private static java.lang.ClassLoadergetContextClassLoader()Get the context class loader associated with the current thread.protected static javax.xml.parsers.DocumentBuilderFactorygetDefaultDocumentBuilderFactory()protected static org.xml.sax.ErrorHandlergetDefaultErrorHandler()protected static javax.xml.parsers.DocumentBuilderFactorygetDocumentBuilderFactory()protected static org.xml.sax.ErrorHandlergetErrorHandler()static JDOHelpergetInstance()Return the singleton instance of JDOHelper.private static java.lang.reflect.MethodgetMethod(java.lang.Class implClass, java.lang.String methodName, java.lang.Class[] parameterTypes)Get the named Method from the named class.protected static java.util.MapgetNamedPMFProperties(java.lang.String name, java.lang.ClassLoader resourceLoader, java.lang.String jdoconfigResourceName)Find and return the namedPersistenceManagerFactory's properties, or null if not found.static java.lang.ObjectgetObjectId(java.lang.Object pc)Return a copy of the JDO identity associated with the parameter instance.static java.lang.Object[]getObjectIds(java.lang.Object[] pcs)Get object ids for an array of instances.static java.util.CollectiongetObjectIds(java.util.Collection pcs)Get object ids for a collection of instances.static ObjectStategetObjectState(java.lang.Object pc)Accessor for the state of the passed object.static PersistenceManagergetPersistenceManager(java.lang.Object pc)Return the associatedPersistenceManagerif there is one.static PersistenceManagerFactorygetPersistenceManagerFactory()Get the anonymousPersistenceManagerFactoryconfigured via the standard configuration file resource "META-INF/jdoconfig.xml", using the current thread's context class loader to locate the configuration file resource(s).static PersistenceManagerFactorygetPersistenceManagerFactory(java.io.File propsFile)Returns aPersistenceManagerFactoryconfigured based on the properties stored in the file atpropsFile.static PersistenceManagerFactorygetPersistenceManagerFactory(java.io.File propsFile, java.lang.ClassLoader loader)Returns aPersistenceManagerFactoryconfigured based on the properties stored in the file atpropsFile.static PersistenceManagerFactorygetPersistenceManagerFactory(java.io.InputStream stream)Returns aPersistenceManagerFactoryconfigured based on the Properties stored in the input stream atstream.static PersistenceManagerFactorygetPersistenceManagerFactory(java.io.InputStream stream, java.lang.ClassLoader loader)Returns aPersistenceManagerFactoryconfigured based on the Properties stored in the input stream atstream.static PersistenceManagerFactorygetPersistenceManagerFactory(java.lang.ClassLoader pmfClassLoader)Get the anonymousPersistenceManagerFactoryconfigured via the standard configuration file resource "META-INF/jdoconfig.xml", using the given class loader.static PersistenceManagerFactorygetPersistenceManagerFactory(java.lang.String name)Returns a namedPersistenceManagerFactoryor persistence unit.static PersistenceManagerFactorygetPersistenceManagerFactory(java.lang.String name, java.lang.ClassLoader loader)Returns a namedPersistenceManagerFactoryor persistence unit.static PersistenceManagerFactorygetPersistenceManagerFactory(java.lang.String name, java.lang.ClassLoader resourceLoader, java.lang.ClassLoader pmfLoader)Returns a namedPersistenceManagerFactoryor persistence unit.static PersistenceManagerFactorygetPersistenceManagerFactory(java.lang.String jndiLocation, javax.naming.Context context)Returns aPersistenceManagerFactoryat the JNDI location specified byjndiLocationin the contextcontext.static PersistenceManagerFactorygetPersistenceManagerFactory(java.lang.String jndiLocation, javax.naming.Context context, java.lang.ClassLoader loader)Returns aPersistenceManagerFactoryat the JNDI location specified byjndiLocationin the contextcontext.static PersistenceManagerFactorygetPersistenceManagerFactory(java.util.Map props)Get aPersistenceManagerFactorybased on aPropertiesinstance, using the current thread's context class loader to locate thePersistenceManagerFactoryclass.static PersistenceManagerFactorygetPersistenceManagerFactory(java.util.Map props, java.lang.ClassLoader pmfClassLoader)Get aPersistenceManagerFactorybased on aMapand a class loader.static PersistenceManagerFactorygetPersistenceManagerFactory(java.util.Map overrides, java.lang.String name)Returns a namedPersistenceManagerFactoryor persistence unit.static PersistenceManagerFactorygetPersistenceManagerFactory(java.util.Map overrides, java.lang.String name, java.lang.ClassLoader resourceLoader)Returns a namedPersistenceManagerFactoryor persistence unit.static PersistenceManagerFactorygetPersistenceManagerFactory(java.util.Map overrides, java.lang.String name, java.lang.ClassLoader resourceLoader, java.lang.ClassLoader pmfLoader)Returns aPersistenceManagerFactoryconfigured based on the properties stored in the resource atname, or, if not found, returns aPersistenceManagerFactorywith the given name or, if not found, returns ajavax.persistence.EntityManagerFactorycast to aPersistenceManagerFactory.protected static PersistenceManagerFactorygetPersistenceManagerFactory(java.util.Map overrides, java.util.Map props, java.lang.ClassLoader pmfClassLoader)Get aPersistenceManagerFactorybased on aMapof overrides, aMapof properties, and a class loader.protected static java.util.MapgetPropertiesFromJdoconfig(java.lang.String name, java.lang.ClassLoader resourceLoader)private static java.io.InputStreamgetResourceAsStream(java.lang.ClassLoader resourceLoader, java.lang.String name)Get the named resource as a stream from the resource loader.protected static java.util.EnumerationgetResources(java.lang.ClassLoader resourceLoader, java.lang.String resourceName)Get resources of the resource loader.static java.lang.ObjectgetTransactionalObjectId(java.lang.Object pc)Return a copy of the JDO identity associated with the parameter instance.static java.lang.ObjectgetVersion(java.lang.Object pc)Return the version of the instance.private static java.lang.Objectinvoke(java.lang.reflect.Method method, java.lang.Object instance, java.lang.Object[] parameters)Invoke the method.protected static PersistenceManagerFactoryinvokeGetPersistenceManagerFactoryOnImplementation(java.lang.String pmfClassName, java.util.Map overrides, java.util.Map properties, java.lang.ClassLoader cl)Invoke the getPersistenceManagerFactory method on the implementation.static booleanisDeleted(java.lang.Object pc)Tests whether the parameter instance has been deleted.static booleanisDetached(java.lang.Object pc)Tests whether the parameter instance has been detached.static booleanisDirty(java.lang.Object pc)Tests whether the parameter instance is dirty.static booleanisNew(java.lang.Object pc)Tests whether the parameter instance has been newly made persistent.protected static booleanisNullOrBlank(java.lang.String s)static booleanisPersistent(java.lang.Object pc)Tests whether the parameter instance is persistent.static booleanisTransactional(java.lang.Object pc)Tests whether the parameter instance is transactional.protected static java.util.MaploadPropertiesFromResource(java.lang.ClassLoader resourceLoader, java.lang.String name)Load a Properties instance by name from the class loader.static voidmakeDirty(java.lang.Object pc, java.lang.String fieldName)Explicitly mark the parameter instance and field dirty.private static java.io.InputStreamopenStream(java.net.URL url)Open an input stream on the url.protected static java.util.MapreadNamedPMFProperties(java.net.URL url, java.lang.String requestedPMFName, javax.xml.parsers.DocumentBuilderFactory factory)Reads JDO configuration file, creates a Map for each persistence-manager-factory, then returns the map.protected static java.util.PropertiesreadPropertiesFromPMFElementAttributes(org.w3c.dom.Node pmfElement)protected static java.util.PropertiesreadPropertiesFromPMFSubelements(org.w3c.dom.Node pmfElement, java.net.URL url)
-
-
-
Field Detail
-
ATTRIBUTE_PROPERTY_XREF
static final java.util.Map ATTRIBUTE_PROPERTY_XREF
A mapping from jdoconfig.xsd element attributes to PMF properties.
-
msg
private static final I18NHelper msg
The Internationalization message helper.
-
implHelper
private static JDOImplHelper implHelper
The JDOImplHelper instance used for handling non-binary-compatible implementations.
-
instance
private static JDOHelper instance
The singleton instance of JDOHelper.- Since:
- 2.1
-
getPersistenceManager
static JDOImplHelper.StateInterrogationObjectReturn getPersistenceManager
The stateless instance used for handling non-binary-compatible implementations of getPersistenceManager.
-
getObjectId
static JDOImplHelper.StateInterrogationObjectReturn getObjectId
The stateless instance used for handling non-binary-compatible implementations of getObjectId.
-
getTransactionalObjectId
static JDOImplHelper.StateInterrogationObjectReturn getTransactionalObjectId
The stateless instance used for handling non-binary-compatible implementations of getTransactionalObjectId.
-
getVersion
static JDOImplHelper.StateInterrogationObjectReturn getVersion
The stateless instance used for handling non-binary-compatible implementations of getVersion.
-
isPersistent
static JDOImplHelper.StateInterrogationBooleanReturn isPersistent
The stateless instance used for handling non-binary-compatible implementations of isPersistent.
-
isTransactional
static JDOImplHelper.StateInterrogationBooleanReturn isTransactional
The stateless instance used for handling non-binary-compatible implementations of isTransactional.
-
isDirty
static JDOImplHelper.StateInterrogationBooleanReturn isDirty
The stateless instance used for handling non-binary-compatible implementations of isDirty.
-
isNew
static JDOImplHelper.StateInterrogationBooleanReturn isNew
The stateless instance used for handling non-binary-compatible implementations of isNew.
-
isDeleted
static JDOImplHelper.StateInterrogationBooleanReturn isDeleted
The stateless instance used for handling non-binary-compatible implementations of isDeleted.
-
isDetached
static JDOImplHelper.StateInterrogationBooleanReturn isDetached
The stateless instance used for handling non-binary-compatible implementations of isDetached.
-
-
Method Detail
-
createAttributePropertyXref
static java.util.Map createAttributePropertyXref()
Creates a map from jdoconfig.xsd element attributes to PMF properties.- Returns:
- An unmodifiable Map of jdoconfig.xsd element attributes to PMF properties.
-
getInstance
public static JDOHelper getInstance()
Return the singleton instance of JDOHelper. This instance is thread-safe.- Returns:
- the thread-safe singleton JDOHelper
- Since:
- 2.1
-
getPersistenceManager
public static PersistenceManager getPersistenceManager(java.lang.Object pc)
Return the associatedPersistenceManagerif there is one. Transactional and persistent instances return the associatedPersistenceManager.Transient non-transactional instances and instances of classes that do not implement
PersistenceCapablereturnnull.- Parameters:
pc- thePersistenceCapableinstance.- Returns:
- the
PersistenceManagerassociated with the parameter instance. - See Also:
PersistenceCapable.jdoGetPersistenceManager()
-
makeDirty
public static void makeDirty(java.lang.Object pc, java.lang.String fieldName)Explicitly mark the parameter instance and field dirty. Normally,PersistenceCapableclasses 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
PersistenceCapableignore this method.- Parameters:
pc- thePersistenceCapableinstance.fieldName- the name of the field to be marked dirty.- See Also:
PersistenceCapable.jdoMakeDirty(String fieldName)
-
getObjectId
public static java.lang.Object getObjectId(java.lang.Object pc)
Return a copy of the JDO identity associated with the parameter instance.Persistent instances of
PersistenceCapableclasses 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 implement
PersistenceCapablereturnnull.The ObjectId may be serialized and later restored, and used with a
PersistenceManagerfrom 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
PersistenceManagerfrom any JDO implementation that supports thePersistenceCapableclass.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)
-
getObjectIds
public static java.util.Collection getObjectIds(java.util.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)
-
getObjectIds
public static java.lang.Object[] getObjectIds(java.lang.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)
-
getTransactionalObjectId
public static java.lang.Object getTransactionalObjectId(java.lang.Object pc)
Return a copy of the JDO identity associated with the parameter instance.- Parameters:
pc- thePersistenceCapableinstance.- 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)
-
getVersion
public static java.lang.Object getVersion(java.lang.Object pc)
Return the version of the instance.- Parameters:
pc- the instance- Returns:
- the version of the instance
- Since:
- 2.0
-
isDirty
public static boolean isDirty(java.lang.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 implement
PersistenceCapablereturnfalse.- Parameters:
pc- thePersistenceCapableinstance.- Returns:
trueif the parameter instance has been modified in the current transaction.- See Also:
StateManager.makeDirty(PersistenceCapable pc, String fieldName),PersistenceCapable.jdoIsDirty()
-
isTransactional
public static boolean isTransactional(java.lang.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 implement
PersistenceCapablereturnfalse.- Parameters:
pc- thePersistenceCapableinstance.- Returns:
trueif the parameter instance is transactional.- See Also:
PersistenceCapable.jdoIsTransactional()
-
isPersistent
public static boolean isPersistent(java.lang.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 implement
PersistenceCapablereturnfalse.- Parameters:
pc- thePersistenceCapableinstance.- Returns:
trueif the parameter instance is persistent.- See Also:
PersistenceManager.makePersistent(Object pc),PersistenceCapable.jdoIsPersistent()
-
isNew
public static boolean isNew(java.lang.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 implement
PersistenceCapablereturnfalse.- Parameters:
pc- thePersistenceCapableinstance.- Returns:
trueif the parameter instance was made persistent in the current transaction.- See Also:
PersistenceManager.makePersistent(Object pc),PersistenceCapable.jdoIsNew()
-
isDeleted
public static boolean isDeleted(java.lang.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 implement
PersistenceCapablereturnfalse.- Parameters:
pc- thePersistenceCapableinstance.- Returns:
trueif the parameter instance was deleted in the current transaction.- See Also:
PersistenceManager.deletePersistent(Object pc),PersistenceCapable.jdoIsDeleted()
-
isDetached
public static boolean isDetached(java.lang.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:
trueif this instance is detached.- Since:
- 2.0
- See Also:
PersistenceCapable.jdoIsDetached()
-
getObjectState
public static ObjectState getObjectState(java.lang.Object pc)
Accessor for the state of the passed object.- Parameters:
pc- The object- Returns:
- The object state
- Since:
- 2.1
-
getPersistenceManagerFactory
public static PersistenceManagerFactory getPersistenceManagerFactory()
Get the anonymousPersistenceManagerFactoryconfigured via the standard configuration file resource "META-INF/jdoconfig.xml", using the current thread's context class loader to locate the configuration file resource(s).- Returns:
- the anonymous
PersistenceManagerFactory. - Since:
- 2.1
- See Also:
getPersistenceManagerFactory(Map,String,ClassLoader,ClassLoader)
-
getPersistenceManagerFactory
public static PersistenceManagerFactory getPersistenceManagerFactory(java.lang.ClassLoader pmfClassLoader)
Get the anonymousPersistenceManagerFactoryconfigured via the standard configuration file resource "META-INF/jdoconfig.xml", using the given class loader.- Parameters:
pmfClassLoader- the ClassLoader used to load resources and classes- Returns:
- the anonymous
PersistenceManagerFactory. - Since:
- 2.1
- See Also:
getPersistenceManagerFactory(Map,String,ClassLoader,ClassLoader)
-
getPersistenceManagerFactory
public static PersistenceManagerFactory getPersistenceManagerFactory(java.util.Map props)
Get aPersistenceManagerFactorybased on aPropertiesinstance, using the current thread's context class loader to locate thePersistenceManagerFactoryclass.- Parameters:
props- aPropertiesinstance with properties of thePersistenceManagerFactory.- Returns:
- the
PersistenceManagerFactory. - See Also:
getPersistenceManagerFactory(java.util.Map,ClassLoader)
-
getPersistenceManagerFactory
public static PersistenceManagerFactory getPersistenceManagerFactory(java.util.Map props, java.lang.ClassLoader pmfClassLoader)
Get aPersistenceManagerFactorybased on aMapand a class loader. This method delegates to the getPersistenceManagerFactory method that takes a Map of overrides and a Map of properties, passing null as the overrides parameter.- Parameters:
props- aMapwith properties of thePersistenceManagerFactory.pmfClassLoader- the class loader used to load thePersistenceManagerFactoryclass- Returns:
- the
PersistenceManagerFactory. - Since:
- 1.0
- See Also:
getPersistenceManagerFactory(java.util.Map, java.util.Map, ClassLoader)
-
getPersistenceManagerFactory
protected static PersistenceManagerFactory getPersistenceManagerFactory(java.util.Map overrides, java.util.Map props, java.lang.ClassLoader pmfClassLoader)
Get aPersistenceManagerFactorybased on aMapof overrides, aMapof properties, and a class loader. The following are standard key names:"javax.jdo.PersistenceManagerFactoryClass"and properties of the form
"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.ReadOnly",
"javax.jdo.option.TransactionIsolationLevel",
"javax.jdo.option.TransactionType",
"javax.jdo.option.ServerTimeZoneID",
"javax.jdo.option.Name".javax.jdo.option.InstanceLifecycleListener.{listenerClass}[=[{pcClasses}]]where{listenerClass}is the fully qualified name of a class that implementsInstanceLifecycleListener, 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
JDOFatalUserExceptionthrown by the method.The returned
PersistenceManagerFactoryis not configurable (thesetXXXmethods will throw an exception).JDO implementations might manage a map of instantiated
PersistenceManagerFactoryinstances based on specified property key values, and return a previously instantiatedPersistenceManagerFactoryinstance. In this case, the properties of the returned instance must exactly match the requested properties.- Parameters:
props- aPropertiesinstance with properties of thePersistenceManagerFactory.pmfClassLoader- the class loader to use to load thePersistenceManagerFactoryclass- Returns:
- the
PersistenceManagerFactory. - Throws:
JDOFatalUserException- if- the pmfClassLoader passed is invalid; or
- a valid class name cannot be obtained from
either
propsor system resources (an entry in META-INF/services/javax.jdo.PersistenceManagerFactory); or - all implementations throw an exception.
- Since:
- 2.1
-
getClassNameFromURL
protected static java.lang.String getClassNameFromURL(java.net.URL url) throws java.io.IOExceptionGet a class name from a URL. The URL is from getResources with e.g. META-INF/services/javax.jdo.PersistenceManagerFactory as the parameter. Parse the file, removing blank lines, comment lines, and comments.- Parameters:
url- the URL of the services file- Returns:
- the name of the class contained in the file
- Throws:
java.io.IOException- Since:
- 2.1
-
getPersistenceManagerFactory
public static PersistenceManagerFactory getPersistenceManagerFactory(java.lang.String name)
Returns a namedPersistenceManagerFactoryor persistence unit.- Since:
- 2.1
- See Also:
getPersistenceManagerFactory(Map,String,ClassLoader,ClassLoader)
-
getPersistenceManagerFactory
public static PersistenceManagerFactory getPersistenceManagerFactory(java.lang.String name, java.lang.ClassLoader loader)
Returns a namedPersistenceManagerFactoryor persistence unit.- Since:
- 1.0
- See Also:
getPersistenceManagerFactory(Map,String,ClassLoader,ClassLoader)
-
getPersistenceManagerFactory
public static PersistenceManagerFactory getPersistenceManagerFactory(java.lang.String name, java.lang.ClassLoader resourceLoader, java.lang.ClassLoader pmfLoader)
Returns a namedPersistenceManagerFactoryor persistence unit.- Since:
- 2.0
- See Also:
getPersistenceManagerFactory(Map,String,ClassLoader,ClassLoader)
-
getPersistenceManagerFactory
public static PersistenceManagerFactory getPersistenceManagerFactory(java.util.Map overrides, java.lang.String name)
Returns a namedPersistenceManagerFactoryor persistence unit.- Since:
- 2.1
- See Also:
getPersistenceManagerFactory(Map,String,ClassLoader,ClassLoader)
-
getPersistenceManagerFactory
public static PersistenceManagerFactory getPersistenceManagerFactory(java.util.Map overrides, java.lang.String name, java.lang.ClassLoader resourceLoader)
Returns a namedPersistenceManagerFactoryor persistence unit.- Since:
- 2.1
- See Also:
getPersistenceManagerFactory(Map,String,ClassLoader,ClassLoader)
-
getPersistenceManagerFactory
public static PersistenceManagerFactory getPersistenceManagerFactory(java.util.Map overrides, java.lang.String name, java.lang.ClassLoader resourceLoader, java.lang.ClassLoader pmfLoader)
Returns aPersistenceManagerFactoryconfigured based on the properties stored in the resource atname, or, if not found, returns aPersistenceManagerFactorywith the given name or, if not found, returns ajavax.persistence.EntityManagerFactorycast to aPersistenceManagerFactory. If the name given is null or consists only of whitespace, it is interpreted asConstants.ANONYMOUS_PERSISTENCE_MANAGER_FACTORY_NAME. The following are standard key names:"javax.jdo.PersistenceManagerFactoryClass"and properties of the form
"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".javax.jdo.option.InstanceLifecycleListener.{listenerClass}[=[{pcClasses}]]where{listenerClass}is the fully qualified name of a class that implementsInstanceLifecycleListener, 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
JDOFatalUserExceptionthrown by the method.The returned
PersistenceManagerFactoryis not configurable (thesetXXXmethods will throw an exception). This method loads the properties found atname, if any, viaresourceLoader, and creates aPersistenceManagerFactorywithpmfLoader. Any exceptions thrown during resource loading will be wrapped in aJDOFatalUserException. If multiple PMFs with the requested name are found, aJDOFatalUserExceptionis 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 anonymousPersistenceManagerFactory.resourceLoader- the class loader to use to load properties file resources; must be non-null ifnameis non-null or blankpmfLoader- the class loader to use to load thePersistenceManagerFactoryorjavax.persistence.EntityManagerFactoryclasses- Returns:
- the
PersistenceManagerFactorywith properties in the given resource, with the given name, or with the given persitence unit name - Since:
- 2.1
- See Also:
Constants.ANONYMOUS_PERSISTENCE_MANAGER_FACTORY_NAME
-
invokeGetPersistenceManagerFactoryOnImplementation
protected static PersistenceManagerFactory invokeGetPersistenceManagerFactoryOnImplementation(java.lang.String pmfClassName, java.util.Map overrides, java.util.Map properties, java.lang.ClassLoader cl)
Invoke the getPersistenceManagerFactory method on the implementation. If the overrides parameter to this method is not null, the static method with Map overrides, Map properties parameters will be invoked. If the overrides parameter to this method is null, the static method with Map properties parameter will be invoked.- Parameters:
pmfClassName- the name of the implementation factory classoverrides- a Map of overridesproperties- a Map of propertiescl- the class loader to use to load the implementation class- Returns:
- the PersistenceManagerFactory
-
loadPropertiesFromResource
protected static java.util.Map loadPropertiesFromResource(java.lang.ClassLoader resourceLoader, java.lang.String name)Load a Properties instance by name from the class loader.- Parameters:
resourceLoader- the class loader from which to load the propertiesname- the name of the resource- Returns:
- a Properties instance or null if no resource is found
-
getPropertiesFromJdoconfig
protected static java.util.Map getPropertiesFromJdoconfig(java.lang.String name, java.lang.ClassLoader resourceLoader)- Since:
- 2.1
- See Also:
getNamedPMFProperties(String,ClassLoader,String)
-
getNamedPMFProperties
protected static java.util.Map getNamedPMFProperties(java.lang.String name, java.lang.ClassLoader resourceLoader, java.lang.String jdoconfigResourceName)Find and return the namedPersistenceManagerFactory's properties, or null if not found. If multiple named PMF property sets with the given name are found (including anonymous ones), throwJDOFatalUserException. This method is here only to facilitate testing; the parameter "jdoconfigResourceName" in public usage should always have the value given in the constantConstants.JDOCONFIG_RESOURCE_NAME.- Parameters:
name- The persistence unit name; null is disallowed.resourceLoader- The ClassLoader used to load the standard JDO configuration file.jdoconfigResourceName- The name of the configuration file to read. In public usage, this should always be the value ofConstants.JDOCONFIG_RESOURCE_NAME.- Returns:
- The named
PersistenceManagerFactoryproperties if found, null if not. - Throws:
JDOFatalUserException- if multiple named PMF property sets are found with the given name, or any other exception is encountered.- Since:
- 2.1
-
getDocumentBuilderFactory
protected static javax.xml.parsers.DocumentBuilderFactory getDocumentBuilderFactory()
-
getDefaultDocumentBuilderFactory
protected static javax.xml.parsers.DocumentBuilderFactory getDefaultDocumentBuilderFactory()
-
getErrorHandler
protected static org.xml.sax.ErrorHandler getErrorHandler()
-
getDefaultErrorHandler
protected static org.xml.sax.ErrorHandler getDefaultErrorHandler()
-
readNamedPMFProperties
protected static java.util.Map readNamedPMFProperties(java.net.URL url, java.lang.String requestedPMFName, javax.xml.parsers.DocumentBuilderFactory factory)Reads JDO configuration file, creates a Map for each persistence-manager-factory, then returns the map.- Parameters:
url- URL of a JDO configuration file compliant with javax/jdo/jdoconfig.xsd.requestedPMFName- The name of the requested persistence unit (allows for fail-fast).factory- TheDocumentBuilderFactoryto use for XML parsing.- Returns:
- a Map
holding persistence unit configurations; for the anonymous persistence unit, the value of the String key is the empty string, "".
-
readPropertiesFromPMFElementAttributes
protected static java.util.Properties readPropertiesFromPMFElementAttributes(org.w3c.dom.Node pmfElement)
-
readPropertiesFromPMFSubelements
protected static java.util.Properties readPropertiesFromPMFSubelements(org.w3c.dom.Node pmfElement, java.net.URL url)
-
isNullOrBlank
protected static boolean isNullOrBlank(java.lang.String s)
-
getPersistenceManagerFactory
public static PersistenceManagerFactory getPersistenceManagerFactory(java.io.File propsFile)
Returns aPersistenceManagerFactoryconfigured based on the properties stored in the file atpropsFile. This method is equivalent to invokinggetPersistenceManagerFactory(File,ClassLoader)withThread.currentThread().getContextClassLoader()as theloaderargument.- Parameters:
propsFile- the file containing the Properties- Returns:
- the PersistenceManagerFactory
- Since:
- 2.0
-
getPersistenceManagerFactory
public static PersistenceManagerFactory getPersistenceManagerFactory(java.io.File propsFile, java.lang.ClassLoader loader)
Returns aPersistenceManagerFactoryconfigured based on the properties stored in the file atpropsFile. Creates aPersistenceManagerFactorywithloader. AnyIOExceptions orFileNotFoundExceptions thrown during resource loading will be wrapped in aJDOFatalUserException.- Parameters:
propsFile- the file containing the Propertiesloader- the class loader to use to load thePersistenceManagerFactoryclass- Returns:
- the PersistenceManagerFactory
- Since:
- 2.0
-
getPersistenceManagerFactory
public static PersistenceManagerFactory getPersistenceManagerFactory(java.lang.String jndiLocation, javax.naming.Context context)
Returns aPersistenceManagerFactoryat the JNDI location specified byjndiLocationin the contextcontext. Ifcontextisnull,new InitialContext()will be used. This method is equivalent to invokinggetPersistenceManagerFactory(String,Context,ClassLoader)withThread.currentThread().getContextClassLoader()as theloaderargument.- Parameters:
jndiLocation- the JNDI location containing the PersistenceManagerFactorycontext- the context in which to find the named PersistenceManagerFactory- Returns:
- the PersistenceManagerFactory
- Since:
- 2.0
-
getPersistenceManagerFactory
public static PersistenceManagerFactory getPersistenceManagerFactory(java.lang.String jndiLocation, javax.naming.Context context, java.lang.ClassLoader loader)
Returns aPersistenceManagerFactoryat the JNDI location specified byjndiLocationin the contextcontext. Ifcontextisnull,new InitialContext()will be used. Creates aPersistenceManagerFactorywithloader. AnyNamingExceptions 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 thePersistenceManagerFactoryclass- Returns:
- the PersistenceManagerFactory
- Since:
- 2.0
-
getPersistenceManagerFactory
public static PersistenceManagerFactory getPersistenceManagerFactory(java.io.InputStream stream)
Returns aPersistenceManagerFactoryconfigured based on the Properties stored in the input stream atstream. This method is equivalent to invokinggetPersistenceManagerFactory(InputStream,ClassLoader)withThread.currentThread().getContextClassLoader()as theloaderargument.- Parameters:
stream- the stream containing the Properties- Returns:
- the PersistenceManagerFactory
- Since:
- 2.0
-
getPersistenceManagerFactory
public static PersistenceManagerFactory getPersistenceManagerFactory(java.io.InputStream stream, java.lang.ClassLoader loader)
Returns aPersistenceManagerFactoryconfigured based on the Properties stored in the input stream atstream. Creates aPersistenceManagerFactorywithloader. AnyIOExceptions thrown during resource loading will be wrapped in aJDOFatalUserException.- Parameters:
stream- the stream containing the Propertiesloader- the class loader to use to load thePersistenceManagerFactoryclass- Returns:
- the PersistenceManagerFactory
- Since:
- 2.0
-
getContextClassLoader
private static java.lang.ClassLoader getContextClassLoader()
Get the context class loader associated with the current thread. This is done in a doPrivileged block because it is a secure method.- Returns:
- the current thread's context class loader.
- Since:
- 2.0
-
getResourceAsStream
private static java.io.InputStream getResourceAsStream(java.lang.ClassLoader resourceLoader, java.lang.String name)Get the named resource as a stream from the resource loader. Perform this operation in a doPrivileged block.
-
getMethod
private static java.lang.reflect.Method getMethod(java.lang.Class implClass, java.lang.String methodName, java.lang.Class[] parameterTypes) throws java.lang.NoSuchMethodExceptionGet the named Method from the named class. Perform this operation in a doPrivileged block.- Parameters:
implClass- the classmethodName- the name of the methodparameterTypes- the parameter types of the method- Returns:
- the Method instance
- Throws:
java.lang.NoSuchMethodException
-
invoke
private static java.lang.Object invoke(java.lang.reflect.Method method, java.lang.Object instance, java.lang.Object[] parameters) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetExceptionInvoke the method. Perform this operation in a doPrivileged block.- Throws:
java.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetException
-
getResources
protected static java.util.Enumeration getResources(java.lang.ClassLoader resourceLoader, java.lang.String resourceName) throws java.io.IOExceptionGet resources of the resource loader. Perform this operation in a doPrivileged block.- Parameters:
resourceLoader-resourceName-- Returns:
- the resources
- Throws:
java.io.IOException
-
forName
private static java.lang.Class forName(java.lang.String name, boolean init, java.lang.ClassLoader loader) throws java.lang.ClassNotFoundExceptionGet the named class. Perform this operation in a doPrivileged block.- Parameters:
name- the name of the classinit- whether to initialize the classloader- which class loader to use- Returns:
- the class
- Throws:
java.lang.ClassNotFoundException
-
openStream
private static java.io.InputStream openStream(java.net.URL url) throws java.io.IOExceptionOpen an input stream on the url. Perform this operation in a doPrivileged block.- Parameters:
url-- Returns:
- the input stream
- Throws:
java.io.IOException
-
-