org.datanucleus
Class ObjectManagerImpl

java.lang.Object
  extended by org.datanucleus.ObjectManagerImpl
All Implemented Interfaces:
ObjectManager

public class ObjectManagerImpl
extends java.lang.Object
implements ObjectManager

Representation of an ObjectManager. An object manager provides management for the persistence of objects into a datastore and the retrieval of these objects using various methods.

Caching

An ObjectManager has its own Level 1 cache. This stores objects against their identity. The Level 1 cache is typically a weak referenced map and so cached objects can be garbage collected. Objects are placed in the Level 1 cache during the transaction. The ObjectManagerFactory also has a Level 2 cache. This is used to allow cross-communication between ObjectManagers. Objects are placed in the Level 2 cache during commit() of a transaction. If an object is deleted during a transaction then it will be removed from the Level 2 cache at commit().

Transactions

An ObjectManager has a single transaction (the "current" transaction). The transaction can be "active" (if begin() has been called on it) or "inactive".

Persisted Objects

When an object involved in the current transaction it is enlisted (calling enlistInTransaction()). Its' identity is saved (in "txEnlistedIds") for use later in any "persistenceByReachability" process run at commit. Any object that is passed via makePersistent() will be stored (as an identity) in "txKnownPersistedIds" and objects persisted due to reachability from these objects will also have their identity stored (in "txFlushedNewIds"). All of this information is used in the "persistence-by-reachability-at-commit" process which detects if some objects originally persisted are no longer reachable and hence should not be persistent after all.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.datanucleus.ObjectManager
ObjectManager.ObjectManagerListener
 
Field Summary
protected static Localiser LOCALISER
          Localisation utility for output messages
 
Constructor Summary
ObjectManagerImpl(ObjectManagerFactoryImpl omf, java.lang.Object owner, java.lang.String userName, java.lang.String password)
          Constructor.
 
Method Summary
protected  org.datanucleus.ObjectManagerImpl.ThreadContextInfo acquireThreadContextInfo()
          Accessor for the thread context information, for the current thread.
 void addInternalFetchGroup(FetchGroup grp)
          Method to add a dynamic FetchGroup for use by this OMF.
 void addListener(java.lang.Object listener, java.lang.Class[] classes)
          Method to register a listener for instances of the specified classes.
 void addStateManager(StateManager sm)
          Method to add the object managed by the specified StateManager to the cache.
protected  void assertActiveTransaction()
          Method to assert if the current transaction is active.
 void assertClassPersistable(java.lang.Class cls)
          Method to assert if the specified class is Persistence Capable.
protected  void assertDetachable(java.lang.Object object)
          Method to assert if the specified object is Detachable.
protected  void assertHasImplementationCreator()
          Validates that an ImplementationCreator instance is accessible.
protected  void assertIsOpen()
          Method to assert if this Object Manager is open.
protected  void assertNotDetached(java.lang.Object object)
          Method to assert if the specified object is detached.
protected  void assertWritable()
          Method to assert if the current transaction is active or non transactional writes are allowed.
 void attachObject(java.lang.Object pc, boolean sco)
          Method to attach a persistent detached object.
 java.lang.Object attachObjectCopy(java.lang.Object pc, boolean sco)
          Method to attach a persistent detached object returning an attached copy of the object.
 void clearDirty()
          Method to clear all objects marked as dirty (whether directly or indirectly).
 void clearDirty(StateManager sm)
          Method to clear an object from the list of dirty objects.
 void close()
          Method to close the Persistence Manager.
 void deleteObject(java.lang.Object obj)
          Method to delete an object from the datastore.
 void deleteObjectInternal(java.lang.Object obj)
          Method to delete an object from persistence which should be called from internal calls only.
 void deleteObjects(java.util.Collection objs)
          Method to delete an array of objects from the datastore.
 void deleteObjects(java.lang.Object[] objs)
          Method to delete an array of objects from the datastore.
 void detachAll()
          Method to detach all objects in the ObjectManager.
 void detachObject(java.lang.Object obj, FetchPlanState state)
          Method to detach a persistent object without making a copy.
 java.lang.Object detachObjectCopy(java.lang.Object pc, FetchPlanState state)
          Detach a copy of the passed persistent object using the provided detach state.
 void disconnectLifecycleListener()
          Disconnect the registered LifecycleListener
 void disconnectSMCache()
          Disconnect SM instances, clear cache and reset settings
 void enlistInTransaction(StateManager sm)
          Method to enlist the specified StateManager in the current transaction.
 void evictAllObjects()
          Method to evict all current objects from L1 cache.
 void evictFromTransaction(StateManager sm)
          Method to evict the specified StateManager from the current transaction.
 void evictObject(java.lang.Object obj)
          Internal method to evict an object from L1 cache.
 void evictObjects(java.lang.Class cls, boolean subclasses)
          Method to evict all objects of the specified type (and optionaly its subclasses).
 boolean exists(java.lang.Object obj)
          Method to return if the specified object exists in the datastore.
 java.lang.Object findObject(java.lang.Object id, boolean validate, boolean checkInheritance, java.lang.String objectClassName)
          Accessor for an object given the object id.
 java.lang.Object findObject(java.lang.Object id, FieldValues fv)
          Accessor for an object given the object id.
 java.lang.Object findObject(java.lang.Object id, FieldValues fv, java.lang.Class cls, boolean ignoreCache)
          Accessor for an object given the object id.
 java.lang.Object findObjectUsingAID(java.lang.Class pcClass, FieldValues fv, boolean ignoreCache, boolean checkInheritance)
          Accessor for the StateManager of an object given the object AID.
 StateManager findStateManager(java.lang.Object pc)
          Method to find the StateManager for an object.
 void flush()
          Method callable from external APIs for user-management of flushing.
 void flushInternal(boolean flushToDatastore)
          This method flushes all dirty, new, and deleted instances to the datastore.
 ApiAdapter getApiAdapter()
          Accessor for the API adapter.
 CallbackHandler getCallbackHandler()
          Retrieve the callback handler for this ObjectManager.
 ClassLoaderResolver getClassLoaderResolver()
          Accessor for the ClassLoaderResolver
 boolean getCopyOnAttach()
          Accessor for whether to copy on attaching.
 boolean getDetachAllOnCommit()
          Accessor for whether to detach all objects on commit of the transaction.
 boolean getDetachOnClose()
          Deprecated.  
 Extent getExtent(java.lang.Class pcClass, boolean subclasses)
          Extents are collections of datastore objects managed by the datastore, not by explicit user operations on collections.
