org.datanucleus.jpa
Class JPAAdapter

java.lang.Object
  extended by org.datanucleus.jpa.JPAAdapter
All Implemented Interfaces:
java.io.Serializable, org.datanucleus.api.ApiAdapter

public class JPAAdapter
extends java.lang.Object
implements org.datanucleus.api.ApiAdapter

Adapter for the JPA API, to allow the DataNucleus core runtime to expose multiple APIs to clients.

See Also:
Serialized Form

Field Summary
protected static org.datanucleus.util.Localiser LOCALISER
           
 
Constructor Summary
JPAAdapter()
           
 
Method Summary
 boolean allowDeleteOfNonPersistentObject()
          Whether the API allows deletion of a non-persistent object.
 boolean allowPersistOfDeletedObject()
          Whether the API allows (re-)persistence of a deleted object.
 boolean allowReadFieldOfDeletedObject()
          Whether the API allows reading a field of a deleted object.
 boolean clearLoadedFlagsOnDeleteObject()
          Whether the API requires clearing of the fields of an object when it is deleted.
 java.lang.RuntimeException getDataStoreExceptionForException(java.lang.String msg, java.lang.Exception e)
          Convenience method to return a datastore exception appropriate for this API.
 boolean getDefaultCascadeDeleteForField()
          Returns the default cascade-delete setting.
 boolean getDefaultCascadePersistForField()
          Returns the default cascade-persist setting.
 boolean getDefaultCascadeRefreshForField()
          Returns the default cascade-refresh setting.
 boolean getDefaultCascadeUpdateForField()
          Returns the default cascade-update setting.
 java.util.Map getDefaultFactoryProperties()
          Method to return the default factory properties for this API.
 org.datanucleus.store.ExecutionContext getExecutionContext(java.lang.Object obj)
          Method to return the ExecutionContext (if any) associated with the passed object.
 java.lang.Object getIdForObject(java.lang.Object obj)
          Method to return the object identity for the passed persistable object.
 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.
 org.datanucleus.state.LifeCycleState getLifeCycleState(int stateType)
          Returns the LifeCycleState for the state constant.
 java.lang.String getName()
          Accessor for the name of the API.
 java.lang.Object getNewApplicationIdentityObjectId(org.datanucleus.ClassLoaderResolver clr, org.datanucleus.metadata.AbstractClassMetaData acmd, java.lang.String value)
          Utility to create a new application identity when you know the metadata for the target class, and the toString() output of the identity.
 java.lang.Object getNewApplicationIdentityObjectId(java.lang.Class cls, java.lang.Object key)
          Method to return a new object identity for the specified class, and key (possibly toString() output).
 java.lang.Object getNewApplicationIdentityObjectId(java.lang.Object pc, org.datanucleus.metadata.AbstractClassMetaData cmd)
          Method to create a new object identity for the passed object with the supplied MetaData.
 java.lang.Object getNewSingleFieldIdentity(java.lang.Class idType, java.lang.Class pcType, java.lang.Object value)
          Utility to create a new SingleFieldIdentity using reflection when you know the type of the PersistenceCapable, and also which SingleFieldIdentity, and the value of the key.
 java.lang.Object getObjectId(org.datanucleus.store.ObjectProvider sm)
          Accessor for the object id from the StateManager for this object.
 java.lang.String getObjectState(java.lang.Object obj)
          Accessor for the object state.
 java.lang.Object getPersistenceManager(java.lang.Object obj)
          Accessor for the persistence manager for this object.
 java.lang.String getSingleFieldIdentityClassNameForByte()
          Accessor for the class name to use for identities when there is a single Byte/byte field.
 java.lang.String getSingleFieldIdentityClassNameForChar()
          Accessor for the class name to use for identities when there is a single Character/char field.
 java.lang.String getSingleFieldIdentityClassNameForInt()
          Accessor for the class name to use for identities when there is a single Integer/int field.
 java.lang.String getSingleFieldIdentityClassNameForLong()
          Accessor for the class name to use for identities when there is a single Long/long field.
 java.lang.String getSingleFieldIdentityClassNameForObject()
          Accessor for the class name to use for identities when there is a single Object field.
 java.lang.String getSingleFieldIdentityClassNameForShort()
          Accessor for the class name to use for identities when there is a single Short/short field.
 java.lang.String getSingleFieldIdentityClassNameForString()
          Accessor for the class name to use for identities when there is a single String field.
 java.lang.Class getTargetClassForSingleFieldIdentity(java.lang.Object id)
          Accessor for the target class for the specified single field application-identity.
 java.lang.String getTargetClassNameForSingleFieldIdentity(java.lang.Object id)
          Accessor for the target class name for the specified single field identity.
 java.lang.Object getTargetKeyForSingleFieldIdentity(java.lang.Object id)
          Accessor for the key object for the specified single field application-identity.
 java.lang.RuntimeException getUserExceptionForException(java.lang.String msg, java.lang.Exception e)
          Convenience method to return an exception to throw for this API when an unexpected exception occurs.
 java.lang.Object getVersion(org.datanucleus.store.ObjectProvider sm)
          Accessor for the version from the StateManager for this object.
 java.lang.Object getVersionForObject(java.lang.Object obj)
          Method to return the object version for the passed persistable object.
 boolean isDatastoreIdentity(java.lang.Object id)
           
 boolean isDeleted(java.lang.Object obj)
          Accessor for whether the passed object is deleted.
 boolean isDetachable(java.lang.Object obj)
          Method to return if the passed object is detachable using this API.
 boolean isDetached(java.lang.Object obj)
          Accessor for whether the passed object is detached.
 boolean isDirty(java.lang.Object obj)
          Accessor for whether the passed object is dirty.
 boolean isLoaded(org.datanucleus.store.ObjectProvider sm, int fieldNumber)
          Accessor for whether a field is loaded for the object managed by the StateManager
 boolean isManaged(java.lang.Object pc)
          Whether the provided object is currently managed (has an ObjectManager).
 boolean isNew(java.lang.Object obj)
          Accessor for whether the passed object is new.
 boolean isPersistable(java.lang.Class cls)
          Utility method to check if the specified class is of a type that can be persisted for this API.
 boolean isPersistable(java.lang.Object obj)
          Method to return if the passed object is persistable using this API.
 boolean isPersistent(java.lang.Object obj)
          Accessor for whether the passed object is persistent.
 boolean isSingleFieldIdentity(java.lang.Object id)
          Accessor for whether the passed identity is a valid single-field application-identity for this API.
 boolean isSingleFieldIdentityClass(java.lang.String className)
          Checks whether the passed class name is valid for a single field application-identity for this API.
 boolean isTransactional(java.lang.Object obj)
          Accessor for whether the passed object is transactional.
 boolean isValidPrimaryKeyClass(java.lang.Class pkClass, org.datanucleus.metadata.AbstractClassMetaData cmd, org.datanucleus.ClassLoaderResolver clr, int noOfPkFields, org.datanucleus.metadata.MetaDataManager mmgr)
          Utility to check if a primary-key class is valid.
 void makeDirty(java.lang.Object obj, java.lang.String member)
           
 void makeFieldDirty(java.lang.Object obj, java.lang.String fieldName)
          Method to make the field dirty in the object.
 org.datanucleus.StateManager newStateManager(org.datanucleus.store.ExecutionContext ec, org.datanucleus.metadata.AbstractClassMetaData acmd)
          Method to create a new StateManager for the ObjectManager and class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static final org.datanucleus.util.Localiser LOCALISER
