Class OpenJPAPersistenceUtil

java.lang.Object
org.apache.openjpa.persistence.OpenJPAPersistenceUtil

public class OpenJPAPersistenceUtil extends Object
  • Constructor Details

    • OpenJPAPersistenceUtil

      public OpenJPAPersistenceUtil()
  • Method Details

    • getIdentifier

      public static Object getIdentifier(Object entity)
      Returns the identifier of the persistent entity.
      Parameters:
      entity -
      Returns:
      The identifier of the entity or null if the entity is not persistent.
    • getIdentifier

      public static Object getIdentifier(OpenJPAEntityManagerFactory emf, Object entity)
      Get the object identifier for a persistent entity managed by one of the entity managers of the specified entity manager factory.
      Returns:
      The identifier of the entity or null if the entity does not have an identifier assigned or is not managed by any of the entity managers of the entity manager factory.
    • getVersion

      public static Object getVersion(OpenJPAEntityManagerFactory emf, Object entity)
      Get version of a persistent entity managed by one of the entity managers of the specified entity manager factory.
      Parameters:
      emf - the entity manager factory presumed to contain the given entity
      entity - the entity whose version is desired
      Returns:
      the version of the entity, or null if it does not have a version field or if it was not persisted yet.
    • isManagedBy

      public static boolean isManagedBy(OpenJPAEntityManagerFactory emf, Object entity)
      Determines whether the specified state manager is managed by an open broker within the persistence unit of the provided EMF instance.
      Parameters:
      emf - OpenJPAEntityManagerFactory
      entity - the entity to check
      Returns:
      true if this entity is managed by a broker within this persistence unit.
    • load

      public static void load(OpenJPAEntityManagerFactory emf, Object entity)
      Loads the given entity from it's entity manager if it is managed.
      Parameters:
      emf - the entity manager factory that contains the manager of the entity
      entity - the entity that must be loaded
    • load

      public static void load(OpenJPAEntityManagerFactory emf, Object entity, String attributeName)
      Loads the given entity attribute from it's entity manager if it is managed.
      Parameters:
      emf - the entity manager factory that contains the manager of the entity
      entity - the entity whose attribute has to be loaded
      attributeName - the attribute to be loaded
    • isLoaded

      public static LoadState isLoaded(Object obj, String attr)
      Determines whether the attribute on the specified object is loaded and is managed by one of the entity managers. Use isManagedBy() to determine if an object is managed by a specific entity manager factory.
      Returns:
      LoadState.LOADED - if the attribute is loaded. LoadState.NOT_LOADED - if the attribute is not loaded or any EAGER fetch attributes of the entity are not loaded. LoadState.UNKNOWN - if the entity is not managed by this provider or if it does not contain the persistent attribute.
    • getClass

      public static <T> Class<T> getClass(OpenJPAEntityManagerFactory emf, Object entity)