Class IdentityUtils

java.lang.Object
org.datanucleus.identity.IdentityUtils

public class IdentityUtils extends Object
Series of utilities for handling identities of objects.
  • Constructor Details

    • IdentityUtils

      public IdentityUtils()
  • Method Details

    • isSingleFieldIdentityClass

      public static boolean isSingleFieldIdentityClass(String className)
      Checks whether the passed class name is valid for a single field application-identity.
      Parameters:
      className - the identity class name
      Returns:
      Whether it is a single field class
    • getTargetClassNameForIdentity

      public static String getTargetClassNameForIdentity(Object id)
      Method to return the target class name of the persistable object that the provided identity represents. For the cases of datastore-identity or single-field identity then utilises the accessor method on those identity types to get the targetClassName. For user-provided identity types checks for a
      targetClassName
      field and returns it if present. Otherwise returns null.
      Parameters:
      id - The identity
      Returns:
      Class name for the identity if easily determinable
    • isSingleFieldIdentity

      public static boolean isSingleFieldIdentity(Object id)
      Accessor for whether the passed identity is a valid single-field application-identity for this API.
      Parameters:
      id - The id
      Returns:
      Whether it is valid
    • isDatastoreIdentity

      public static boolean isDatastoreIdentity(Object id)
      Accessor for whether the provided id is datastore identity.
      Parameters:
      id - The identity to check
      Returns:
      Whether it is datastore identity
    • getTargetKeyForSingleFieldIdentity

      public static Object getTargetKeyForSingleFieldIdentity(Object id)
      Accessor for the key object for the specified single field application-identity.
      Parameters:
      id - The identity
      Returns:
      The key object
    • getTargetKeyForDatastoreIdentity

      public static Object getTargetKeyForDatastoreIdentity(Object id)
      Accessor for the key object for the specified datastore-identity.
      Parameters:
      id - The identity
      Returns:
      The key object
    • getSingleFieldIdentityTypeForKeyType

      public static Class<? extends SingleFieldId> getSingleFieldIdentityTypeForKeyType(Class keyType)
    • getKeyTypeForSingleFieldIdentityType

      public static Class getKeyTypeForSingleFieldIdentityType(Class idType)
      Accessor for the type of the single field application-identity key given the single field identity type.
      Parameters:
      idType - Single field identity type
      Returns:
      key type
    • getPersistableIdentityForId

      public static String getPersistableIdentityForId(Object id)
      Method to return a persistable form of the identity of a persistable object. This can be used by datastores that don't use foreign keys and want to store the explicit class of the persistable object.
      Parameters:
      id - The id
      Returns:
      String form
    • getObjectFromPersistableIdentity

      public static Object getObjectFromPersistableIdentity(String persistableId, AbstractClassMetaData cmd, ExecutionContext ec)
      Convenience method to find an object given a string form of its identity, and the metadata for the class (or a superclass).
      Parameters:
      persistableId - The persistable id
      cmd - (Root) metadata for the class
      ec - Execution Context
      Returns:
      The object
    • getApplicationIdentityForResultSetRow

      public static Object getApplicationIdentityForResultSetRow(ExecutionContext ec, AbstractClassMetaData cmd, Class pcClass, boolean inheritanceCheck, FieldManager resultsFM)
      Method to return the object application identity for a row of the result set. If the class isn't using application identity then returns null
      Parameters:
      ec - Execution Context
      cmd - Metadata for the class
      pcClass - The class required
      inheritanceCheck - Whether need an inheritance check (may be for a subclass)
      resultsFM - FieldManager servicing the results
      Returns:
      The identity (if found) or null (if either not sure of inheritance, or not known).
    • getValueForMemberInId

      public static Object getValueForMemberInId(Object id, AbstractMemberMetaData pkMmd)
      Convenience method that interrogates a user-supplied object identity and returns the value of a particular member in that id. A user-supplied PK has to provide either public/package/protected fields with the same names as the owning class, or getters for bean properties of the same name as the class members.
      Parameters:
      id - The (user-defined) identity
      pkMmd - Metadata for the member that we require the value for
      Returns:
      The value for this member in the id
    • getObjectFromIdString

      public static Object getObjectFromIdString(String idStr, AbstractClassMetaData cmd, ExecutionContext ec, boolean checkInheritance)
      Convenience method to find an object given a string form of its identity, and the metadata for the class (or a superclass). Developers should move to using "persistable identity" and method getObjectFromPersistableIdentity().
      Parameters:
      idStr - The id string
      cmd - Metadata for the class
      ec - Execution Context
      checkInheritance - Whether to check the inheritance level of this object
      Returns:
      The object
    • getObjectFromIdString

      public static Object getObjectFromIdString(String idStr, AbstractMemberMetaData mmd, FieldRole fieldRole, ExecutionContext ec, boolean checkInheritance)
      Convenience method to find an object given a string form of its identity, and the metadata for the member.
      Parameters:
      idStr - The id string
      mmd - Metadata for the member
      fieldRole - Role of this field (see org.datanucleus.metadata.FieldRole)
      ec - Execution Context
      checkInheritance - Whether to check the inheritance level of this object
      Returns:
      The object