Constructor Detail

JPAAdapter

public JPAAdapter()
Method Detail

getName

public java.lang.String getName()
Accessor for the name of the API.

Specified by:
getName in interface org.datanucleus.api.ApiAdapter
Returns:
Name of the API

isManaged

public boolean isManaged(java.lang.Object pc)
Whether the provided object is currently managed (has an ObjectManager).

Specified by:
isManaged in interface org.datanucleus.api.ApiAdapter
Returns:
Whether it is managed

getExecutionContext

public org.datanucleus.store.ExecutionContext getExecutionContext(java.lang.Object obj)
Method to return the ExecutionContext (if any) associated with the passed object. Supports persistable objects, and PersistenceManager.

Specified by:
getExecutionContext in interface org.datanucleus.api.ApiAdapter
Parameters:
obj - The object
Returns:
The ExecutionContext

newStateManager

public org.datanucleus.StateManager newStateManager(org.datanucleus.store.ExecutionContext ec,
                                                    org.datanucleus.metadata.AbstractClassMetaData acmd)
Method to create a new StateManager for the ObjectManager and class.

Specified by:
newStateManager in interface org.datanucleus.api.ApiAdapter
Parameters:
ec - execution context
acmd - MetaData for the class/interface

getLifeCycleState

public org.datanucleus.state.LifeCycleState getLifeCycleState(int stateType)
Returns the LifeCycleState for the state constant.

