- java.lang.Object
-
- org.datanucleus.api.jpa.NucleusJPAHelper
-
public class NucleusJPAHelper extends Object
Helper for persistence operations with JPA.
-
-
Constructor Summary
Constructors Constructor Description NucleusJPAHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ObjectgetDatastoreIdForEntity(Object obj)Convenience method to allow access to the datastore id of an object when it is using DN Extension "datastore-id".static Object[]getDetachedStateForObject(Object obj)Accessor for the jdoDetachedState field of a detached object.static String[]getDirtyFields(Object obj, javax.persistence.EntityManager em)Accessor for the names of the dirty fields of the persistable object.static javax.persistence.EntityManagergetEntityManager(Object obj)Accessor for the EntityManager for the supplied (persistable) object.static javax.persistence.PersistenceExceptiongetJPAExceptionForNucleusException(org.datanucleus.exceptions.NucleusException ne)Convenience method to convert a Nucleus exception into a JPA exception.static String[]getLoadedFields(Object obj, javax.persistence.EntityManager em)Accessor for the names of the loaded fields of the persistable object.static ObjectgetObjectId(Object obj)static StringgetObjectState(Object obj)Convenience method to return a string of the state of an object.static ObjectgetSurrogateVersionForEntity(Object obj)Convenience method to allow access to the version of an object when it is using DN Extension "surrogate-version".static booleanisDeleted(Object obj)Convenience accessor for whether the object is deleted.static booleanisDetached(Object obj)Convenience accessor for whether the object is detached.static booleanisPersistent(Object obj)Convenience accessor for whether the object is persistent.static booleanisTransactional(Object obj)Convenience accessor for whether the object is transactional.
-
-
-
Method Detail
-
getSurrogateVersionForEntity
public static Object getSurrogateVersionForEntity(Object obj)
Convenience method to allow access to the version of an object when it is using DN Extension "surrogate-version".- Parameters:
obj- The entity object- Returns:
- The (surrogate) version
-
getDatastoreIdForEntity
public static Object getDatastoreIdForEntity(Object obj)
Convenience method to allow access to the datastore id of an object when it is using DN Extension "datastore-id".- Parameters:
obj- The entity object- Returns:
- The datastore id key
-
getEntityManager
public static javax.persistence.EntityManager getEntityManager(Object obj)
Accessor for the EntityManager for the supplied (persistable) object. If the object is detached or transient then returns null.- Parameters:
obj- The persistable object- Returns:
- The entity manager for this object
-
isPersistent
public static boolean isPersistent(Object obj)
Convenience accessor for whether the object is persistent.- Parameters:
obj- The object- Returns:
- Whether it is persistent
-
isDeleted
public static boolean isDeleted(Object obj)
Convenience accessor for whether the object is deleted.- Parameters:
obj- The object- Returns:
- Whether it is deleted
-
isDetached
public static boolean isDetached(Object obj)
Convenience accessor for whether the object is detached.- Parameters:
obj- The object- Returns:
- Whether it is persistent
-
isTransactional
public static boolean isTransactional(Object obj)
Convenience accessor for whether the object is transactional.- Parameters:
obj- The object- Returns:
- Whether it is transactional
-
getObjectState
public static String getObjectState(Object obj)
Convenience method to return a string of the state of an object. Will return things like "detached", "persistent", etc- Parameters:
obj- The object- Returns:
- The state
-
getDetachedStateForObject
public static Object[] getDetachedStateForObject(Object obj)
Accessor for the jdoDetachedState field of a detached object. The returned array is made up of :- 0 - the identity of the object
- 1 - the version of the object (upon detach)
- 2 - loadedFields BitSet
- 3 - dirtyFields BitSet
- Parameters:
obj- The detached object- Returns:
- The detached state
-
getDirtyFields
public static String[] getDirtyFields(Object obj, javax.persistence.EntityManager em)
Accessor for the names of the dirty fields of the persistable object.- Parameters:
obj- The persistable objectem- The Entity Manager (only required if the object is detached)- Returns:
- Names of the dirty fields
-
getLoadedFields
public static String[] getLoadedFields(Object obj, javax.persistence.EntityManager em)
Accessor for the names of the loaded fields of the persistable object.- Parameters:
obj- Persistable objectem- The Entity Manager (only required if the object is detached)- Returns:
- Names of the loaded fields
-
getJPAExceptionForNucleusException
public static javax.persistence.PersistenceException getJPAExceptionForNucleusException(org.datanucleus.exceptions.NucleusException ne)
Convenience method to convert a Nucleus exception into a JPA exception. If the incoming exception has a "failed object" then create the new exception with a failed object. Otherwise if the incoming exception has nested exceptions then create this exception with those nested exceptions. Else create this exception with the incoming exception as its nested exception.- Parameters:
ne- NucleusException- Returns:
- The JPAException
-
-