protected  FetchGroupManager getFetchGroupManager()
          Convenience accessor for the FetchGroupManager.
 java.util.Set getFetchGroupsWithName(java.lang.String name)
          Accessor for the fetch groups for the specified name.
 FetchPlan getFetchPlan()
          Acessor for the current FetchPlan
 boolean getIgnoreCache()
          Accessor for whether to ignore the cache.
 FetchGroup getInternalFetchGroup(java.lang.Class cls, java.lang.String name)
          Accessor for an internal fetch group for the specified class.
 java.util.Set getManagedObjects()
          Accessor for the currently managed objects for the current transaction.
 java.util.Set getManagedObjects(java.lang.Class[] classes)
          Accessor for the currently managed objects for the current transaction.
 java.util.Set getManagedObjects(java.lang.String[] states)
          Accessor for the currently managed objects for the current transaction.
 java.util.Set getManagedObjects(java.lang.String[] states, java.lang.Class[] classes)
          Accessor for the currently managed objects for the current transaction.
 MetaDataManager getMetaDataManager()
          Accessor for the MetaDataManager for this ObjectManager (and its factory).
 boolean getMultithreaded()
          Accessor for whether the Persistence Manager is multithreaded.
 java.lang.Object getObjectFromCache(java.lang.Object id)
          Convenience method to access an object in the cache.
 ObjectManagerFactoryImpl getObjectManagerFactory()
          Accessor for the ObjectManagerFactory to which this manager belongs.
 OMFContext getOMFContext()
          Gets the context in which this ObjectManager is running
 java.lang.Object getOwner()
          Method to return the owner PM/EM object.
 StateManager getStateManagerById(java.lang.Object id)
          Accessor for the StateManager of an object given the object id.
 StoreManager getStoreManager()
          Accessor for the Store Manager.
protected  org.datanucleus.ObjectManagerImpl.ThreadContextInfo getThreadContextInfo()
          Get the current ThreadContextInfo assigned to the current thread without changing the reference counter.
 Transaction getTransaction()
          Accessor for the current transaction.
 boolean hasPersistenceInformationForClass(java.lang.Class cls)
          Utility method to check if the specified class has reachable metadata or annotations.
 void hereIsStateManager(StateManager sm, java.lang.Object pc)
          Method to add the StateManager for an object to this ObjectManager's list.
protected  void initialiseLevel1Cache()
          Method to initialise the L1 cache.
 boolean isClosed()
          Accessor for whether this ObjectManager is closed.
 boolean isDelayDatastoreOperationsEnabled()
          Whether the datastore operations are delayed until commit/flush.
 boolean isEnlistedInTransaction(java.lang.Object id)
          Method to return if an object is enlisted in the current transaction.
 boolean isFlushing()
          Returns whether the ObjectManager is in the process of flushing.
 boolean isInserting(java.lang.Object pc)
          Tests whether this persistable object is in the process of being inserted.
 boolean isManagingRelations()
          Returns whether this ObjectManager is currently performing the manage relationships task.
 boolean isRunningDetachAllOnCommit()
          Accessor for whether this ObjectManager is currently running detachAllOnCommit.
 void makeObjectNontransactional(java.lang.Object obj)
          Method to make an object nontransactional.
 void makeObjectTransactional(java.lang.Object obj)
          Method to make an object transactional.
 void makeObjectTransient(java.lang.Object obj, FetchPlanState state)
          Method to migrate an object to transient state.
 void markDirty(StateManager sm, boolean directUpdate)
          Method to mark an object (StateManager) as dirty.
 void markManagedRelationDirty(StateManager sm)
          Method to mark the specified StateManager as needing an update due to managed relation constraints.
 java.lang.Object newInstance(java.lang.Class cls)
          Method to generate an instance of an interface, abstract class, or concrete PC class.
 java.lang.Object newObjectId(java.lang.Class pcClass, java.lang.Object key)
          This method returns an object id instance corresponding to the pcClass and key arguments.
 java.lang.Object newObjectId(java.lang.String className, java.lang.Object pc)
          This method returns an object id instance corresponding to the class name, and the passed object (when using app identity).
 Query newQuery()
          Construct an empty query instance.