Specified by:
getLifeCycleState in interface org.datanucleus.api.ApiAdapter
Parameters:
stateType - the type as integer
Returns:
the type as LifeCycleState object

isPersistent

public boolean isPersistent(java.lang.Object obj)
Accessor for whether the passed object is persistent.

Specified by:
isPersistent in interface org.datanucleus.api.ApiAdapter
Parameters:
obj - The object
Returns:
Whether it is persistent

isNew

public boolean isNew(java.lang.Object obj)
Accessor for whether the passed object is new.

Specified by:
isNew in interface org.datanucleus.api.ApiAdapter
Parameters:
obj - The object
Returns:
Whether it is new

isDirty

public boolean isDirty(java.lang.Object obj)
Accessor for whether the passed object is dirty.

Specified by:
isDirty in interface org.datanucleus.api.ApiAdapter
Parameters:
obj - The object
Returns:
Whether it is dirty

isDeleted

public boolean isDeleted(java.lang.Object obj)
Accessor for whether the passed object is deleted.

Specified by:
isDeleted in interface org.datanucleus.api.ApiAdapter
Parameters:
obj - The object
Returns:
Whether it is deleted

isDetached

public boolean isDetached(java.lang.Object obj)
Accessor for whether the passed object is detached.

Specified by:
isDetached in interface org.datanucleus.api.ApiAdapter
Parameters:
obj - The object
Returns:
Whether it is detached

isTransactional

public boolean isTransactional(java.lang.Object obj)
Accessor for whether the passed object is transactional.

Specified by:
isTransactional in interface org.datanucleus.api.ApiAdapter
Parameters:
obj - The object
Returns:
Whether it is transactional

isPersistable

public boolean isPersistable(java.lang.Object obj)
Method to return if the passed object is persistable using this API.

Specified by:
isPersistable in interface org.datanucleus.api.ApiAdapter
Parameters:
obj - The object
Returns:
Whether it is persistable

isPersistable

public boolean isPersistable(java.lang.Class cls)
Utility method to check if the specified class is of a type that can be persisted for this API.

Specified by:
isPersistable in interface org.datanucleus.api.ApiAdapter
Parameters:
cls - The class to check
Returns:
Whether the class is persistable

isDetachable

public boolean isDetachable(java.lang.Object obj)
Method to return if the passed object is detachable using this API. Returns whether the object is an instance of javax.jdo.spi.Detachable.

Specified by:
isDetachable in interface org.datanucleus.api.ApiAdapter
Parameters:
obj - The object
Returns:
Whether it is detachable

getObjectState

public java.lang.String getObjectState(java.lang.Object obj)
Accessor for the object state.

Specified by:
getObjectState in interface org.datanucleus.api.ApiAdapter
Parameters:
obj - Object
Returns:
The state ("persistent-clean", "detached-dirty" etc)

makeDirty

public void makeDirty(java.lang.Object obj,
                      java.lang.String member)
Specified by:
makeDirty in interface org.datanucleus.api.ApiAdapter

getIdForObject

public java.lang.Object getIdForObject(java.lang.Object obj)
Method to return the object identity for the passed persistable object. Returns null if it is not persistable, or has no identity.

Specified by:
getIdForObject in interface org.datanucleus.api.ApiAdapter
Parameters:
obj - The object
Returns:
The identity

getVersionForObject

public java.lang.Object getVersionForObject(java.lang.Object obj)
Method to return the object version for the passed persistable object. Returns null if it is not persistable, or not versioned.

Specified by:
getVersionForObject in interface org.datanucleus.api.ApiAdapter
Parameters:
obj - The object
Returns:
The version

