Package org.datanucleus.identity
Class IdentityUtils
- java.lang.Object
-
- org.datanucleus.identity.IdentityUtils
-
public class IdentityUtils extends java.lang.ObjectSeries of utilities for handling identities of objects.
-
-
Constructor Summary
Constructors Constructor Description IdentityUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.ObjectgetApplicationIdentityForResultSetRow(ExecutionContext ec, AbstractClassMetaData cmd, java.lang.Class pcClass, boolean inheritanceCheck, FieldManager resultsFM)Method to return the object application identity for a row of the result set.static java.lang.ClassgetKeyTypeForSingleFieldIdentityType(java.lang.Class idType)Accessor for the type of the single field application-identity key given the single field identity type.static java.lang.ObjectgetObjectFromIdString(java.lang.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).static java.lang.ObjectgetObjectFromIdString(java.lang.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.static java.lang.ObjectgetObjectFromPersistableIdentity(java.lang.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).static java.lang.StringgetPersistableIdentityForId(java.lang.Object id)Method to return a persistable form of the identity of a persistable object.static java.lang.Class<? extends SingleFieldId>getSingleFieldIdentityTypeForKeyType(java.lang.Class keyType)static java.lang.StringgetTargetClassNameForIdentity(java.lang.Object id)Method to return the target class name of the persistable object that the provided identity represents.static java.lang.ObjectgetTargetKeyForDatastoreIdentity(java.lang.Object id)Accessor for the key object for the specified datastore-identity.static java.lang.ObjectgetTargetKeyForSingleFieldIdentity(java.lang.Object id)Accessor for the key object for the specified single field application-identity.static java.lang.ObjectgetValueForMemberInId(java.lang.Object id, AbstractMemberMetaData pkMmd)Convenience method that interrogates a user-supplied object identity and returns the value of a particular member in that id.static booleanisDatastoreIdentity(java.lang.Object id)Accessor for whether the provided id is datastore identity.static booleanisSingleFieldIdentity(java.lang.Object id)Accessor for whether the passed identity is a valid single-field application-identity for this API.static booleanisSingleFieldIdentityClass(java.lang.String className)Checks whether the passed class name is valid for a single field application-identity.
-
-
-
Method Detail
-
isSingleFieldIdentityClass
public static boolean isSingleFieldIdentityClass(java.lang.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 java.lang.String getTargetClassNameForIdentity(java.lang.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 atargetClassName
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(java.lang.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(java.lang.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 java.lang.Object getTargetKeyForSingleFieldIdentity(java.lang.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 java.lang.Object getTargetKeyForDatastoreIdentity(java.lang.Object id)
Accessor for the key object for the specified datastore-identity.- Parameters:
id- The identity- Returns:
- The key object
-
getSingleFieldIdentityTypeForKeyType
public static java.lang.Class<? extends SingleFieldId> getSingleFieldIdentityTypeForKeyType(java.lang.Class keyType)
-
getKeyTypeForSingleFieldIdentityType
public static java.lang.Class getKeyTypeForSingleFieldIdentityType(java.lang.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 java.lang.String getPersistableIdentityForId(java.lang.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 java.lang.Object getObjectFromPersistableIdentity(java.lang.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 idcmd- (Root) metadata for the classec- Execution Context- Returns:
- The object
-
getApplicationIdentityForResultSetRow
public static java.lang.Object getApplicationIdentityForResultSetRow(ExecutionContext ec, AbstractClassMetaData cmd, java.lang.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 Contextcmd- Metadata for the classpcClass- The class requiredinheritanceCheck- 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 java.lang.Object getValueForMemberInId(java.lang.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) identitypkMmd- Metadata for the member that we require the value for- Returns:
- The value for this member in the id
-
getObjectFromIdString
public static java.lang.Object getObjectFromIdString(java.lang.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 stringcmd- Metadata for the classec- Execution ContextcheckInheritance- Whether to check the inheritance level of this object- Returns:
- The object
-
getObjectFromIdString
public static java.lang.Object getObjectFromIdString(java.lang.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 stringmmd- Metadata for the memberfieldRole- Role of this field (see org.datanucleus.metadata.FieldRole)ec- Execution ContextcheckInheritance- Whether to check the inheritance level of this object- Returns:
- The object
-
-