protected  void performManagedRelationships()
          Method to perform managed relationships tasks.
 java.lang.Object persistObject(java.lang.Object obj)
          Method to make an object persistent.
 java.lang.Object persistObjectInternal(java.lang.Object obj, FieldValues preInsertChanges, StateManager ownerSM, int ownerFieldNum, int objectType)
          Method to make an object persistent which should be called from internal calls only.
 void postBegin()
          Method to perform any post-begin checks.
 void postClose()
          Method called during the close process.
 void postCommit()
          Commit any changes made to objects managed by the persistence manager to the database.
 void preCommit()
          Method to perform any pre-commit checks.
 void preRollback()
          Rollback any changes made to objects managed by the persistence manager to the database.
 void putObjectIntoCache(StateManager sm)
          Convenience method to add an object to the L1 cache.
 void refreshAllObjects()
          Method to do a refresh of all objects.
 void refreshObject(java.lang.Object obj)
          Method to do a refresh of an object, updating it from its datastore representation.
protected  void releaseThreadContextInfo()
          Method to remove the current thread context info for the current thread, after the reference counter reached 0.
 void removeAllInstanceLifecycleListeners()
          This method removes all previously registered lifecycle listeners.
protected  void removeInternalFetchGroup(FetchGroup grp)
          Method to remove a dynamic FetchGroup from use by this OMF.
 void removeListener(java.lang.Object listener)
          Method to remove a currently registered listener.
 void removeObjectFromCache(java.lang.Object pc, java.lang.Object id)
          Convenience method to evict an object from the L1 cache.
 void removeStateManager(StateManager sm)
          Method to remove the object managed by the specified StateManager from the cache.
 void replaceObjectId(java.lang.Object pc, java.lang.Object oldID, java.lang.Object newID)
          Replace the previous object id for a persistable object with a new one.
 void retrieveObject(java.lang.Object obj, boolean fgOnly)
          Method to retrieve an object.
 void setCopyOnAttach(boolean flag)
          Mutator for whether to copy on attaching.
 void setDetachAllOnCommit(boolean flag)
          Mutator for whether to detach all objects on commit of the transaction.
 void setDetachOnClose(boolean flag)
          Deprecated.  
 void setIgnoreCache(boolean flag)
          Mutator for whether to ignore the cache.
 void setMultithreaded(boolean flag)
          Mutator for whether the Persistence Manager is multithreaded.
 
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
Localisation utility for output messages

Constructor Detail

ObjectManagerImpl

public ObjectManagerImpl(ObjectManagerFactoryImpl omf,
                         java.lang.Object owner,
                         java.lang.String userName,
                         java.lang.String password)
Constructor.

Parameters:
omf - Object Manager Factory
owner - The owning PM/EM
userName - Username for the datastore
password - Password for the datastore
Throws:
NucleusUserException - if an error occurs allocating the necessary requested components
Method Detail

initialiseLevel1Cache

protected void initialiseLevel1Cache()
Method to initialise the L1 cache.

Throws:
NucleusUserException - if an error occurs setting up the L1 cache

isClosed

public boolean isClosed()
Accessor for whether this ObjectManager is closed.

Specified by:
isClosed in interface ObjectManager
Returns:
Whether this manager is closed.

getClassLoaderResolver

public ClassLoaderResolver getClassLoaderResolver()
Accessor for the ClassLoaderResolver

Specified by:
getClassLoaderResolver in interface ObjectManager
Returns:
the ClassLoaderResolver

getStoreManager

public StoreManager getStoreManager()
Accessor for the Store Manager.

Specified by:
getStoreManager in interface ObjectManager
Returns:
StoreManager

getObjectManagerFactory

public ObjectManagerFactoryImpl getObjectManagerFactory()
Accessor for the ObjectManagerFactory to which this manager belongs.

Specified by:
getObjectManagerFactory in interface ObjectManager
Returns:
The OMF

getApiAdapter

public ApiAdapter getApiAdapter()
Accessor for the API adapter.

Specified by:
getApiAdapter in interface ObjectManager
Returns:
API adapter.

getFetchPlan

public FetchPlan getFetchPlan()
Acessor for the current FetchPlan

Specified by:
getFetchPlan in interface ObjectManager
Returns:
FetchPlan

getOwner

public java.lang.Object getOwner()
Method to return the owner PM/EM object. For JDO this will return the PersistenceManager owning this ObjectManager. For JPA this will return the EntityManager owning this ObjectManager.

Specified by:
getOwner in interface ObjectManager
Returns:
The owner manager object

getOMFContext

public OMFContext getOMFContext()
Gets the context in which this ObjectManager is running

Specified by:
getOMFContext in interface ObjectManager
Returns:
Returns the context.

getMetaDataManager

public MetaDataManager getMetaDataManager()
Accessor for the MetaDataManager for this ObjectManager (and its factory). This is used as the interface to MetaData in the ObjectManager/Factory.

Specified by:
getMetaDataManager in interface ObjectManager
Returns:
Returns the MetaDataManager.

setMultithreaded

public void setMultithreaded(boolean flag)
Mutator for whether the Persistence Manager is multithreaded.

Specified by:
setMultithreaded in interface ObjectManager
Parameters:
flag - Whether to run multithreaded.

getMultithreaded

public boolean getMultithreaded()
Accessor for whether the Persistence Manager is multithreaded.