isValidPrimaryKeyClass

public boolean isValidPrimaryKeyClass(java.lang.Class pkClass,
                                      org.datanucleus.metadata.AbstractClassMetaData cmd,
                                      org.datanucleus.ClassLoaderResolver clr,
                                      int noOfPkFields,
                                      org.datanucleus.metadata.MetaDataManager mmgr)
Utility to check if a primary-key class is valid. Will throw a InvalidPrimaryKeyException if it is invalid, otherwise returning true.

Specified by:
isValidPrimaryKeyClass in interface org.datanucleus.api.ApiAdapter
Parameters:
pkClass - The Primary Key class
cmd - AbstractClassMetaData for the PersistenceCapable class
clr - the ClassLoaderResolver
noOfPkFields - Number of primary key fields
mmgr - MetaData manager
Returns:
Whether it is valid

isSingleFieldIdentity

public boolean isSingleFieldIdentity(java.lang.Object id)
Accessor for whether the passed identity is a valid single-field application-identity for this API.

Specified by:
isSingleFieldIdentity in interface org.datanucleus.api.ApiAdapter
Returns:
Whether it is valid

isDatastoreIdentity

public boolean isDatastoreIdentity(java.lang.Object id)
Specified by:
isDatastoreIdentity in interface org.datanucleus.api.ApiAdapter

isSingleFieldIdentityClass

public boolean isSingleFieldIdentityClass(java.lang.String className)
Checks whether the passed class name is valid for a single field application-identity for this API.

Specified by:
isSingleFieldIdentityClass in interface org.datanucleus.api.ApiAdapter
Parameters:
className - the full class name
Returns:
Whether it is a single field class

getSingleFieldIdentityClassNameForLong

public java.lang.String getSingleFieldIdentityClassNameForLong()
Accessor for the class name to use for identities when there is a single Long/long field.

Specified by:
getSingleFieldIdentityClassNameForLong in interface org.datanucleus.api.ApiAdapter
Returns:
Class name of identity class

getSingleFieldIdentityClassNameForInt

public java.lang.String getSingleFieldIdentityClassNameForInt()
Accessor for the class name to use for identities when there is a single Integer/int field.

Specified by:
getSingleFieldIdentityClassNameForInt in interface org.datanucleus.api.ApiAdapter
Returns:
Class name of identity class

getSingleFieldIdentityClassNameForShort

public java.lang.String getSingleFieldIdentityClassNameForShort()
Accessor for the class name to use for identities when there is a single Short/short field.

Specified by:
getSingleFieldIdentityClassNameForShort in interface org.datanucleus.api.ApiAdapter
Returns:
Class name of identity class

getSingleFieldIdentityClassNameForByte

public java.lang.String getSingleFieldIdentityClassNameForByte()
Accessor for the class name to use for identities when there is a single Byte/byte field.

Specified by:
getSingleFieldIdentityClassNameForByte in interface org.datanucleus.api.ApiAdapter
Returns:
Class name of identity class

getSingleFieldIdentityClassNameForChar

public java.lang.String getSingleFieldIdentityClassNameForChar()
Accessor for the class name to use for identities when there is a single Character/char field.

Specified by:
getSingleFieldIdentityClassNameForChar in interface org.datanucleus.api.ApiAdapter
Returns:
Class name of identity class

getSingleFieldIdentityClassNameForString

public java.lang.String getSingleFieldIdentityClassNameForString()
Accessor for the class name to use for identities when there is a single String field.

Specified by:
getSingleFieldIdentityClassNameForString in interface org.datanucleus.api.ApiAdapter
Returns:
Class name of identity class

getSingleFieldIdentityClassNameForObject

public java.lang.String getSingleFieldIdentityClassNameForObject()
Accessor for the class name to use for identities when there is a single Object field.

Specified by:
getSingleFieldIdentityClassNameForObject in interface org.datanucleus.api.ApiAdapter
Returns:
Class name of identity class

getTargetClassForSingleFieldIdentity

public java.lang.Class getTargetClassForSingleFieldIdentity(java.lang.Object id)
Accessor for the target class for the specified single field application-identity.

Specified by:
getTargetClassForSingleFieldIdentity in interface org.datanucleus.api.ApiAdapter
Parameters:
id - The identity
Returns:
The target class

