org.datanucleus
Class ObjectManagerImpl

java.lang.Object
  extended by org.datanucleus.ObjectManagerImpl
All Implemented Interfaces:
ExecutionContext, TransactionEventListener
Direct Known Subclasses:
MultithreadedObjectManager

public class ObjectManagerImpl
extends Object
implements ExecutionContext, TransactionEventListener

Managed for persistence, representing the execution context. Provides the basics of object persistence internally, upon which are built javax.jdo.PersistenceManager and javax.persistence.EntityManager. 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(). If an object is no longer enlisted in the transaction at commit then it will be removed from the Level 2 cache (so we remove the chance of handing out old data).

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.store.ExecutionContext
ExecutionContext.LifecycleListener
 
Field Summary
protected  Level1Cache cache
          Level 1 Cache, essentially a Map of ObjectProvider keyed by the id.
protected static Localiser LOCALISER
          Localisation utility for output messages
protected  Lock lock
          Lock object for use during commit/rollback/evict, to prevent any further field accesses.
 
Constructor Summary
ObjectManagerImpl(NucleusContext ctx, Object owner, String userName, 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.
 void addListener(Object listener, Class[] classes)
          Method to register a listener for instances of the specified classes.
 void addObjectProvider(ObjectProvider op)
          Method to add the object managed by the specified ObjectProvider to the (L1) cache.
protected  void assertActiveTransaction()
          Method to assert if the current transaction is active.
 void assertClassPersistable(Class cls)
          Method to assert if the specified class is Persistence Capable.
protected  void assertDetachable(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(Object object)
          Method to assert if the specified object is detached.
 void attachObject(ObjectProvider ownerOP, Object pc, boolean sco)
          Method to attach a persistent detached object.
 Object attachObjectCopy(ObjectProvider ownerOP, 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(ObjectProvider op)
          Method to clear an object from the list of dirty objects.
 void close()
          Method to close the Object Manager.
 void deleteObject(Object obj)
          Method to delete an object from the datastore.
 void deleteObjectInternal(Object obj)
          Method to delete an object from persistence which should be called from internal calls only.
 void deleteObjects(Object[] objs)
          Method to delete an array of objects from the datastore.
 void detachAll()
          Method to detach all objects in the ObjectManager.
 void detachObject(Object obj, FetchPlanState state)
          Method to detach a persistent object without making a copy.
 Object detachObjectCopy(Object pc, FetchPlanState state)
          Detach a copy of the passed persistent object using the provided detach state.
 void disconnectLifecycleListener()
          Disconnect the registered LifecycleListener
protected  void disconnectObjectProvidersFromCache()
          Disconnect ObjectProviders that are cached from their objects, and removes them from the cache.
 void enlistInTransaction(ObjectProvider op)
          Method to enlist the specified ObjectProvider in the current transaction.
 void evictAllObjects()
          Method to evict all current objects from L1 cache.
 void evictFromTransaction(ObjectProvider op)
          Method to evict the specified ObjectProvider from the current transaction.
 void evictObject(Object obj)
          Internal method to evict an object from L1 cache.
 void evictObjects(Class cls, boolean subclasses)
          Method to evict all objects of the specified type (and optionaly its subclasses) that are present in the L1 cache.
 boolean exists(Object obj)
          Method to return if the specified object exists in the datastore.
 Object findObject(Object id, boolean validate, boolean checkInheritance, String objectClassName)
          Accessor for an object given the object id.
 Object findObject(Object id, FieldValues fv, Class cls, boolean ignoreCache, boolean checkInheritance)
          Accessor for an object given the object id and a set of field values to apply to it.
 ObjectProvider findObjectProvider(Object pc)
          Method to find the ObjectProvider for an object.
 ObjectProvider findObjectProvider(Object pc, boolean persist)
          Method to find the ObjectProvider for the passed persistable object when it is managed by this manager, and if not yet persistent to persist it.
 ObjectProvider findObjectProviderForEmbedded(Object value, ObjectProvider owner, AbstractMemberMetaData mmd)
          Method to find the ObjectProvider for the passed embedded persistable object.
 Object[] findObjects(Object[] identities, boolean validate)
          Accessor for objects with the specified identities.
 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.
protected  List<NucleusOptimisticException> flushInternalNonReferential()
          Flush method for cases where the datastore doesn't use referential integrity so we can send batches of deletes, then batches of inserts, then any updates to optimise the persistence.
protected  List<NucleusOptimisticException> flushInternalWithOrdering()
          Flush process that takes the objects in the order that they became dirty.
 ApiAdapter getApiAdapter()
          Accessor for the API adapter.
 Object getAttachedObjectForId(Object id)
          Convenience method to return the attached object for the specified id if one exists.
 Boolean getBooleanProperty(String name)
          Accessor for a boolean property value.
 CallbackHandler getCallbackHandler()
          Retrieve the callback handler for this ObjectManager.
 ClassLoaderResolver getClassLoaderResolver()
          Accessor for the ClassLoader resolver to use in class loading issues.
 boolean getCopyOnAttach()
          Accessor for whether to copy on attaching.
 Integer getDatastoreReadTimeoutMillis()
          Accessor for the datastore read timeout in milliseconds.
 Integer getDatastoreWriteTimeoutMillis()
          Accessor for the datastore write timeout in milliseconds.
protected  boolean getDetachAllOnCommit()
          Accessor for whether to detach all objects on commit of the transaction.
protected  boolean getDetachAllOnRollback()
          Accessor for whether to detach all objects on rollback of the transaction.
protected  boolean getDetachOnClose()
          Accessor for whether to detach objects on close of the ObjectManager.
 Extent getExtent(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.
 Set getFetchGroupsWithName(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(Class cls, String name)
          Accessor for an internal fetch group for the specified class.
 Integer getIntProperty(String name)
          Accessor for an int property value.
protected  CachedPC getL2CacheableObject(ObjectProvider op)
          Convenience method to convert the object managed by the ObjectProvider into a form suitable for caching in an L2 cache.
 Lock getLock()
          Accessor for the ObjectManager lock object.
 LockManager getLockManager()
          Accessor for the lock manager for this execution context.
 Set getManagedObjects()
          Accessor for the currently managed objects for the current transaction.
 Set getManagedObjects(Class[] classes)
          Accessor for the currently managed objects for the current transaction.
 Set getManagedObjects(String[] states)
          Accessor for the currently managed objects for the current transaction.
 Set getManagedObjects(String[] states, Class[] classes)
          Accessor for the currently managed objects for the current transaction.
 boolean getManageRelations()
          Accessor for whether to manage relationships at flush/commit.
 boolean getManageRelationsChecks()
          Accessor for whether to manage relationships checks at flush/commit.
 MetaDataManager getMetaDataManager()
          Accessor for the MetaDataManager for this ObjectManager (and its factory).
 boolean getMultithreaded()
          Accessor for whether the object manager is multithreaded.
 NucleusContext getNucleusContext()
          Gets the context in which this ObjectManager is running
 Object getObjectFromCache(Object id)
          Convenience method to access an object in the cache.
 Object getObjectFromLevel1Cache(Object id)
          Convenience method to access an object in the Level 1 cache.
 Object getObjectFromLevel2Cache(Object id)
          Convenience method to access an object in the Level 2 cache.
protected  Map getObjectsFromLevel2Cache(Collection ids)
          Convenience method to access a collection of objects from the Level 2 cache.
 List<ObjectProvider> getObjectsToBeFlushed()
          Convenience method to inspect the list of objects with outstanding changes to flush.
 Object getOwner()
          Method to return the owner PM object.
 Map<String,Object> getProperties()
          Accessor for the defined properties.
 Object getProperty(String name)
          Accessor for a property.
protected  boolean getReachabilityAtCommit()
          Accessor for whether to run the reachability algorithm at commit time.
 RelationshipManager getRelationshipManager(ObjectProvider op)
          Accessor for the RelationshipManager for the provided ObjectProvider.
 boolean getSerializeReadForClass(String className)
          Convenience method to return the setting for serialize read for the current transaction for the specified class name.
 ManagerStatistics getStatistics()
          Accessor for any statistics-gathering object.
 StoreManager getStoreManager()
          Accessor for the Store Manager.
 Set<String> getSupportedProperties()
          Accessor for the supported property names.
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.
 TypeManager getTypeManager()
          TODO should we keep this here? this is api/language dependent
 boolean hasIdentityInCache(Object id)
          Whether the specified identity is cached currently.
 boolean hasPersistenceInformationForClass(Class cls)
          Utility method to check if the specified class has reachable metadata or annotations.
 void hereIsObjectProvider(ObjectProvider op, Object pc)
          Method to add the ObjectProvider 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(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(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 isObjectModifiedInTransaction(Object id)
          Accessor for whether the object with this identity is modified in the current transaction.
 boolean isRunningDetachAllOnCommit()
          Accessor for whether this ObjectManager is currently running detachAllOnCommit.
 void makeObjectNontransactional(Object obj)
          Method to make an object nontransactional.
 void makeObjectTransactional(Object obj)
          Method to make an object transactional.
 void makeObjectTransient(Object obj, FetchPlanState state)
          Method to migrate an object to transient state.
 void markDirty(ObjectProvider op, boolean directUpdate)
          Method to mark an object (ObjectProvider) as dirty.
 Object newInstance(Class cls)
          Method to generate an instance of an interface, abstract class, or concrete PC class.
 Object newObjectId(Class pcClass, Object key)
          This method returns an object id instance corresponding to the pcClass and key arguments.
 Object newObjectId(String className, Object pc)
          This method returns an object id instance corresponding to the class name, and the passed object (when using app identity).
protected  ObjectProvider newObjectProviderForCachedPC(Object id, CachedPC cachedPC)
          Constructor to create a ObjectProvider for an object taken from the L2 cache with the specified id.
 ObjectProvider newObjectProviderForDetached(Object pc, Object id, Object version)
          Constructor for creating ObjectProvider instances to manage persistable objects in detached state.
 ObjectProvider newObjectProviderForEmbedded(AbstractClassMetaData cmd, ObjectProvider ownerOP, int ownerFieldNumber)
          Constructs an ObjectProvider for an object of the specified type, creating the PC object to hold the values where this object will be EMBEDDED/SERIALISED into another persistable object.
 ObjectProvider newObjectProviderForEmbedded(Object pc, boolean copyPc, ObjectProvider ownerOP, int ownerFieldNumber)
          Constructs an ObjectProvider to manage a persistable instance that will be EMBEDDED/SERIALISED into another persistable object.
 ObjectProvider newObjectProviderForHollow(Class pcClass, Object id)
          Constructs an ObjectProvider to manage a hollow instance having the given object ID.
 ObjectProvider newObjectProviderForHollowPopulated(Class pcClass, Object id, FieldValues fv)
          Constructs an ObjectProvider to manage a recently populated hollow instance having the given object ID and the given field values.
 ObjectProvider newObjectProviderForHollowPopulatedAppId(Class pcClass, FieldValues fv)
          Deprecated. Use newObjectProviderForHollowPopulated instead
 ObjectProvider newObjectProviderForHollowPreConstructed(Object id, Object pc)
          Constructs an ObjectProvider to manage a hollow instance having the given object ID.
 ObjectProvider newObjectProviderForPersistentClean(Object id, Object pc)
          Constructs an ObjectProvider to manage the specified persistent instance having the given object ID.
 ObjectProvider newObjectProviderForPersistentNew(Object pc, FieldValues preInsertChanges)
          Constructs an ObjectProvider to manage a transient instance that is becoming newly persistent.
 ObjectProvider newObjectProviderForPNewToBeDeleted(Object pc)
          Constructor for creating ObjectProvider instances to manage persistable objects that are not persistent yet are about to be deleted.
 ObjectProvider newObjectProviderForTransactionalTransient(Object pc)
          Constructs an ObjectProvider to manage a Transactional-Transient instance.
 Query newQuery()
          Construct an empty query instance.
protected  void performManagedRelationships()
          Method to perform managed relationships tasks.
 Object persistObject(Object obj, boolean merging)
          Method to make an object persistent.
 Object persistObjectInternal(Object pc, FieldValues preInsertChanges, int objectType)
          Method to persist the passed object (internally).
 Object persistObjectInternal(Object obj, FieldValues preInsertChanges, ObjectProvider ownerOP, int ownerFieldNum, int objectType)
          Method to make an object persistent which should be called from internal calls only.
 Object persistObjectInternal(Object pc, ObjectProvider ownerOP, int ownerFieldNum, int objectType)
          Method to persist the passed object (internally).
 Object[] persistObjects(Object[] objs)
          Method to persist an array of objects to the datastore.
 void postBegin()
          Method to perform any post-begin checks.
 void postCommit()
          Commit any changes made to objects managed by the object manager to the database.
 void postRollback()
          Callback invoked after the actual datastore rollback.
 void preCommit()
          Method to perform any pre-commit checks.
 void preRollback()
          Rollback any changes made to objects managed by the object manager to the database.
protected  void processNontransactionalAtomicChanges()
          Handler for all outstanding changes to be "committed" atomically.
 void processNontransactionalUpdate()
          Method called when a non-tx update has been performed (via setter call on the persistable object, or via use of mutator methods of a field).
 void putObjectIntoLevel1Cache(ObjectProvider op)
          Convenience method to add an object to the L1 cache.
protected  void putObjectIntoLevel2Cache(ObjectProvider op, boolean updateIfPresent)
          Method to add/update the managed object into the L2 cache as long as it isn't modified in the current transaction.
protected  void putObjectIntoLevel2CacheInternal(ObjectProvider op, boolean updateIfPresent)
          Convenience method to add/update an object in the L2 cache.
protected  void putObjectsIntoLevel2Cache(Set<ObjectProvider> ops)
          Method to put the passed objects into the L2 cache.
 void refreshAllObjects()
          Method to do a refresh of all objects.
 void refreshObject(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.
 void removeListener(Object listener)
          Method to remove a currently registered listener.
 void removeObjectFromLevel1Cache(Object id)
          Convenience method to evict an object from the L1 cache.
 void removeObjectFromLevel2Cache(Object id)
          Convenience method to remove the object with the specified identity from the L2 cache.
 void removeObjectProvider(ObjectProvider op)
          Method to remove the object managed by the specified ObjectProvider from the cache.
 void replaceObjectId(Object pc, Object oldID, Object newID)
          Replace the previous object id for a persistable object with a new one.
 void retrieveObject(Object obj, boolean fgOnly)
          Method to retrieve an object.
 void setProperties(Map props)
          Method to set properties on the execution context.
 void setProperty(String name, Object value)
          Method to set a property on the execution context
 void transactionCommitted()
          Method invoked when the transaction is committed.
 void transactionEnded()
          Method invoked when the transaction is ended (Using XA).
 void transactionFlushed()
          Method invoked when the transaction is flushed (happens before commit, rollback).
 void transactionPreCommit()
          Method invoked before the transaction commit.
 void transactionPreFlush()
          Method invoked just before a flush.
 void transactionPreRollBack()
          Method invoked before the transaction is rolledback.
 void transactionRolledBack()
          Method invoked when the transaction is rolled back.
 void transactionStarted()
          Method invoked when the transaction is started.
 
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


cache

protected Level1Cache cache
Level 1 Cache, essentially a Map of ObjectProvider keyed by the id.


lock

protected Lock lock
Lock object for use during commit/rollback/evict, to prevent any further field accesses.

Constructor Detail

ObjectManagerImpl

public ObjectManagerImpl(NucleusContext ctx,
                         Object owner,
                         String userName,
                         String password)
Constructor.

Parameters:
ctx - NucleusContext
owner - The owning PM/EM depending on calling API.
userName - Username for the datastore
password - Password for the datastore
Throws:
NucleusUserException - if an error occurs allocating the necessary requested components
Method Detail

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()

transactionStarted

public void transactionStarted()
Description copied from interface: TransactionEventListener
Method invoked when the transaction is started.

Specified by:
transactionStarted in interface TransactionEventListener

transactionPreFlush

public void transactionPreFlush()
Description copied from interface: TransactionEventListener
Method invoked just before a flush.

Specified by:
transactionPreFlush in interface TransactionEventListener

transactionFlushed

public void transactionFlushed()
Description copied from interface: TransactionEventListener
Method invoked when the transaction is flushed (happens before commit, rollback).

Specified by:
transactionFlushed in interface TransactionEventListener

transactionPreCommit

public void transactionPreCommit()
Description copied from interface: TransactionEventListener
Method invoked before the transaction commit.

Specified by:
transactionPreCommit in interface TransactionEventListener

transactionCommitted

public void transactionCommitted()
Description copied from interface: TransactionEventListener
Method invoked when the transaction is committed.

Specified by:
transactionCommitted in interface TransactionEventListener

transactionPreRollBack

public void transactionPreRollBack()
Description copied from interface: TransactionEventListener
Method invoked before the transaction is rolledback.

Specified by:
transactionPreRollBack in interface TransactionEventListener

transactionRolledBack

public void transactionRolledBack()
Description copied from interface: TransactionEventListener
Method invoked when the transaction is rolled back.

Specified by:
transactionRolledBack in interface TransactionEventListener

transactionEnded

public void transactionEnded()
Description copied from interface: TransactionEventListener
Method invoked when the transaction is ended (Using XA).

Specified by:
transactionEnded in interface TransactionEventListener

getStatistics

public ManagerStatistics getStatistics()
Description copied from interface: ExecutionContext
Accessor for any statistics-gathering object.

Specified by:
getStatistics in interface ExecutionContext
Returns:
The statistics for this manager

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 ExecutionContext
Returns:
Whether this manager is closed.

getClassLoaderResolver

public ClassLoaderResolver getClassLoaderResolver()
Description copied from interface: ExecutionContext
Accessor for the ClassLoader resolver to use in class loading issues.

Specified by:
getClassLoaderResolver in interface ExecutionContext
Returns:
The ClassLoader resolver

getStoreManager

public StoreManager getStoreManager()
Description copied from interface: ExecutionContext
Accessor for the Store Manager.

Specified by:
getStoreManager in interface ExecutionContext
Returns:
Store Manager

getApiAdapter

public ApiAdapter getApiAdapter()
Description copied from interface: ExecutionContext
Accessor for the API adapter.

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

getTypeManager

public TypeManager getTypeManager()
Description copied from interface: ExecutionContext
TODO should we keep this here? this is api/language dependent

Specified by:
getTypeManager in interface ExecutionContext
Returns:
The type manager

getLockManager

public LockManager getLockManager()
Description copied from interface: ExecutionContext
Accessor for the lock manager for this execution context.

Specified by:
getLockManager in interface ExecutionContext
Returns:
The lock manager

getFetchPlan

public FetchPlan getFetchPlan()
Acessor for the current FetchPlan.

Specified by:
getFetchPlan in interface ExecutionContext
Returns:
FetchPlan

getOwner

public Object getOwner()
Method to return the owner PM object.

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

getNucleusContext

public NucleusContext getNucleusContext()
Gets the context in which this ObjectManager is running

Specified by:
getNucleusContext in interface ExecutionContext
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 ExecutionContext
Returns:
Returns the MetaDataManager.

setProperties

public void setProperties(Map props)
Description copied from interface: ExecutionContext
Method to set properties on the execution context.

Specified by:
setProperties in interface ExecutionContext
Parameters:
props - The properties

setProperty

public void setProperty(String name,
                        Object value)
Description copied from interface: ExecutionContext
Method to set a property on the execution context

Specified by:
setProperty in interface ExecutionContext
Parameters:
name - Name of the property
value - Value to set

getProperties

public Map<String,Object> getProperties()
Description copied from interface: ExecutionContext
Accessor for the defined properties.

Specified by:
getProperties in interface ExecutionContext
Returns:
Properties for this execution context

getBooleanProperty

public Boolean getBooleanProperty(String name)
Description copied from interface: ExecutionContext
Accessor for a boolean property value.

Specified by:
getBooleanProperty in interface ExecutionContext
Parameters:
name - Name of the property
Returns:
the value

getIntProperty

public Integer getIntProperty(String name)
Description copied from interface: ExecutionContext
Accessor for an int property value.

Specified by:
getIntProperty in interface ExecutionContext
Parameters:
name - Name of the property
Returns:
the value

getProperty

public Object getProperty(String name)
Description copied from interface: ExecutionContext
Accessor for a property.

Specified by:
getProperty in interface ExecutionContext
Parameters:
name - Name of the property
Returns:
The value

getSupportedProperties

public Set<String> getSupportedProperties()
Description copied from interface: ExecutionContext
Accessor for the supported property names.

Specified by:
getSupportedProperties in interface ExecutionContext
Returns:
Set of names

getDatastoreReadTimeoutMillis

public Integer getDatastoreReadTimeoutMillis()
Accessor for the datastore read timeout in milliseconds.

Specified by:
getDatastoreReadTimeoutMillis in interface ExecutionContext
Returns:
Datastore read timeout in milliseconds (if specified)

getDatastoreWriteTimeoutMillis

public Integer getDatastoreWriteTimeoutMillis()
Accessor for the datastore write timeout in milliseconds.

Specified by:
getDatastoreWriteTimeoutMillis in interface ExecutionContext
Returns:
Datastore write timeout in milliseconds (if specified)

getMultithreaded

public boolean getMultithreaded()
Accessor for whether the object manager is multithreaded.

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

getDetachOnClose

protected boolean getDetachOnClose()
Accessor for whether to detach objects on close of the ObjectManager. This is not suitable for use in JCA mode.

Returns:
Whether to detach on close.

getDetachAllOnCommit

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

Returns:
Whether to detach all on commit.

getDetachAllOnRollback

protected boolean getDetachAllOnRollback()
Accessor for whether to detach all objects on rollback of the transaction.

Returns:
Whether to detach all on rollback.

getReachabilityAtCommit

protected boolean getReachabilityAtCommit()
Accessor for whether to run the reachability algorithm at commit time.

Returns:
Whether to run PBR at commit

getCopyOnAttach

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

Returns:
Whether to copy on attaching

getIgnoreCache

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

Specified by:
getIgnoreCache in interface ExecutionContext
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 ExecutionContext
Returns:
true if datastore operations are delayed until commit/flush

isInserting

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

Specified by:
isInserting in interface ExecutionContext
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 ExecutionContext
Returns:
The transaction

enlistInTransaction

public void enlistInTransaction(ObjectProvider op)
Method to enlist the specified ObjectProvider in the current transaction.

Specified by:
enlistInTransaction in interface ExecutionContext
Parameters:
op - The ObjectProvider

evictFromTransaction

public void evictFromTransaction(ObjectProvider op)
Method to evict the specified ObjectProvider from the current transaction.

Specified by:
evictFromTransaction in interface ExecutionContext
Parameters:
op - The ObjectProvider

isEnlistedInTransaction

public boolean isEnlistedInTransaction(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 ExecutionContext
Parameters:
id - Identity for the object
Returns:
Whether it is enlisted in the current transaction

getAttachedObjectForId

public Object getAttachedObjectForId(Object id)
Convenience method to return the attached object for the specified id if one exists. Returns null if there is no currently enlisted/cached object with the specified id.

Specified by:
getAttachedObjectForId in interface ExecutionContext
Parameters:
id - The id
Returns:
The attached object

addObjectProvider

public void addObjectProvider(ObjectProvider op)
Method to add the object managed by the specified ObjectProvider to the (L1) cache.

Specified by:
addObjectProvider in interface ExecutionContext
Parameters:
op - The ObjectProvider

removeObjectProvider

public void removeObjectProvider(ObjectProvider op)
Method to remove the object managed by the specified ObjectProvider from the cache.

Specified by:
removeObjectProvider in interface ExecutionContext
Parameters:
op - The ObjectProvider

findObjectProvider

public ObjectProvider findObjectProvider(Object pc)
Method to find the ObjectProvider for an object.

Specified by:
findObjectProvider in interface ExecutionContext
Parameters:
pc - The object we are checking
Returns:
The ObjectProvider, null if not found.

findObjectProvider

public ObjectProvider findObjectProvider(Object pc,
                                         boolean persist)
Description copied from interface: ExecutionContext
Method to find the ObjectProvider for the passed persistable object when it is managed by this manager, and if not yet persistent to persist it.

Specified by:
findObjectProvider in interface ExecutionContext
Parameters:
persist - persists the object if not yet persisted.
pc - The persistable object
Returns:
The ObjectProvider

findObjectProviderForEmbedded

public ObjectProvider findObjectProviderForEmbedded(Object value,
                                                    ObjectProvider owner,
                                                    AbstractMemberMetaData mmd)
Description copied from interface: ExecutionContext
Method to find the ObjectProvider for the passed embedded persistable object. Will create one if not already registered, and tie it to the specified owner.

Specified by:
findObjectProviderForEmbedded in interface ExecutionContext
Parameters:
value - The embedded object
owner - The owner ObjectProvider (if known).
mmd - Metadata for the field of the owner
Returns:
The ObjectProvider for the embedded object

newObjectProviderForHollow

public ObjectProvider newObjectProviderForHollow(Class pcClass,
                                                 Object id)
Constructs an ObjectProvider to manage a hollow instance having the given object ID. This constructor is used for creating new instances of existing persistent objects.

Specified by:
newObjectProviderForHollow in interface ExecutionContext
Parameters:
pcClass - the class of the new instance to be created.
id - the JDO identity of the object.

newObjectProviderForHollowPreConstructed

public ObjectProvider newObjectProviderForHollowPreConstructed(Object id,
                                                               Object pc)
Constructs an ObjectProvider to manage a hollow instance having the given object ID. The instance is already supplied.

Specified by:
newObjectProviderForHollowPreConstructed in interface ExecutionContext
Parameters:
id - the JDO identity of the object.
pc - The object that is hollow that we are going to manage

newObjectProviderForHollowPopulated

public ObjectProvider newObjectProviderForHollowPopulated(Class pcClass,
                                                          Object id,
                                                          FieldValues fv)
Constructs an ObjectProvider to manage a recently populated hollow instance having the given object ID and the given field values. This constructor is used for creating new instances of persistent objects obtained e.g. via a Query or backed by a view.

Specified by:
newObjectProviderForHollowPopulated in interface ExecutionContext
Parameters:
pcClass - the class of the new instance to be created.
id - the JDO identity of the object.
fv - the initial field values of the object.

newObjectProviderForPersistentClean

public ObjectProvider newObjectProviderForPersistentClean(Object id,
                                                          Object pc)
Constructs an ObjectProvider to manage the specified persistent instance having the given object ID.

Specified by:
newObjectProviderForPersistentClean in interface ExecutionContext
Parameters:
id - the JDO identity of the object.
pc - The object that is persistent that we are going to manage

newObjectProviderForHollowPopulatedAppId

public ObjectProvider newObjectProviderForHollowPopulatedAppId(Class pcClass,
                                                               FieldValues fv)
Deprecated. Use newObjectProviderForHollowPopulated instead

Constructs an ObjectProvider to manage a hollow (or pclean) instance having the given FieldValues. This constructor is used for creating new instances of existing persistent objects using application identity.

Specified by:
newObjectProviderForHollowPopulatedAppId in interface ExecutionContext
Parameters:
pcClass - the class of the new instance to be created.
fv - the initial field values of the object.

newObjectProviderForEmbedded

public ObjectProvider newObjectProviderForEmbedded(Object pc,
                                                   boolean copyPc,
                                                   ObjectProvider ownerOP,
                                                   int ownerFieldNumber)
Constructs an ObjectProvider to manage a persistable instance that will be EMBEDDED/SERIALISED into another persistable object. The instance will not be assigned an identity in the process since it is a SCO.

Specified by:
newObjectProviderForEmbedded in interface ExecutionContext
Parameters:
pc - The persistable to manage (see copyPc also)
copyPc - Whether the SM should manage a copy of the passed PC or that one
ownerOP - Owner ObjectProvider
ownerFieldNumber - Field number in owner object where this is stored

newObjectProviderForEmbedded

public ObjectProvider newObjectProviderForEmbedded(AbstractClassMetaData cmd,
                                                   ObjectProvider ownerOP,
                                                   int ownerFieldNumber)
Constructs an ObjectProvider for an object of the specified type, creating the PC object to hold the values where this object will be EMBEDDED/SERIALISED into another persistable object. The instance will not be assigned an identity in the process since it is a SCO.

Specified by:
newObjectProviderForEmbedded in interface ExecutionContext
Parameters:
cmd - Meta-data for the class that this is an instance of.
ownerOP - Owner ObjectProvider
ownerFieldNumber - Field number in owner object where this is stored

newObjectProviderForPersistentNew

public ObjectProvider newObjectProviderForPersistentNew(Object pc,
                                                        FieldValues preInsertChanges)
Constructs an ObjectProvider to manage a transient instance that is becoming newly persistent. A new object ID for the instance is obtained from the store manager and the object is inserted in the data store. This constructor is used for assigning ObjectProviders to existing instances that are transitioning to a persistent state.

Specified by:
newObjectProviderForPersistentNew in interface ExecutionContext
Parameters:
pc - the instance being make persistent.
preInsertChanges - Any changes to make before inserting

newObjectProviderForTransactionalTransient

public ObjectProvider newObjectProviderForTransactionalTransient(Object pc)
Constructs an ObjectProvider to manage a Transactional-Transient instance. A new object ID for the instance is obtained from the store manager and the object is inserted in the data store. This constructor is used for assigning state managers to Transient instances that are transitioning to a transient clean state.

Specified by:
newObjectProviderForTransactionalTransient in interface ExecutionContext
Parameters:
ec - ExecutionContext
pc - the instance being make persistent.

newObjectProviderForDetached

public ObjectProvider newObjectProviderForDetached(Object pc,
                                                   Object id,
                                                   Object version)
Constructor for creating ObjectProvider instances to manage persistable objects in detached state.

Specified by:
newObjectProviderForDetached in interface ExecutionContext
Parameters:
pc - the detached object
id - the JDO identity of the object.
version - the detached version

newObjectProviderForPNewToBeDeleted

public ObjectProvider newObjectProviderForPNewToBeDeleted(Object pc)
Constructor for creating ObjectProvider instances to manage persistable objects that are not persistent yet are about to be deleted. Consequently the initial lifecycle state will be P_NEW, but will soon move to P_NEW_DELETED.

Specified by:
newObjectProviderForPNewToBeDeleted in interface ExecutionContext
Parameters:
pc - the object being deleted from persistence

newObjectProviderForCachedPC

protected ObjectProvider newObjectProviderForCachedPC(Object id,
                                                      CachedPC cachedPC)
Constructor to create a ObjectProvider for an object taken from the L2 cache with the specified id. Creates an object that the cached object represents, assigns a ObjectProvider to it, and copies across the fields that were cached, and assigns a version (if available).

Parameters:
id - Id to assign to the persistable object
cachedPC - CachedPC object from the L2 cache

hereIsObjectProvider

public void hereIsObjectProvider(ObjectProvider op,
                                 Object pc)
Method to add the ObjectProvider for an object to this ObjectManager's list.

Specified by:
hereIsObjectProvider in interface ExecutionContext
Parameters:
op - The ObjectProvider
pc - The object managed by the ObjectProvider

close

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

Specified by:
close in interface ExecutionContext

disconnectObjectProvidersFromCache

protected void disconnectObjectProvidersFromCache()
Disconnect ObjectProviders that are cached from their objects, and removes them from the cache.


processNontransactionalUpdate

public void processNontransactionalUpdate()
Method called when a non-tx update has been performed (via setter call on the persistable object, or via use of mutator methods of a field). Only hands the update across to be "committed" if not part of an owning persist/delete call.

Specified by:
processNontransactionalUpdate in interface ExecutionContext

processNontransactionalAtomicChanges

protected void processNontransactionalAtomicChanges()
Handler for all outstanding changes to be "committed" atomically. If a transaction is active, non-tx writes are disabled, or atomic updates not enabled then will do nothing. Otherwise will flush any updates that are outstanding (updates to an object), will perform detachAllOnCommit if enabled (so user always has detached objects), update objects in any L2 cache, and migrates any objects through lifecycle changes. Is similar in content to "flush"+"preCommit"+"postCommit" Note that this handling for updates is not part of standard JDO which expects non-tx updates to migrate an object to P_NONTRANS_DIRTY rather than committing it directly. TODO If any update fails we should throw the appropriate exception for the API


evictObject

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

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

evictObjects

public void evictObjects(Class cls,
                         boolean subclasses)
Method to evict all objects of the specified type (and optionaly its subclasses) that are present in the L1 cache.

Specified by:
evictObjects in interface ExecutionContext
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 ExecutionContext

refreshObject

public void refreshObject(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 ExecutionContext
Parameters:
obj - The Object

refreshAllObjects

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

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

retrieveObject

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

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

persistObject

public Object persistObject(Object obj,
                            boolean merging)
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 ExecutionContext
Parameters:
obj - The object
merging - Whether this object (and dependents) is being merged
Returns:
The persisted object
Throws:
NucleusUserException - if the object is managed by a different manager

persistObjects

public Object[] persistObjects(Object[] objs)
Method to persist an array of objects to the datastore.

Specified by:
persistObjects in interface ExecutionContext
Parameters:
objs - The objects to persist
Returns:
The persisted objects
Throws:
NucleusUserException - Thrown if an error occurs during the persist process. Any exception could have several nested exceptions for each failed object persist

persistObjectInternal

public Object persistObjectInternal(Object obj,
                                    FieldValues preInsertChanges,
                                    ObjectProvider ownerOP,
                                    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 ExecutionContext
Parameters:
obj - The object
preInsertChanges - Any changes to make before inserting
ownerOP - ObjectProvider 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.ObjectProvider, e.g ObjectProvider.PC)
Returns:
The persisted object
Throws:
NucleusUserException - if the object is managed by a different manager

persistObjectInternal

public Object persistObjectInternal(Object pc,
                                    ObjectProvider ownerOP,
                                    int ownerFieldNum,
                                    int objectType)
Method to persist the passed object (internally).

Specified by:
persistObjectInternal in interface ExecutionContext
Parameters:
pc - The object
ownerOP - ObjectProvider 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.ObjectProvider, e.g ObjectProvider.PC)
Returns:
The persisted object

persistObjectInternal

public Object persistObjectInternal(Object pc,
                                    FieldValues preInsertChanges,
                                    int objectType)
Description copied from interface: ExecutionContext
Method to persist the passed object (internally).

Specified by:
persistObjectInternal in interface ExecutionContext
Parameters:
pc - The object
preInsertChanges - Changes to be made before inserting
objectType - Type of object (see org.datanucleus.StateManager, e.g StateManager.PC)
Returns:
The persisted object

deleteObjects

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

Specified by:
deleteObjects in interface ExecutionContext
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

deleteObject

public void deleteObject(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 ExecutionContext
Parameters:
obj - The object

deleteObjectInternal

public void deleteObjectInternal(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 ExecutionContext
Parameters:
obj - Object to delete

makeObjectTransient

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

Specified by:
makeObjectTransient in interface ExecutionContext
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(Object obj)
Method to make an object transactional.

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

makeObjectNontransactional

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

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

attachObject

public void attachObject(ObjectProvider ownerOP,
                         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 ExecutionContext
Parameters:
ownerOP - ObjectProvider of the owner object that has this in a field that causes this attach
pc - The persistable object
sco - Whether the PC object is stored without an identity (embedded/serialised)

attachObjectCopy

public Object attachObjectCopy(ObjectProvider ownerOP,
                               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 ExecutionContext
Parameters:
ownerOP - ObjectProvider of the owner object that has this in a field that causes this attach
pc - The object
sco - Whether it has no identity (second-class object)
Returns:
The attached object

detachObject

public void detachObject(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 NucleusUserException is thrown. For internal use only

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

detachObjectCopy

public Object detachObjectCopy(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 ExecutionContext
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. Detaches all objects enlisted as well as all objects in the L1 cache. Of particular use with JPA when doing a clear of the persistence context.

Specified by:
detachAll in interface ExecutionContext

newInstance

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

Specified by:
newInstance in interface ExecutionContext
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(Object obj)
Method to return if the specified object exists in the datastore.

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

getManagedObjects

public 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 ExecutionContext
Returns:
Collection of managed objects enlisted in the current transaction

getManagedObjects

public Set getManagedObjects(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 ExecutionContext
Parameters:
classes - Classes that we want the enlisted objects for
Returns:
Collection of managed objects enlisted in the current transaction

getManagedObjects

public Set getManagedObjects(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 ExecutionContext
Parameters:
states - States that we want the enlisted objects for
Returns:
Collection of managed objects enlisted in the current transaction

getManagedObjects

public Set getManagedObjects(String[] states,
                             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 ExecutionContext
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

findObject

public Object findObject(Object id,
                         FieldValues fv,
                         Class cls,
                         boolean ignoreCache,
                         boolean checkInheritance)
Accessor for an object given the object id and a set of field values to apply to it. This is intended for use where we have done a query and have the id from the results, and we want to create the object, preferably using the cache, and then apply any field values to it.

Specified by:
findObject in interface ExecutionContext
Parameters:
id - Id of the object.
fv - Field values for the object (to copy in)
cls - the type which the object is (optional). Used to instantiate the object
ignoreCache - true if it must ignore the cache
checkInheritance - Whether to check the inheritance on the id of the object
Returns:
The Object

findObjects

public Object[] findObjects(Object[] identities,
                            boolean validate)
Accessor for objects with the specified identities.

Specified by:
findObjects in interface ExecutionContext
Parameters:
identities - Ids of the object(s).
validate - Whether to validate the object state
Returns:
The Objects with these ids (same order)
Throws:
NucleusObjectNotFoundException - if an object doesn't exist in the datastore

findObject

public Object findObject(Object id,
                         boolean validate,
                         boolean checkInheritance,
                         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.

Specified by:
findObject in interface ExecutionContext
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
Throws:
NucleusObjectNotFoundException - if the object doesn't exist in the datastore

newObjectId

public Object newObjectId(Class pcClass,
                          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 ExecutionContext
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 Object newObjectId(String className,
                          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 ExecutionContext
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(ObjectProvider op)
Method to clear an object from the list of dirty objects.

Specified by:
clearDirty in interface ExecutionContext
Parameters:
op - The ObjectProvider

clearDirty

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

Specified by:
clearDirty in interface ExecutionContext

markDirty

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

Specified by:
markDirty in interface ExecutionContext
Parameters:
op - ObjectProvider
directUpdate - Whether the object has had a direct update made on it (if known)

getManageRelations

public boolean getManageRelations()
Accessor for whether to manage relationships at flush/commit.

Specified by:
getManageRelations in interface ExecutionContext
Returns:
Whether to manage relationships at flush/commit.

getManageRelationsChecks

public boolean getManageRelationsChecks()
Accessor for whether to manage relationships checks at flush/commit.

Returns:
Whether to manage relationships checks at flush/commit.

getRelationshipManager

public RelationshipManager getRelationshipManager(ObjectProvider op)
Description copied from interface: ExecutionContext
Accessor for the RelationshipManager for the provided ObjectProvider.

Specified by:
getRelationshipManager in interface ExecutionContext
Parameters:
op - ObjectProvider
Returns:
The RelationshipManager

isManagingRelations

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

Specified by:
isManagingRelations in interface ExecutionContext
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

getObjectsToBeFlushed

public List<ObjectProvider> getObjectsToBeFlushed()
Convenience method to inspect the list of objects with outstanding changes to flush.

Specified by:
getObjectsToBeFlushed in interface ExecutionContext
Returns:
ObjectProviders for the objects to be flushed.

isFlushing

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

Specified by:
isFlushing in interface ExecutionContext
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 ExecutionContext

flushInternal

public void flushInternal(boolean flushToDatastore)
This method flushes all dirty, new, and deleted instances to the datastore.

Specified by:
flushInternal in interface ExecutionContext
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

flushInternalWithOrdering

protected List<NucleusOptimisticException> flushInternalWithOrdering()
Flush process that takes the objects in the order that they became dirty. If a datastore uses referential integrity this is typically the best way of maintaining a valid update process.

Returns:
Any optimistic exception(s) thrown by the update

flushInternalNonReferential

protected List<NucleusOptimisticException> flushInternalNonReferential()
Flush method for cases where the datastore doesn't use referential integrity so we can send batches of deletes, then batches of inserts, then any updates to optimise the persistence.

Returns:
Any optimistic exceptions during the deletes/inserts/updates

postBegin

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


preCommit

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


isObjectModifiedInTransaction

public boolean isObjectModifiedInTransaction(Object id)
Accessor for whether the object with this identity is modified in the current transaction. Only returns true when using the L2 cache and the object has been modified during the txn.

Specified by:
isObjectModifiedInTransaction in interface ExecutionContext
Parameters:
id - The identity
Returns:
Whether it is modified/new/deleted in this transaction

isRunningDetachAllOnCommit

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

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

postCommit

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


preRollback

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


postRollback

public void postRollback()
Callback invoked after the actual datastore rollback.


putObjectIntoLevel1Cache

public void putObjectIntoLevel1Cache(ObjectProvider op)
Convenience method to add an object to the L1 cache.

Specified by:
putObjectIntoLevel1Cache in interface ExecutionContext
Parameters:
op - The ObjectProvider

putObjectIntoLevel2Cache

protected void putObjectIntoLevel2Cache(ObjectProvider op,
                                        boolean updateIfPresent)
Method to add/update the managed object into the L2 cache as long as it isn't modified in the current transaction.

Parameters:
op - ObjectProvider for the object
updateIfPresent - Whether to update it in the L2 cache if already present

getL2CacheableObject

protected CachedPC getL2CacheableObject(ObjectProvider op)
Convenience method to convert the object managed by the ObjectProvider into a form suitable for caching in an L2 cache.

Parameters:
op - ObjectProvider for the object
Returns:
The cacheable form of the object

putObjectsIntoLevel2Cache

protected void putObjectsIntoLevel2Cache(Set<ObjectProvider> ops)
Method to put the passed objects into the L2 cache. Performs the "put" in batches

Parameters:
ops - The ObjectProviders whose objects are to be cached

putObjectIntoLevel2CacheInternal

protected void putObjectIntoLevel2CacheInternal(ObjectProvider op,
                                                boolean updateIfPresent)
Convenience method to add/update an object in the L2 cache.

Parameters:
op - ObjectProvider of the object to add.
updateIfPresent - Whether to update the L2 cache if it is present

removeObjectFromLevel1Cache

public void removeObjectFromLevel1Cache(Object id)
Convenience method to evict an object from the L1 cache.

Specified by:
removeObjectFromLevel1Cache in interface ExecutionContext
Parameters:
id - The Persistable object id

removeObjectFromLevel2Cache

public void removeObjectFromLevel2Cache(Object id)
Convenience method to remove the object with the specified identity from the L2 cache.

Specified by:
removeObjectFromLevel2Cache in interface ExecutionContext
Parameters:
id - Identity of the object

hasIdentityInCache

public boolean hasIdentityInCache(Object id)
Whether the specified identity is cached currently. Looks in L1 cache and L2 cache.

Specified by:
hasIdentityInCache in interface ExecutionContext
Parameters:
id - The identity
Returns:
Whether an object exists in the cache(s) with this identity

getObjectFromCache

public Object getObjectFromCache(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 ExecutionContext
Parameters:
id - Id of the object
Returns:
Persistence Capable object (with connected ObjectProvider).

getObjectFromLevel1Cache

public Object getObjectFromLevel1Cache(Object id)
Convenience method to access an object in the Level 1 cache.

Parameters:
id - Id of the object
Returns:
Persistable object (with connected ObjectProvider).

getObjectFromLevel2Cache

public Object getObjectFromLevel2Cache(Object id)
Convenience method to access an object in the Level 2 cache.

Parameters:
id - Id of the object
Returns:
Persistable object (with connected ObjectProvider).

getObjectsFromLevel2Cache

protected Map getObjectsFromLevel2Cache(Collection ids)
Convenience method to access a collection of objects from the Level 2 cache.

Parameters:
ids - Collection of ids to retrieve
Returns:
Map of persistable objects (with connected ObjectProvider) keyed by their id if found in the L2 cache

replaceObjectId

public void replaceObjectId(Object pc,
                            Object oldID,
                            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 ExecutionContext
Parameters:
pc - The Persistable object
oldID - the old id it was known by
newID - the new id

getSerializeReadForClass

public boolean getSerializeReadForClass(String className)
Convenience method to return the setting for serialize read for the current transaction for the specified class name. Returns the setting for the transaction (if set), otherwise falls back to the setting for the class, otherwise returns false.

Specified by:
getSerializeReadForClass in interface ExecutionContext
Parameters:
className - Name of the class
Returns:
Setting for serialize read

getExtent

public Extent getExtent(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 ExecutionContext
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 ExecutionContext
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 PMF/EMF. Otherwise they might be registered multiple times.


getCallbackHandler

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

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

addListener

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

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

removeListener

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

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

disconnectLifecycleListener

public void disconnectLifecycleListener()
Disconnect the registered LifecycleListener

Specified by:
disconnectLifecycleListener in interface ExecutionContext

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(Class cls)
Method to assert if the specified class is Persistence Capable.

Specified by:
assertClassPersistable in interface ExecutionContext
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(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(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


assertHasImplementationCreator

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

Throws:
NucleusUserException - if an ImplementationCreator instance does not exist

hasPersistenceInformationForClass

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

Specified by:
hasPersistenceInformationForClass in interface ExecutionContext
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.

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

removeInternalFetchGroup

protected void removeInternalFetchGroup(FetchGroup grp)
Method to remove a dynamic FetchGroup.

Parameters:
grp - The group

getInternalFetchGroup

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

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

getFetchGroupsWithName

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

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

getLock

public Lock getLock()
Accessor for the ObjectManager lock object.

Specified by:
getLock in interface ExecutionContext
Returns:
The lock object


Copyright © 2012. All Rights Reserved.