Specified by:
getMultithreaded in interface ObjectManager
Returns:
Whether to run multithreaded.

setDetachOnClose

public void setDetachOnClose(boolean flag)
Deprecated. 

Mutator for whether to detach objects on close of the ObjectManager. This is an extension and will not work when in JCA mode.

Specified by:
setDetachOnClose in interface ObjectManager
Parameters:
flag - Whether to detach on close.

getDetachOnClose

public boolean getDetachOnClose()
Deprecated. 

Accessor for whether to detach objects on close of the ObjectManager. This is an extension and will not work when in JCA mode.

Returns:
Whether to detach on close.

setDetachAllOnCommit

public void setDetachAllOnCommit(boolean flag)
Mutator for whether to detach all objects on commit of the transaction.

Specified by:
setDetachAllOnCommit in interface ObjectManager
Parameters:
flag - Whether to detach all on commit.

getDetachAllOnCommit

public boolean getDetachAllOnCommit()
Accessor for whether to detach all objects on commit of the transaction.

Specified by:
getDetachAllOnCommit in interface ObjectManager
Returns:
Whether to detach all on commit.

setCopyOnAttach

public void setCopyOnAttach(boolean flag)
Mutator for whether to copy on attaching.

Specified by:
setCopyOnAttach in interface ObjectManager
Parameters:
flag - Whether to copy on attaching

getCopyOnAttach

public boolean getCopyOnAttach()
Accessor for whether to copy on attaching.

Specified by:
getCopyOnAttach in interface ObjectManager
Returns:
Whether to copy on attaching

setIgnoreCache

public void setIgnoreCache(boolean flag)
Mutator for whether to ignore the cache.

Specified by:
setIgnoreCache in interface ObjectManager
Parameters:
flag - Whether to ignore the cache.

getIgnoreCache

public boolean getIgnoreCache()
Accessor for whether to ignore the cache.

Specified by:
getIgnoreCache in interface ObjectManager
Returns:
Whether to ignore the cache.

isDelayDatastoreOperationsEnabled

public boolean isDelayDatastoreOperationsEnabled()
Whether the datastore operations are delayed until commit/flush. In optimistic transactions this is automatically enabled. In datastore transactions there is a persistence property to enable it. If we are committing/flushing then will return false since the delay is no longer required.

Specified by:
isDelayDatastoreOperationsEnabled in interface ObjectManager
Returns:
true if datastore operations are delayed until commit/flush

isInserting

public boolean isInserting(java.lang.Object pc)
Tests whether this persistable object is in the process of being inserted.

Specified by:
isInserting in interface ObjectManager
Parameters:
pc - the object to verify the status
Returns:
true if this instance is inserting.

getTransaction

public Transaction getTransaction()
Accessor for the current transaction.

Specified by:
getTransaction in interface ObjectManager
Returns:
The transaction

enlistInTransaction

public void enlistInTransaction(StateManager sm)
Method to enlist the specified StateManager in the current transaction.

Specified by:
enlistInTransaction in interface ObjectManager
Parameters:
sm - The StateManager

evictFromTransaction

public void evictFromTransaction(StateManager sm)
Method to evict the specified StateManager from the current transaction.

Specified by:
evictFromTransaction in interface ObjectManager
Parameters:
sm - The StateManager

isEnlistedInTransaction

public boolean isEnlistedInTransaction(java.lang.Object id)
Method to return if an object is enlisted in the current transaction. This is only of use when running "persistence-by-reachability-at-commit"

Specified by:
isEnlistedInTransaction in interface ObjectManager
Parameters:
id - Identity for the object
Returns:
Whether it is enlisted in the current transaction

addStateManager

public void addStateManager(StateManager sm)
Method to add the object managed by the specified StateManager to the cache.

Specified by:
addStateManager in interface ObjectManager
Parameters:
sm - The StateManager

removeStateManager

public void removeStateManager(StateManager sm)
Method to remove the object managed by the specified StateManager from the cache.

Specified by:
removeStateManager in interface ObjectManager
Parameters:
sm - The StateManager

getStateManagerById

public StateManager getStateManagerById(java.lang.Object id)
Accessor for the StateManager of an object given the object id.

Specified by:
getStateManagerById in interface ObjectManager
Parameters:
id - Id of the object.
Returns:
The StateManager

findStateManager

public StateManager findStateManager(java.lang.Object pc)
Method to find the StateManager for an object.

Specified by:
findStateManager in interface ObjectManager
Parameters:
pc - The object we require the StateManager for.
Returns:
The StateManager, null if StateManager not found. See JDO spec for the calling behavior when null is returned

hereIsStateManager

public void hereIsStateManager(StateManager sm,
                               java.lang.Object pc)
Method to add the StateManager for an object to this ObjectManager's list.

Specified by:
hereIsStateManager in interface ObjectManager
Parameters:
sm - The StateManager
pc - The object managed by the StateManager

close

public void close()
Method to close the Persistence Manager.

Specified by:
close in interface ObjectManager

postClose

public void postClose()
Description copied from interface: ObjectManager
Method called during the close process.

Specified by:
postClose in interface ObjectManager

disconnectSMCache

public void disconnectSMCache()
Disconnect SM instances, clear cache and reset settings

Specified by:
disconnectSMCache in interface ObjectManager

evictObject

public void evictObject(java.lang.Object obj)
Internal method to evict an object from L1 cache.