getTargetClassNameForSingleFieldIdentity

public java.lang.String getTargetClassNameForSingleFieldIdentity(java.lang.Object id)
Accessor for the target class name for the specified single field identity.

Specified by:
getTargetClassNameForSingleFieldIdentity in interface org.datanucleus.api.ApiAdapter
Parameters:
id - The identity
Returns:
The target class name

getTargetKeyForSingleFieldIdentity

public java.lang.Object getTargetKeyForSingleFieldIdentity(java.lang.Object id)
Accessor for the key object for the specified single field application-identity.

Specified by:
getTargetKeyForSingleFieldIdentity in interface org.datanucleus.api.ApiAdapter
Parameters:
id - The identity
Returns:
The key object

getKeyTypeForSingleFieldIdentityType

public 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.

Specified by:
getKeyTypeForSingleFieldIdentityType in interface org.datanucleus.api.ApiAdapter
Parameters:
idType - Single field identity type
Returns:
key type

getNewSingleFieldIdentity

public java.lang.Object getNewSingleFieldIdentity(java.lang.Class idType,
                                                  java.lang.Class pcType,
                                                  java.lang.Object value)
Utility to create a new SingleFieldIdentity using reflection when you know the type of the PersistenceCapable, and also which SingleFieldIdentity, and the value of the key.

Specified by:
getNewSingleFieldIdentity in interface org.datanucleus.api.ApiAdapter
Parameters:
idType - Type of SingleFieldIdentity
pcType - Type of the PersistenceCapable
value - The value for the identity (the Long, or Int, or ... etc).
Returns:
Single field identity
Throws:
org.datanucleus.exceptions.NucleusException - if invalid input is received

getNewApplicationIdentityObjectId

public java.lang.Object getNewApplicationIdentityObjectId(org.datanucleus.ClassLoaderResolver clr,
                                                          org.datanucleus.metadata.AbstractClassMetaData acmd,
                                                          java.lang.String value)
Utility to create a new application identity when you know the metadata for the target class, and the toString() output of the identity.

Specified by:
getNewApplicationIdentityObjectId in interface org.datanucleus.api.ApiAdapter
Parameters:
clr - ClassLoader resolver
acmd - MetaData for the target class
value - String form of the key
Returns:
The identity
Throws:
org.datanucleus.exceptions.NucleusException - if invalid input is received

getNewApplicationIdentityObjectId

public java.lang.Object getNewApplicationIdentityObjectId(java.lang.Object pc,
                                                          org.datanucleus.metadata.AbstractClassMetaData cmd)
Method to create a new object identity for the passed object with the supplied MetaData. Only applies to application-identity cases.

Specified by:
getNewApplicationIdentityObjectId in interface org.datanucleus.api.ApiAdapter
Parameters:
pc - The persistable object
cmd - Its metadata
Returns:
The new identity object

getNewApplicationIdentityObjectId

public java.lang.Object getNewApplicationIdentityObjectId(java.lang.Class cls,
                                                          java.lang.Object key)
Method to return a new object identity for the specified class, and key (possibly toString() output).

Specified by:
getNewApplicationIdentityObjectId in interface org.datanucleus.api.ApiAdapter
Parameters:
cls - Persistable class
key - form of the object id
Returns:
The object identity

allowPersistOfDeletedObject

public boolean allowPersistOfDeletedObject()
Whether the API allows (re-)persistence of a deleted object.

Specified by:
allowPersistOfDeletedObject in interface org.datanucleus.api.ApiAdapter
Returns:
Whether you can call persist on a deleted object

allowDeleteOfNonPersistentObject

public boolean allowDeleteOfNonPersistentObject()
Whether the API allows deletion of a non-persistent object.

Specified by:
allowDeleteOfNonPersistentObject in interface org.datanucleus.api.ApiAdapter
Returns:
Whether you can call delete on an object not yet persisted

allowReadFieldOfDeletedObject

public boolean allowReadFieldOfDeletedObject()
Whether the API allows reading a field of a deleted object.

Specified by:
allowReadFieldOfDeletedObject in interface org.datanucleus.api.ApiAdapter
Returns:
Whether you can read after deleting

