Class DataNucleusHelperJPA


  • public class DataNucleusHelperJPA
    extends Object
    Helper class for accessing DataNucleus internals from a JPA environment. This is a supplement to using the wrap() methods on EntityManagerFactory and EntityManager.
    • Constructor Detail

      • DataNucleusHelperJPA

        public DataNucleusHelperJPA()
    • 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
      • getObjectId

        public static Object getObjectId​(Object obj)
      • 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 object
        em - 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 object
        em - The Entity Manager (only required if the object is detached)
        Returns:
        Names of the loaded fields
      • isFieldLoaded

        public static Boolean isFieldLoaded​(Object obj,
                                            String memberName,
                                            javax.persistence.EntityManager em)
        Accessor for whether the specified member (field/property) of the passed persistable object is loaded.
        Parameters:
        obj - The persistable object
        memberName - Name of the field/property
        em - EntityManager (if the object is detached)
        Returns:
        Whether the member is loaded
      • isFieldDirty

        public static Boolean isFieldDirty​(Object obj,
                                           String memberName,
                                           javax.persistence.EntityManager em)
        Accessor for whether the specified member (field/property) of the passed persistable object is dirty.
        Parameters:
        obj - The persistable object
        memberName - Name of the field/property
        em - EntityManager (if the object is detached)
        Returns:
        Whether the member is dirty
      • makeFieldDirty

        public static void makeFieldDirty​(Object obj,
                                          String memberName)
        Convenience method to mark the specified member (field/property) as dirty, when managed. Normally, Persistable 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.
        Parameters:
        obj - The persistable object
        memberName - The member to mark as dirty