Specified by:
evictObject in interface ObjectManager
Parameters:
obj - The object
Throws:
NucleusException - if an error occurs evicting the object

evictObjects

public void evictObjects(java.lang.Class cls,
                         boolean subclasses)
Method to evict all objects of the specified type (and optionaly its subclasses).

Specified by:
evictObjects in interface ObjectManager
Parameters:
cls - Type of persistable object
subclasses - Whether to include subclasses

evictAllObjects

public void evictAllObjects()
Method to evict all current objects from L1 cache.

Specified by:
evictAllObjects in interface ObjectManager

refreshObject

public void refreshObject(java.lang.Object obj)
Method to do a refresh of an object, updating it from its datastore representation. Also updates the object in the L1/L2 caches.

Specified by:
refreshObject in interface ObjectManager
Parameters:
obj - The Object

refreshAllObjects

public void refreshAllObjects()
Method to do a refresh of all objects.

Specified by:
refreshAllObjects in interface ObjectManager
Throws:
NucleusUserException - thrown if instances could not be refreshed.

retrieveObject

public void retrieveObject(java.lang.Object obj,
                           boolean fgOnly)
Method to retrieve an object.

Specified by:
retrieveObject in interface ObjectManager
Parameters:
obj - The object
fgOnly - Whether to retrieve the current fetch group fields only

acquireThreadContextInfo

protected org.datanucleus.ObjectManagerImpl.ThreadContextInfo acquireThreadContextInfo()
Accessor for the thread context information, for the current thread. If the current thread is not present, will add an info context for it.

You must call releaseThreadContextInfo() when you don't need it anymore, since we use reference counting. Use a try...finally-block for this purpose.

Returns:
The thread context information
See Also:
getThreadContextInfo()

getThreadContextInfo

protected org.datanucleus.ObjectManagerImpl.ThreadContextInfo getThreadContextInfo()
Get the current ThreadContextInfo assigned to the current thread without changing the reference counter.

Returns:
the thread context information
See Also:
acquireThreadContextInfo()

releaseThreadContextInfo

protected void releaseThreadContextInfo()
Method to remove the current thread context info for the current thread, after the reference counter reached 0. This method decrements a reference counter (per thread), that is incremented by acquireThreadContextInfo().

See Also:
acquireThreadContextInfo()

persistObject

public java.lang.Object persistObject(java.lang.Object obj)
Method to make an object persistent. NOT to be called by internal DataNucleus methods. Only callable by external APIs (JDO/JPA).

Specified by:
persistObject in interface ObjectManager
Parameters:
obj - The object
Returns:
The persisted object
Throws:
NucleusUserException - if the object is managed by a different manager

persistObjectInternal

public java.lang.Object persistObjectInternal(java.lang.Object obj,
                                              FieldValues preInsertChanges,
                                              StateManager ownerSM,
                                              int ownerFieldNum,
                                              int objectType)
Method to make an object persistent which should be called from internal calls only. All PM/EM calls should go via persistObject(Object obj).

Specified by:
persistObjectInternal in interface ObjectManager
Parameters:
obj - The object
preInsertChanges - Any changes to make before inserting
ownerSM - StateManager of the owner when embedded
ownerFieldNum - Field number in the owner where this is embedded (or -1 if not embedded)
objectType - Type of object (see org.datanucleus.StateManager, e.g StateManager.PC)
Returns:
The persisted object
Throws:
NucleusUserException - if the object is managed by a different manager

deleteObject

public void deleteObject(java.lang.Object obj)
Method to delete an object from the datastore. NOT to be called by internal methods. Only callable by external APIs (JDO/JPA).

Specified by:
deleteObject in interface ObjectManager
Parameters:
obj - The object

deleteObjectInternal

public void deleteObjectInternal(java.lang.Object obj)
Method to delete an object from persistence which should be called from internal calls only. All PM/EM calls should go via deleteObject(Object obj).

Specified by:
deleteObjectInternal in interface ObjectManager
Parameters:
obj - Object to delete

deleteObjects

public void deleteObjects(java.lang.Object[] objs)
Method to delete an array of objects from the datastore.

Specified by:
deleteObjects in interface ObjectManager
Parameters:
objs - The objects
Throws:
NucleusUserException - Thrown if an error occurs during the deletion process. Any exception could have several nested exceptions for each failed object deletion

deleteObjects

public void deleteObjects(java.util.Collection objs)
Method to delete an array of objects from the datastore.

Specified by:
deleteObjects in interface ObjectManager
Parameters:
objs - The objects
Throws:
NucleusUserException - Thrown if an error occurs during the deletion process. Any exception could have several nested exceptions for each failed object deletion

makeObjectTransient

public void makeObjectTransient(java.lang.Object obj,
                                FetchPlanState state)
Method to migrate an object to transient state.

Specified by:
makeObjectTransient in interface ObjectManager
Parameters:
obj - The object
state - Object containing the state of the fetch plan process (if any)
Throws:
NucleusException - When an error occurs in making the object transient

makeObjectTransactional

public void makeObjectTransactional(java.lang.Object obj)
Method to make an object transactional.

Specified by:
makeObjectTransactional in interface ObjectManager
Parameters:
obj - The object
Throws:
NucleusException - Thrown when an error occurs

makeObjectNontransactional

public void makeObjectNontransactional(java.lang.Object obj)
Method to make an object nontransactional.