clearLoadedFlagsOnDeleteObject

public boolean clearLoadedFlagsOnDeleteObject()
Whether the API requires clearing of the fields of an object when it is deleted.

Specified by:
clearLoadedFlagsOnDeleteObject in interface org.datanucleus.api.ApiAdapter
Returns:
Whether to clear loaded fields at delete

getDefaultCascadePersistForField

public boolean getDefaultCascadePersistForField()
Returns the default cascade-persist setting. JPA defaults to not persisting by reachability.

Specified by:
getDefaultCascadePersistForField in interface org.datanucleus.api.ApiAdapter
Returns:
The default cascade-persist (false)

getDefaultCascadeUpdateForField

public boolean getDefaultCascadeUpdateForField()
Returns the default cascade-update setting. JPA defaults to not updating by reachability.

Specified by:
getDefaultCascadeUpdateForField in interface org.datanucleus.api.ApiAdapter
Returns:
The default cascade-update (false)

getDefaultCascadeDeleteForField

public boolean getDefaultCascadeDeleteForField()
Returns the default cascade-delete setting. JPA defaults to not deleting by reachability.

Specified by:
getDefaultCascadeDeleteForField in interface org.datanucleus.api.ApiAdapter
Returns:
The default cascade-delete (false)

getDefaultCascadeRefreshForField

public boolean getDefaultCascadeRefreshForField()
Returns the default cascade-refresh setting.

Specified by:
getDefaultCascadeRefreshForField in interface org.datanucleus.api.ApiAdapter
Returns:
The default cascade-refresh (false)

getDefaultFactoryProperties

public java.util.Map getDefaultFactoryProperties()
Method to return the default factory properties for this API.

Specified by:
getDefaultFactoryProperties in interface org.datanucleus.api.ApiAdapter
Returns:
The default props

getObjectId

public java.lang.Object getObjectId(org.datanucleus.store.ObjectProvider sm)
Accessor for the object id from the StateManager for this object.

Specified by:
getObjectId in interface org.datanucleus.api.ApiAdapter
Parameters:
sm - StateManager
Returns:
object id

getVersion

public java.lang.Object getVersion(org.datanucleus.store.ObjectProvider sm)
Accessor for the version from the StateManager for this object.

Specified by:
getVersion in interface org.datanucleus.api.ApiAdapter
Parameters:
sm - StateManager

isLoaded

public boolean isLoaded(org.datanucleus.store.ObjectProvider sm,
                        int fieldNumber)
Accessor for whether a field is loaded for the object managed by the StateManager

Specified by:
isLoaded in interface org.datanucleus.api.ApiAdapter
Parameters:
sm - StateManager
fieldNumber - Number of the field
Returns:
Whether it is loaded

getPersistenceManager

public java.lang.Object getPersistenceManager(java.lang.Object obj)
Accessor for the persistence manager for this object. The returned object will be a JPA EntityManager or null if not managed.

Specified by:
getPersistenceManager in interface org.datanucleus.api.ApiAdapter
Parameters:
obj - The object
Returns:
The persistence manager

makeFieldDirty

public void makeFieldDirty(java.lang.Object obj,
                           java.lang.String fieldName)
Method to make the field dirty in the object.

Specified by:
makeFieldDirty in interface org.datanucleus.api.ApiAdapter
Parameters:
obj - Object
fieldName - Name of the field to make dirty

getUserExceptionForException

public java.lang.RuntimeException getUserExceptionForException(java.lang.String msg,
                                                               java.lang.Exception e)
Convenience method to return an exception to throw for this API when an unexpected exception occurs. This is considered a user exception.

Specified by:
getUserExceptionForException in interface org.datanucleus.api.ApiAdapter
Parameters:
msg - The message
e - The cause
Returns:
The JPA exception

getDataStoreExceptionForException

public java.lang.RuntimeException getDataStoreExceptionForException(java.lang.String msg,
                                                                    java.lang.Exception e)
Convenience method to return a datastore exception appropriate for this API.

Specified by:
getDataStoreExceptionForException in interface org.datanucleus.api.ApiAdapter
Parameters:
msg - The message
e - Any root cause exception
Returns:
The exception


Copyright © 2011. All Rights Reserved.