org.datanucleus.jdo
Class JDOAdapter

java.lang.Object
  extended by org.datanucleus.jdo.JDOAdapter
All Implemented Interfaces:
java.io.Serializable, ApiAdapter

public class JDOAdapter
extends java.lang.Object
implements ApiAdapter

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

See Also:
Serialized Form

Field Summary
protected static Localiser LOCALISER
           
 
Constructor Summary
JDOAdapter()
           
 
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.
 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.
 ExecutionContext getExecutionContext(java.lang.Object obj)
          Method to return the ObjectManager (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.
 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(ClassLoaderResolver clr, 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, 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(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 a user exception appropriate for this API.
 java.lang.Object getVersion(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)
          Accessor for whether the passed identity is a valid datastore-identity for this API.
 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(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, AbstractClassMetaData cmd, ClassLoaderResolver clr, int noOfPkFields, MetaDataManager mmgr)
          Utility to check if a primary-key class is valid.
 void makeDirty(java.lang.Object obj, java.lang.String member)
          Method to make the member of the persistable object dirty.
 void makeFieldDirty(java.lang.Object obj, java.lang.String fieldName)
          Method to make the field dirty in the object.
 StateManager newStateManager(ExecutionContext ec, 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 Localiser LOCALISER
Constructor Detail

JDOAdapter

public JDOAdapter()
Method Detail

getName

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

Specified by:
getName in interface 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 ApiAdapter
Returns:
Whether it is managed

getExecutionContext

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

Specified by:
getExecutionContext in interface ApiAdapter
Parameters:
obj - The object
Returns:
The ObjectManager

newStateManager

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

Specified by:
newStateManager in interface ApiAdapter
Parameters:
ec - ExecutionContext
acmd - MetaData for the class/interface

getLifeCycleState

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

Specified by:
getLifeCycleState in interface 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 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 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 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 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 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 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. Returns whether the object is an instance of javax.jdo.spi.PersistenceCapable.

Specified by:
isPersistable in interface 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. Checks that it implements javax.jdo.spi.PersistenceCapable.

Specified by:
isPersistable in interface 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 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 ApiAdapter
Parameters:
obj - Object
Returns:
The state ("persistent-clean", "detached-dirty" etc)

makeDirty

public void makeDirty(java.lang.Object obj,
                      java.lang.String member)
Description copied from interface: ApiAdapter
Method to make the member of the persistable object dirty.

Specified by:
makeDirty in interface ApiAdapter
Parameters:
obj - The object
member - Name of the member

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 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 ApiAdapter
Parameters:
obj - The object
Returns:
The version

isValidPrimaryKeyClass

public boolean isValidPrimaryKeyClass(java.lang.Class pkClass,
                                      AbstractClassMetaData cmd,
                                      ClassLoaderResolver clr,
                                      int noOfPkFields,
                                      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 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 ApiAdapter
Returns:
Whether it is valid

isDatastoreIdentity

public boolean isDatastoreIdentity(java.lang.Object id)
Description copied from interface: ApiAdapter
Accessor for whether the passed identity is a valid datastore-identity for this API.

Specified by:
isDatastoreIdentity in interface ApiAdapter
Returns:
Whether it is valid

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 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 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 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 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 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 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 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 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 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 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 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 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 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:
NucleusException - if invalid input is received

getNewApplicationIdentityObjectId

public java.lang.Object getNewApplicationIdentityObjectId(ClassLoaderResolver clr,
                                                          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 ApiAdapter
Parameters:
clr - ClassLoader resolver
acmd - MetaData for the target class
value - String form of the key
Returns:
The identity
Throws:
NucleusException - if invalid input is received

getNewApplicationIdentityObjectId

public java.lang.Object getNewApplicationIdentityObjectId(java.lang.Object pc,
                                                          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 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 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 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 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 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 ApiAdapter
Returns:
Whether to clear loaded fields at delete

getDefaultCascadePersistForField

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

Specified by:
getDefaultCascadePersistForField in interface ApiAdapter
Returns:
The default value for cascade-persist (true)

getDefaultCascadeUpdateForField

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

Specified by:
getDefaultCascadeUpdateForField in interface ApiAdapter
Returns:
The default cascade-update (true)

getDefaultCascadeDeleteForField

public boolean getDefaultCascadeDeleteForField()
Returns the default cascade-delete setting. JDO defaults to not deleting by reachability (unless using delete dependent)

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

getDefaultCascadeRefreshForField

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

Specified by:
getDefaultCascadeRefreshForField in interface 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 ApiAdapter
Returns:
The default props

getObjectId

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

Specified by:
getObjectId in interface ApiAdapter
Parameters:
sm - StateManager
Returns:
object id

getVersion

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

Specified by:
getVersion in interface ApiAdapter
Parameters:
sm - StateManager

isLoaded

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

Specified by:
isLoaded in interface 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 JDO PersistenceManager or null if not managed.

Specified by:
getPersistenceManager in interface 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 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 a user exception appropriate for this API.

Specified by:
getUserExceptionForException in interface ApiAdapter
Parameters:
msg - The message
e - The cause
Returns:
The JDO 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 ApiAdapter
Parameters:
msg - The message
e - Any root cause exception
Returns:
The exception


Copyright © 2011. All Rights Reserved.