Specified by:
makeObjectNontransactional in interface ObjectManager
Parameters:
obj - The object

attachObject

public void attachObject(java.lang.Object pc,
                         boolean sco)
Method to attach a persistent detached object. If a different object with the same identity as this object exists in the L1 cache then an exception will be thrown.

Specified by:
attachObject in interface ObjectManager
Parameters:
pc - The persistable object
sco - Whether the PC object is stored without an identity (embedded/serialised)

attachObjectCopy

public java.lang.Object attachObjectCopy(java.lang.Object pc,
                                         boolean sco)
Method to attach a persistent detached object returning an attached copy of the object. If the object is of class that is not detachable, a ClassNotDetachableException will be thrown.

Specified by:
attachObjectCopy in interface ObjectManager
Parameters:
pc - The object
sco - Whether it has no identity (second-class object)
Returns:
The attached object

detachObject

public void detachObject(java.lang.Object obj,
                         FetchPlanState state)
Method to detach a persistent object without making a copy. Note that also all the objects which are refered to from this object are detached. If the object is of class that is not detachable a ClassNotDetachableException will be thrown. If the object is not persistent a JDOUserException is thrown. For internal use only

Specified by:
detachObject in interface ObjectManager
Parameters:
obj - The object
state - State for the detachment process

detachObjectCopy

public java.lang.Object detachObjectCopy(java.lang.Object pc,
                                         FetchPlanState state)
Detach a copy of the passed persistent object using the provided detach state. If the object is of class that is not detachable it will be detached as transient. If it is not yet persistent it will be first persisted.

Specified by:
detachObjectCopy in interface ObjectManager
Parameters:
pc - The object
state - State for the detachment process
Returns:
The detached object

detachAll

public void detachAll()
Method to detach all objects in the ObjectManager.

Specified by:
detachAll in interface ObjectManager

newInstance

public java.lang.Object newInstance(java.lang.Class cls)
Method to generate an instance of an interface, abstract class, or concrete PC class.

Specified by:
newInstance in interface ObjectManager
Parameters:
cls - The class of the interface or abstract class, or concrete class defined in MetaData
Returns:
The instance of this type

exists

public boolean exists(java.lang.Object obj)
Method to return if the specified object exists in the datastore.

Specified by:
exists in interface ObjectManager
Parameters:
obj - The (persistable) object
Returns:
Whether it exists

getManagedObjects

public java.util.Set getManagedObjects()
Accessor for the currently managed objects for the current transaction. If the transaction is not active this returns null.

Specified by:
getManagedObjects in interface ObjectManager
Returns:
Collection of managed objects enlisted in the current transaction

getManagedObjects

public java.util.Set getManagedObjects(java.lang.Class[] classes)
Accessor for the currently managed objects for the current transaction. If the transaction is not active this returns null.

Specified by:
getManagedObjects in interface ObjectManager
Parameters:
classes - Classes that we want the enlisted objects for
Returns:
Collection of managed objects enlisted in the current transaction

getManagedObjects

public java.util.Set getManagedObjects(java.lang.String[] states)
Accessor for the currently managed objects for the current transaction. If the transaction is not active this returns null.

Specified by:
getManagedObjects in interface ObjectManager
Parameters:
states - States that we want the enlisted objects for
Returns:
Collection of managed objects enlisted in the current transaction

getManagedObjects

public java.util.Set getManagedObjects(java.lang.String[] states,
                                       java.lang.Class[] classes)
Accessor for the currently managed objects for the current transaction. If the transaction is not active this returns null.

Specified by:
getManagedObjects in interface ObjectManager
Parameters:
states - States that we want the enlisted objects for
classes - Classes that we want the enlisted objects for
Returns:
Collection of managed objects enlisted in the current transaction

findObjectUsingAID

public java.lang.Object findObjectUsingAID(java.lang.Class pcClass,
                                           FieldValues fv,
                                           boolean ignoreCache,
                                           boolean checkInheritance)
Accessor for the StateManager of an object given the object AID.

Specified by:
findObjectUsingAID in interface ObjectManager
Parameters:
pcClass - The class of the PC object
fv - The field values to be loaded
ignoreCache - true if it must ignore the cache
checkInheritance - Whether look to the database to determine which class this object is. This parameter is a hint. Set false, if it's already determined the correct pcClass for this pc "object" in a certain level in the hierarchy. Set to true and it will look to the database.
Returns:
Object

findObject

public java.lang.Object findObject(java.lang.Object id,
                                   FieldValues fv,
                                   java.lang.Class cls,
                                   boolean ignoreCache)
Accessor for an object given the object id.

Specified by:
findObject in interface ObjectManager
Parameters:
id - Id of the object.
fv - Field values for the object
cls - the type which the object is. This type will be used to instanciat the object
ignoreCache - true if it must ignore the cache
Returns:
The Object

findObject

public java.lang.Object findObject(java.lang.Object id,
                                   FieldValues fv)
Accessor for an object given the object id. Checks the inheritance level of the object

Specified by:
findObject in interface ObjectManager
Parameters:
id - Id of the object.
fv - Field values for the object
Returns:
The Object

findObject

public java.lang.Object findObject(java.lang.Object id,
                                   boolean validate,
                                   boolean checkInheritance,
                                   java.lang.String objectClassName)
Accessor for an object given the object id. If validate is false, we return the object if found in the cache, or otherwise a Hollow object with that id. If validate is true we check with the datastore and return an object with the FetchPlan fields loaded (unless the object doesnt exist in the datastore, where we throw a NucleusObjectNotFoundException).

Specified by:
findObject in interface ObjectManager
Parameters:
id - Id of the object.
validate - Whether to validate the object state
checkInheritance - Whether look to the database to determine which class this object is.
objectClassName - Class name for the object with this id (if known, optional)
Returns:
The Object with this id

newObjectId

public java.lang.Object newObjectId(java.lang.Class pcClass,
                                    java.lang.Object key)
This method returns an object id instance corresponding to the pcClass and key arguments. Operates in 2 modes :-

Specified by:
newObjectId in interface ObjectManager
Parameters:
pcClass - Class of the PersistenceCapable to create the identity for
key - Value of the key for SingleFieldIdentity (or the toString value)
Returns:
The new object-id instance

newObjectId

public java.lang.Object newObjectId(java.lang.String className,
                                    java.lang.Object pc)
This method returns an object id instance corresponding to the class name, and the passed object (when using app identity).

Specified by:
newObjectId in interface ObjectManager
Parameters:
className - Name of the class of the object.
pc - The persistable object. Used for application-identity
Returns:
A new object ID.

clearDirty

public void clearDirty(StateManager sm)
Method to clear an object from the list of dirty objects.

Specified by:
clearDirty in interface ObjectManager
Parameters:
sm - The StateManager

clearDirty

public void clearDirty()
Method to clear all objects marked as dirty (whether directly or indirectly).

Specified by:
clearDirty in interface ObjectManager

markDirty

public void markDirty(StateManager sm,
                      boolean directUpdate)
Method to mark an object (StateManager) as dirty.

Specified by:
markDirty in interface ObjectManager
Parameters:
sm - The StateManager
directUpdate - Whether the object has had a direct update made on it (if known)

markManagedRelationDirty

public void markManagedRelationDirty(StateManager sm)
Method to mark the specified StateManager as needing an update due to managed relation constraints.

Specified by:
markManagedRelationDirty in interface ObjectManager
Parameters:
sm - The StateManager

isManagingRelations

public boolean isManagingRelations()
Returns whether this ObjectManager is currently performing the manage relationships task.

Specified by:
isManagingRelations in interface ObjectManager
Returns:
Whether in the process of managing relations

performManagedRelationships

protected void performManagedRelationships()
Method to perform managed relationships tasks.

Throws:
NucleusUserException - if a consistency check fails

isFlushing

public boolean isFlushing()
Returns whether the ObjectManager is in the process of flushing.

Specified by:
isFlushing in interface ObjectManager
Returns:
true if the ObjectManager is flushing

flush

public void flush()
Method callable from external APIs for user-management of flushing. Called by JDO PM.flush, or JPA EM.flush(). Performs management of relations, prior to performing internal flush of all dirty/new/deleted instances to the datastore.

Specified by:
flush in interface ObjectManager

flushInternal

public void flushInternal(boolean flushToDatastore)
This method flushes all dirty, new, and deleted instances to the datastore. It has no effect if a transaction is not active. If a datastore transaction is active, this method synchronizes the cache with the datastore and reports any exceptions. If an optimistic transaction is active, this method obtains a datastore connection and synchronizes the cache with the datastore using this connection. The connection obtained by this method is held until the end of the transaction.

Specified by:
flushInternal in interface ObjectManager
Parameters:
flushToDatastore - Whether to ensure any changes reach the datastore Otherwise they will be flushed to the datastore manager and leave it to decide the opportune moment to actually flush them to the datastore
Throws:
NucleusOptimisticException - when optimistic locking error(s) occur

postBegin

public void postBegin()
Method to perform any post-begin checks.

Specified by:
postBegin in interface ObjectManager

preCommit

public void preCommit()
Method to perform any pre-commit checks.

Specified by:
preCommit in interface ObjectManager

isRunningDetachAllOnCommit

public boolean isRunningDetachAllOnCommit()
Accessor for whether this ObjectManager is currently running detachAllOnCommit.

Specified by:
isRunningDetachAllOnCommit in interface ObjectManager
Returns:
Whether running detachAllOnCommit

postCommit

public void postCommit()
Commit any changes made to objects managed by the persistence manager to the database.

Specified by:
postCommit in interface ObjectManager

preRollback

public void preRollback()
Rollback any changes made to objects managed by the persistence manager to the database.

Specified by:
preRollback in interface ObjectManager

replaceObjectId

public void replaceObjectId(java.lang.Object pc,
                            java.lang.Object oldID,
                            java.lang.Object newID)
Replace the previous object id for a persistable object with a new one. This is used where we have already added the object to the cache(s) and/or enlisted it in the txn before its real identity was fixed (attributed in the datastore).

Specified by:
replaceObjectId in interface ObjectManager
Parameters:
pc - The Persistable object
oldID - the old id it was known by
newID - the new id

putObjectIntoCache

public void putObjectIntoCache(StateManager sm)
Convenience method to add an object to the L1 cache.

Specified by:
putObjectIntoCache in interface ObjectManager
Parameters:
sm - The State Manager

removeObjectFromCache

public void removeObjectFromCache(java.lang.Object pc,
                                  java.lang.Object id)
Convenience method to evict an object from the L1 cache.

Specified by:
removeObjectFromCache in interface ObjectManager
Parameters:
pc - The Persistable object
id - The Persistable object id

getObjectFromCache

public java.lang.Object getObjectFromCache(java.lang.Object id)
Convenience method to access an object in the cache. Firstly looks in the L1 cache for this ObjectManager, and if not found looks in the L2 cache.

Specified by:
getObjectFromCache in interface ObjectManager
Parameters:
id - Id of the object
Returns:
Persistence Capable object (with connected StateManager).

getExtent

public Extent getExtent(java.lang.Class pcClass,
                        boolean subclasses)
Extents are collections of datastore objects managed by the datastore, not by explicit user operations on collections. Extent capability is a boolean property of classes that are persistence capable. If an instance of a class that has a managed extent is made persistent via reachability, the instance is put into the extent implicitly.

Specified by:
getExtent in interface ObjectManager
Parameters:
pcClass - The class to query
subclasses - Whether to include subclasses in the query.
Returns:
returns an Extent that contains all of the instances in the parameter class, and if the subclasses flag is true, all of the instances of the parameter class and its subclasses.

newQuery

public Query newQuery()
Construct an empty query instance.

Specified by:
newQuery in interface ObjectManager
Returns:
The query

removeAllInstanceLifecycleListeners

public void removeAllInstanceLifecycleListeners()
This method removes all previously registered lifecycle listeners. It is necessary to make sure, that a cached ObjectManager (in j2ee environment) will have no listener before the listeners are copied from the OMF. Otherwise they might be registered multiple times.


getCallbackHandler

public CallbackHandler getCallbackHandler()
Retrieve the callback handler for this ObjectManager.

Specified by:
getCallbackHandler in interface ObjectManager
Returns:
the callback handler

addListener

public void addListener(java.lang.Object listener,
                        java.lang.Class[] classes)
Method to register a listener for instances of the specified classes.

Specified by:
addListener in interface ObjectManager
Parameters:
listener - The listener to sends events to
classes - The classes that it is interested in

removeListener

public void removeListener(java.lang.Object listener)
Method to remove a currently registered listener.

Specified by:
removeListener in interface ObjectManager
Parameters:
listener - The listener to remove.

disconnectLifecycleListener

public void disconnectLifecycleListener()
Disconnect the registered LifecycleListener

Specified by:
disconnectLifecycleListener in interface ObjectManager

assertIsOpen

protected void assertIsOpen()
Method to assert if this Object Manager is open. Throws a NucleusUserException if the ObjectManager is closed.


assertClassPersistable

public void assertClassPersistable(java.lang.Class cls)
Method to assert if the specified class is Persistence Capable.

Specified by:
assertClassPersistable in interface ObjectManager
Parameters:
cls - The class to check
Throws:
ClassNotPersistableException - if class is not persistable
NoPersistenceInformationException - if no metadata/annotations are found for class

assertDetachable

protected void assertDetachable(java.lang.Object object)
Method to assert if the specified object is Detachable. Throws a ClassNotDetachableException if not capable

Parameters:
object - The object to check

assertNotDetached

protected void assertNotDetached(java.lang.Object object)
Method to assert if the specified object is detached. Throws a ObjectDetachedException if it is detached.

Parameters:
object - The object to check

assertActiveTransaction

protected void assertActiveTransaction()
Method to assert if the current transaction is active. Throws a TransactionNotActiveException if not active


assertWritable

protected void assertWritable()
Method to assert if the current transaction is active or non transactional writes are allowed.

Throws:
a - TransactionNotActiveException if not active and non transactional writes are disabled

assertHasImplementationCreator

protected void assertHasImplementationCreator()
Validates that an ImplementationCreator instance is accessible.

Throws:
NucleusUserException - if an ImplementationCreator instance does not exist

hasPersistenceInformationForClass

public boolean hasPersistenceInformationForClass(java.lang.Class cls)
Utility method to check if the specified class has reachable metadata or annotations.

Specified by:
hasPersistenceInformationForClass in interface ObjectManager
Parameters:
cls - The class to check
Returns:
Whether the class has reachable metadata or annotations

getFetchGroupManager

protected FetchGroupManager getFetchGroupManager()
Convenience accessor for the FetchGroupManager. Creates it if not yet existing.

Returns:
The FetchGroupManager

addInternalFetchGroup

public void addInternalFetchGroup(FetchGroup grp)
Method to add a dynamic FetchGroup for use by this OMF.

Specified by:
addInternalFetchGroup in interface ObjectManager
Parameters:
grp - The group

removeInternalFetchGroup

protected void removeInternalFetchGroup(FetchGroup grp)
Method to remove a dynamic FetchGroup from use by this OMF.

Parameters:
grp - The group

getInternalFetchGroup

public FetchGroup getInternalFetchGroup(java.lang.Class cls,
                                        java.lang.String name)
Accessor for an internal fetch group for the specified class.

Specified by:
getInternalFetchGroup in interface ObjectManager
Parameters:
cls - The class
name - Name of the group
Returns:
The FetchGroup
Throws:
NucleusUserException - if the class is not persistable

getFetchGroupsWithName

public java.util.Set getFetchGroupsWithName(java.lang.String name)
Accessor for the fetch groups for the specified name.

Specified by:
getFetchGroupsWithName in interface ObjectManager
Parameters:
name - Name of the group
Returns:
The FetchGroup


Copyright © 2009. All Rights Reserved.