Class ExecutionContextImpl
- java.lang.Object
-
- org.datanucleus.ExecutionContextImpl
-
- All Implemented Interfaces:
ExecutionContextReference
,ExecutionContext
,TransactionEventListener
- Direct Known Subclasses:
ExecutionContextThreadedImpl
public class ExecutionContextImpl extends Object implements ExecutionContext, TransactionEventListener
Manager for persistence/retrieval of objects within an execution context, equating to the work required by JDO PersistenceManager and JPA EntityManager.Caching
An ExecutionContext 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 NucleusContext also has a Level 2 cache. This is used to allow cross-communication between ExecutionContexts. 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 ExecutionContext 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.
StateManager-based storage
You may note that we have various fields here storing StateManager-related information such as which StateManager is embedded into which StateManager etc, or the managed relations for a StateManager. These are stored here to avoid adding a reference to the storage of each and every StateManager, since we could potentially have a very large number of StateManagers (and they may not use that field in the majority, but it still needs the reference). The same should be followed as a general rule when considering storing something in StateManager.
This class is NOT thread-safe. Use ExecutionContextThreadedImpl if you want to *attempt* to have multithreaded PM/EMs.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ExecutionContextImpl.NullCallbackHandler
Callback handler that does nothing.-
Nested classes/interfaces inherited from interface org.datanucleus.ExecutionContext
ExecutionContext.EmbeddedOwnerRelation, ExecutionContext.LifecycleListener
-
-
Field Summary
Fields Modifier and Type Field Description protected Level1Cache
cache
Level 1 Cache, essentially a Map of StateManager keyed by the id.protected Map<DNStateManager,Map<?,?>>
stateManagerAssociatedValuesMap
Map of associated values per StateManager.-
Fields inherited from interface org.datanucleus.ExecutionContext
OPTION_JTA_AUTOJOIN, OPTION_PASSWORD, OPTION_USERNAME
-
-
Constructor Summary
Constructors Constructor Description ExecutionContextImpl(PersistenceNucleusContext ctx, Object owner, Map<String,Object> options)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.datanucleus.ExecutionContextImpl.ThreadContextInfo
acquireThreadContextInfo()
Accessor for the thread context information, for the current thread.void
addInternalFetchGroup(FetchGroup grp)
Method to add a dynamic FetchGroup.void
addOperationToQueue(Operation oper)
Method to add an operation to the queue.void
addStateManagerToCache(DNStateManager sm)
Method to add the object managed by the specified StateManager 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
assertIsOpen()
Method to assert if this context is open.protected void
assertNotDetached(Object object)
Method to assert if the specified object is detached.void
attachObject(DNStateManager ownerSM, Object pc, boolean sco)
Method to attach a persistent detached object.<T> T
attachObjectCopy(DNStateManager ownerSM, T 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(DNStateManager sm)
Method to clear an object from the list of dirty objects.void
close()
Method to close the context.void
closeCallbackHandler()
Close the callback handler and disconnect any registered listeners.boolean
containsStateManagerAssociatedValue(DNStateManager sm, Object key)
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
deregisterEmbeddedRelation(ExecutionContext.EmbeddedOwnerRelation rel)
Method to deregister the specified embedded relation (e.g when the embedded object is disconnected).void
deregisterExecutionContextListener(ExecutionContextListener listener)
Deregister a listener from calling when this ExecutionContext is closing.void
detachAll()
Method to detach all objects in the context.void
detachObject(FetchPlanState state, Object obj)
Method to detach a persistent object without making a copy.<T> T
detachObjectCopy(FetchPlanState state, T pc)
Detach a copy of the passed persistent object using the provided detach state.void
detachObjects(FetchPlanState state, Object... pcs)
Method to detach the passed object(s).void
enlistInTransaction(DNStateManager sm)
Method to enlist the specified StateManager in the current transaction.void
evictAllObjects()
Method to evict all current objects from L1 cache.void
evictFromTransaction(DNStateManager sm)
Method to evict the specified StateManager 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 optionally its subclasses) that are present in the L1 cache.boolean
exists(Object obj)
Method to return if the specified object exists in the datastore.<T> T
findObject(Class<T> cls, Object key)
Accessor for an object of the specified type with the provided id "key".Persistable
findObject(Object id, boolean validate)
Shortcut to calling "findObject(id, validate, validate, null)".Persistable
findObject(Object id, boolean validate, boolean checkInheritance, String objectClassName)
Accessor for an object given the object id.Persistable
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.<T> T
findObjectByUnique(Class<T> cls, String[] memberNames, Object[] memberValues)
Accessor for an object of the specified type with the provided values for a unique key.<T> List<T>
findObjects(Class<T> cls, List keys)
Accessor for objects of the specified type, with the provided id "key"s.Persistable[]
findObjectsById(Object[] identities, boolean validate)
Accessor for objects with the specified identities.DNStateManager
findStateManager(Object pc)
Method to return StateManager for an object (if managed).DNStateManager
findStateManager(Object pc, boolean persist)
Find StateManager for the specified object, persisting it if required and assigning a StateManager if doing soDNStateManager
findStateManagerForEmbedded(Object value, DNStateManager ownerSM, AbstractMemberMetaData mmd, PersistableObjectType objectType)
Method to find StateManager for the passed embedded persistable object.DNStateManager
findStateManagerOfOwnerForAttachingObject(Object pc)
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.void
flushOperationsForBackingStore(Store backingStore, DNStateManager sm)
Method to flush all queued operations for the specified backing store (if any).Object
getAttachDetachReferencedObject(DNStateManager sm)
Access a referenced object for this StateManager during the attach/detach process.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 context.ClassLoaderResolver
getClassLoaderResolver()
Accessor for the ClassLoader resolver to use in class loading issues.String
getCurrentUser()
Accessor for the current user, for this ExecutionContext.List<ExecutionContext.EmbeddedOwnerRelation>
getEmbeddedInformationForOwner(DNStateManager ownerSM)
Accessor for the relations for the specified embedded StateManager where it is embedded.<T> Extent<T>
getExtent(Class<T> 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<FetchGroup>
getFetchGroupsWithName(String name)
Accessor for the fetch groups for the specified name.FetchPlan
getFetchPlan()
Acessor for the current FetchPlanFlushMode
getFlushMode()
Accessor for the flush mode.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(DNStateManager sm, CachedPC currentCachedPC)
Convenience method to convert the object managed by StateManager into a form suitable for caching in an L2 cache.Level1Cache
getLevel1Cache()
protected String
getLevel2CacheRetrieveMode()
protected String
getLevel2CacheStoreMode()
LockManager
getLockManager()
Accessor for the lock manager for objects in 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
getMultithreaded()
Accessor for whether this context is multithreaded.PersistenceNucleusContext
getNucleusContext()
Accessor for the context in which this execution context is running.Persistable
getObjectFromCache(Object id)
Convenience method to access an object in the cache.protected Persistable
getObjectFromLevel1Cache(Object id)
Convenience method to access an object in the Level 1 cache.protected Persistable
getObjectFromLevel2Cache(Object id)
Convenience method to access an object in the Level 2 cache.protected Persistable
getObjectFromLevel2CacheForUnique(CacheUniqueKey uniKey)
Convenience method to access the identity that corresponds to a unique key, in the Level 2 cache.Persistable[]
getObjectsFromCache(Object[] ids)
Convenience method to access objects in the cache.protected Map<Object,Persistable>
getObjectsFromLevel2Cache(Collection ids)
Convenience method to access a collection of objects from the Level 2 cache.List<DNStateManager>
getObjectsToBeFlushed()
Convenience method to inspect the list of objects with outstanding changes to flush.OperationQueue
getOperationQueue()
Accessor for the operation queue.Object
getOwner()
Accessor for the owner of this ExecutionContext.DNStateManager
getOwnerForEmbeddedStateManager(DNStateManager embSM)
Accessor for the owner StateManager for the provided embedded StateManager.ExecutionContext.EmbeddedOwnerRelation
getOwnerInformationForEmbedded(DNStateManager embSM)
Accessor for the owner relation for the specified embedded StateManager where it is embedded.Map<String,Object>
getProperties()
Accessor for the defined properties.Object
getProperty(String name)
Accessor for a property.RelationshipManager
getRelationshipManager(DNStateManager sm)
Method to return the RelationshipManager for StateManager.boolean
getSerializeReadForClass(String className)
Convenience method to return the setting for serialize read for the current transaction for the specified class name.Object
getStateManagerAssociatedValue(DNStateManager sm, Object key)
ManagerStatistics
getStatistics()
Accessor for any statistics-gathering object.String
getStringProperty(String name)
Accessor for a String property value.Set<String>
getSupportedProperties()
Accessor for the supported property names.String
getTenantId()
Accessor for the tenant id, for this ExecutionContext.protected org.datanucleus.ExecutionContextImpl.ThreadContextInfo
getThreadContextInfo()
Get the current ThreadContextInfo assigned to the current thread without changing the reference counter.Transaction
getTransaction()
Accessor for the current transaction for this execution context.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
initialise(Object owner, Map<String,Object> options)
protected void
initialiseLevel1Cache()
Method to initialise the L1 cache.boolean
isClosed()
Accessor for whether this context 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 context is in the process of flushing.boolean
isInserting(Object pc)
Tests whether this persistable object is being inserted.boolean
isManagingRelations()
Returns whether this context 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 context is currently running detachAllOnCommit.void
makeObjectNontransactional(Object obj)
Method to make the passed 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(DNStateManager sm, boolean directUpdate)
Method to mark an object (StateManager) as dirty.void
markFieldsForUpdateInLevel2Cache(Object id, boolean[] fields)
Method to mark the object with specifed id to have the supplied fields updated in the L2 cache at commit.<T> T
newInstance(Class<T> 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).boolean
operationQueueIsActive()
Accessor for whether the operation queue is currently active.Object
persistObject(Object obj, boolean merging)
Method to make an object persistent.<T> T
persistObjectInternal(T obj, FieldValues preInsertChanges, PersistableObjectType objectType, DNStateManager ownerSM, int ownerFieldNum)
Method to make an object persistent which should be called from INTERNAL (DataNucleus) calls only.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(DNStateManager sm)
Convenience method to add an object to the L1 cache.void
putObjectIntoLevel2Cache(DNStateManager sm, 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(DNStateManager sm, boolean updateIfPresent)
Convenience method to add/update an object in the L2 cache.protected void
putObjectsIntoLevel2Cache(Set<DNStateManager> sms)
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.ExecutionContext.EmbeddedOwnerRelation
registerEmbeddedRelation(DNStateManager ownerSM, int ownerMemberNum, PersistableObjectType objectType, DNStateManager embSM)
Method to register an embedded relation for the specified member of the owner StateManager where the embedded StateManager is stored.void
registerExecutionContextListener(ExecutionContextListener listener)
Register a listener to be called when this ExecutionContext is closing.protected void
releaseThreadContextInfo()
Method to remove the current thread context info for the current thread, after the reference counter reached 0.void
removeEmbeddedOwnerRelation(DNStateManager ownerSM, int ownerFieldNum, DNStateManager embSM)
Convenience method to remove the EmbeddedOwnerRelation between the specified StateManagers.protected void
removeInternalFetchGroup(FetchGroup grp)
Method to remove a dynamic FetchGroup.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
removeStateManagerAssociatedValue(DNStateManager sm, Object key)
void
removeStateManagerFromCache(DNStateManager sm)
Method to remove the object managed by the specified StateManager from the cache.void
replaceObjectId(Persistable pc, Object oldID, Object newID)
Replace the previous object id for a persistable object with a new one.void
retrieveObjects(boolean useFetchPlan, Object... pcs)
Method to retrieve the (fields of the) passed object(s).void
setAttachDetachReferencedObject(DNStateManager sm, Object obj)
Register a referenced object against this StateManager for the attach/detach process.protected void
setLevel2Cache(boolean flag)
Method to set whether we are supporting the Level2 Cache with this ExecutionContext Note that if the NucleusContext has no Level2 Cache enabled then you cannot turn it on here.void
setProperties(Map<String,Object> props)
Method to set properties on the execution context.void
setProperty(String name, Object value)
Method to set a property on the execution contextvoid
setStateManagerAssociatedValue(DNStateManager sm, Object key, Object value)
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
transactionReleaseSavepoint(String name)
Savepoint to be released for this name.void
transactionRollbackToSavepoint(String name)
Invoke a rollback to this savepoint name.void
transactionRolledBack()
Method invoked when the transaction is rolled back.void
transactionSetSavepoint(String name)
Savepoint to be registered under this name.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
-
Methods inherited from interface org.datanucleus.ExecutionContext
getApiAdapter, getMetaDataManager, getStoreManager, getTypeManager, persistObjectInternal, threadLock, threadUnlock
-
-
-
-
Field Detail
-
cache
protected Level1Cache cache
Level 1 Cache, essentially a Map of StateManager keyed by the id.
-
stateManagerAssociatedValuesMap
protected Map<DNStateManager,Map<?,?>> stateManagerAssociatedValuesMap
Map of associated values per StateManager. This can contain anything really and is down to the StoreManager to define. For example RDBMS datastores typically put external FK info in here keyed by the mapping of the field to which it pertains.
-
-
Constructor Detail
-
ExecutionContextImpl
public ExecutionContextImpl(PersistenceNucleusContext ctx, Object owner, Map<String,Object> options)
Constructor. TODO userName/password aren't currently used and we always use the PMF/EMF userName/password.- Parameters:
ctx
- NucleusContextowner
- Owning object (for bytecode enhancement contract, PersistenceManager)options
- Any options affecting startup- Throws:
NucleusUserException
- if an error occurs allocating the necessary requested components
-
-
Method Detail
-
initialise
public void initialise(Object owner, Map<String,Object> options)
- Specified by:
initialise
in interfaceExecutionContext
-
close
public void close()
Method to close the context.- Specified by:
close
in interfaceExecutionContext
-
registerExecutionContextListener
public void registerExecutionContextListener(ExecutionContextListener listener)
Description copied from interface:ExecutionContext
Register a listener to be called when this ExecutionContext is closing.- Specified by:
registerExecutionContextListener
in interfaceExecutionContext
- Parameters:
listener
- The listener
-
deregisterExecutionContextListener
public void deregisterExecutionContextListener(ExecutionContextListener listener)
Description copied from interface:ExecutionContext
Deregister a listener from calling when this ExecutionContext is closing.- Specified by:
deregisterExecutionContextListener
in interfaceExecutionContext
- Parameters:
listener
- The listener
-
setLevel2Cache
protected void setLevel2Cache(boolean flag)
Method to set whether we are supporting the Level2 Cache with this ExecutionContext Note that if the NucleusContext has no Level2 Cache enabled then you cannot turn it on here.- Parameters:
flag
- Whether to enable/disable it
-
isClosed
public boolean isClosed()
Accessor for whether this context is closed.- Specified by:
isClosed
in interfaceExecutionContext
- Returns:
- Whether this manager is closed.
-
acquireThreadContextInfo
protected org.datanucleus.ExecutionContextImpl.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.ExecutionContextImpl.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 byacquireThreadContextInfo()
.- See Also:
acquireThreadContextInfo()
-
transactionStarted
public void transactionStarted()
Description copied from interface:TransactionEventListener
Method invoked when the transaction is started.- Specified by:
transactionStarted
in interfaceTransactionEventListener
-
transactionPreFlush
public void transactionPreFlush()
Description copied from interface:TransactionEventListener
Method invoked just before a flush.- Specified by:
transactionPreFlush
in interfaceTransactionEventListener
-
transactionFlushed
public void transactionFlushed()
Description copied from interface:TransactionEventListener
Method invoked when the transaction is flushed (happens before commit, rollback).- Specified by:
transactionFlushed
in interfaceTransactionEventListener
-
transactionPreCommit
public void transactionPreCommit()
Description copied from interface:TransactionEventListener
Method invoked before the transaction commit.- Specified by:
transactionPreCommit
in interfaceTransactionEventListener
-
transactionCommitted
public void transactionCommitted()
Description copied from interface:TransactionEventListener
Method invoked when the transaction is committed.- Specified by:
transactionCommitted
in interfaceTransactionEventListener
-
transactionPreRollBack
public void transactionPreRollBack()
Description copied from interface:TransactionEventListener
Method invoked before the transaction is rolledback.- Specified by:
transactionPreRollBack
in interfaceTransactionEventListener
-
transactionRolledBack
public void transactionRolledBack()
Description copied from interface:TransactionEventListener
Method invoked when the transaction is rolled back.- Specified by:
transactionRolledBack
in interfaceTransactionEventListener
-
transactionEnded
public void transactionEnded()
Description copied from interface:TransactionEventListener
Method invoked when the transaction is ended (Using XA).- Specified by:
transactionEnded
in interfaceTransactionEventListener
-
transactionSetSavepoint
public void transactionSetSavepoint(String name)
Description copied from interface:TransactionEventListener
Savepoint to be registered under this name. Do nothing if not supported- Specified by:
transactionSetSavepoint
in interfaceTransactionEventListener
- Parameters:
name
- Name of the savepoint
-
transactionReleaseSavepoint
public void transactionReleaseSavepoint(String name)
Description copied from interface:TransactionEventListener
Savepoint to be released for this name. Do nothing if not supported- Specified by:
transactionReleaseSavepoint
in interfaceTransactionEventListener
- Parameters:
name
- Name of the savepoint
-
transactionRollbackToSavepoint
public void transactionRollbackToSavepoint(String name)
Description copied from interface:TransactionEventListener
Invoke a rollback to this savepoint name. Do nothing if not supported.- Specified by:
transactionRollbackToSavepoint
in interfaceTransactionEventListener
- Parameters:
name
- Name of the savepoint
-
getStatistics
public ManagerStatistics getStatistics()
Description copied from interface:ExecutionContext
Accessor for any statistics-gathering object.- Specified by:
getStatistics
in interfaceExecutionContext
- 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
-
getLevel1Cache
public Level1Cache getLevel1Cache()
- Specified by:
getLevel1Cache
in interfaceExecutionContext
-
getClassLoaderResolver
public ClassLoaderResolver getClassLoaderResolver()
Description copied from interface:ExecutionContext
Accessor for the ClassLoader resolver to use in class loading issues.- Specified by:
getClassLoaderResolver
in interfaceExecutionContext
- Returns:
- The ClassLoader resolver
-
getLockManager
public LockManager getLockManager()
Description copied from interface:ExecutionContext
Accessor for the lock manager for objects in this execution context.- Specified by:
getLockManager
in interfaceExecutionContext
- Returns:
- The lock manager
-
getFetchPlan
public FetchPlan getFetchPlan()
Description copied from interface:ExecutionContext
Acessor for the current FetchPlan- Specified by:
getFetchPlan
in interfaceExecutionContext
- Returns:
- FetchPlan
-
getNucleusContext
public PersistenceNucleusContext getNucleusContext()
Description copied from interface:ExecutionContext
Accessor for the context in which this execution context is running.- Specified by:
getNucleusContext
in interfaceExecutionContext
- Returns:
- Returns the context.
-
getOwner
public Object getOwner()
Accessor for the owner of this ExecutionContext. This will typically be PersistenceManager (JDO) or EntityManager (JPA).- Specified by:
getOwner
in interfaceExecutionContextReference
- Returns:
- The owner
-
setProperties
public void setProperties(Map<String,Object> props)
Description copied from interface:ExecutionContext
Method to set properties on the execution context.- Specified by:
setProperties
in interfaceExecutionContext
- 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 interfaceExecutionContext
- Parameters:
name
- Name of the propertyvalue
- Value to set
-
getProperties
public Map<String,Object> getProperties()
Description copied from interface:ExecutionContext
Accessor for the defined properties.- Specified by:
getProperties
in interfaceExecutionContext
- 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 interfaceExecutionContext
- 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 interfaceExecutionContext
- Parameters:
name
- Name of the property- Returns:
- the value
-
getStringProperty
public String getStringProperty(String name)
Description copied from interface:ExecutionContext
Accessor for a String property value.- Specified by:
getStringProperty
in interfaceExecutionContext
- 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 interfaceExecutionContext
- 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 interfaceExecutionContext
- Returns:
- Set of names
-
getMultithreaded
public boolean getMultithreaded()
Description copied from interface:ExecutionContext
Accessor for whether this context is multithreaded.- Specified by:
getMultithreaded
in interfaceExecutionContext
- Returns:
- Whether multithreaded (and hence needing locking)
-
getFlushMode
public FlushMode getFlushMode()
Description copied from interface:ExecutionContext
Accessor for the flush mode. Whether to auto-commit, or whether to delay flushing.- Specified by:
getFlushMode
in interfaceExecutionContext
- Returns:
- The flush mode.
-
isDelayDatastoreOperationsEnabled
public boolean isDelayDatastoreOperationsEnabled()
Description copied from interface:ExecutionContext
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 interfaceExecutionContext
- Returns:
- true if datastore operations are delayed until commit
-
getTenantId
public String getTenantId()
Description copied from interface:ExecutionContext
Accessor for the tenant id, for this ExecutionContext.- Specified by:
getTenantId
in interfaceExecutionContext
- Returns:
- The tenant id for this context.
-
getCurrentUser
public String getCurrentUser()
Description copied from interface:ExecutionContext
Accessor for the current user, for this ExecutionContext.- Specified by:
getCurrentUser
in interfaceExecutionContext
- Returns:
- The current user for this context
-
isInserting
public boolean isInserting(Object pc)
Description copied from interface:ExecutionContext
Tests whether this persistable object is being inserted.- Specified by:
isInserting
in interfaceExecutionContext
- Parameters:
pc
- the object to verify the status- Returns:
- true if this instance is inserting.
-
getTransaction
public Transaction getTransaction()
Description copied from interface:ExecutionContext
Accessor for the current transaction for this execution context.- Specified by:
getTransaction
in interfaceExecutionContext
- Returns:
- The current transaction
-
enlistInTransaction
public void enlistInTransaction(DNStateManager sm)
Description copied from interface:ExecutionContext
Method to enlist the specified StateManager in the current transaction.- Specified by:
enlistInTransaction
in interfaceExecutionContext
- Parameters:
sm
- StateManager
-
evictFromTransaction
public void evictFromTransaction(DNStateManager sm)
Description copied from interface:ExecutionContext
Method to evict the specified StateManager from the current transaction.- Specified by:
evictFromTransaction
in interfaceExecutionContext
- Parameters:
sm
- StateManager
-
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 interfaceExecutionContext
- Parameters:
id
- Identity for the object- Returns:
- Whether it is enlisted in the current transaction
-
addStateManagerToCache
public void addStateManagerToCache(DNStateManager sm)
Method to add the object managed by the specified StateManager to the (L1) cache.- Specified by:
addStateManagerToCache
in interfaceExecutionContext
- Parameters:
sm
- StateManager
-
removeStateManagerFromCache
public void removeStateManagerFromCache(DNStateManager sm)
Method to remove the object managed by the specified StateManager from the cache.- Specified by:
removeStateManagerFromCache
in interfaceExecutionContext
- Parameters:
sm
- StateManager
-
findStateManager
public DNStateManager findStateManager(Object pc)
Method to return StateManager for an object (if managed).- Specified by:
findStateManager
in interfaceExecutionContext
- Parameters:
pc
- The object we are checking- Returns:
- StateManager, null if not found.
- Throws:
NucleusUserException
- if the persistable object is managed by a different ExecutionContext
-
findStateManager
public DNStateManager findStateManager(Object pc, boolean persist)
Find StateManager for the specified object, persisting it if required and assigning a StateManager if doing so- Specified by:
findStateManager
in interfaceExecutionContext
- Parameters:
pc
- The persistable objectpersist
- persists the object if not yet persisted- Returns:
- StateManager
-
findStateManagerForEmbedded
public DNStateManager findStateManagerForEmbedded(Object value, DNStateManager ownerSM, AbstractMemberMetaData mmd, PersistableObjectType objectType)
Description copied from interface:ExecutionContext
Method to find StateManager for the passed embedded persistable object. Will create one if not already registered, and tie it to the specified owner.- Specified by:
findStateManagerForEmbedded
in interfaceExecutionContext
- Parameters:
value
- The embedded objectownerSM
- The owner StateManager (if known).mmd
- Metadata for the field of the ownerobjectType
- Type of persistable object being stored- Returns:
- StateManager for the embedded object
-
findStateManagerOfOwnerForAttachingObject
public DNStateManager findStateManagerOfOwnerForAttachingObject(Object pc)
- Specified by:
findStateManagerOfOwnerForAttachingObject
in interfaceExecutionContext
-
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 interfaceExecutionContext
-
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 interfaceExecutionContext
- 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 optionally its subclasses) that are present in the L1 cache.- Specified by:
evictObjects
in interfaceExecutionContext
- Parameters:
cls
- Type of persistable objectsubclasses
- Whether to include subclasses
-
evictAllObjects
public void evictAllObjects()
Method to evict all current objects from L1 cache.- Specified by:
evictAllObjects
in interfaceExecutionContext
-
refreshObject
public void refreshObject(Object obj)
Description copied from interface:ExecutionContext
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 interfaceExecutionContext
- Parameters:
obj
- The object
-
refreshAllObjects
public void refreshAllObjects()
Description copied from interface:ExecutionContext
Method to do a refresh of all objects.- Specified by:
refreshAllObjects
in interfaceExecutionContext
-
retrieveObjects
public void retrieveObjects(boolean useFetchPlan, Object... pcs)
Description copied from interface:ExecutionContext
Method to retrieve the (fields of the) passed object(s).- Specified by:
retrieveObjects
in interfaceExecutionContext
- Parameters:
useFetchPlan
- Whether to retrieve the current fetch planpcs
- The objects
-
persistObject
public Object persistObject(Object obj, boolean merging)
Description copied from interface:ExecutionContext
Method to make an object persistent. Should be called by EXTERNAL APIs (JDO/JPA) only. All INTERNAL (DataNucleus) calls should go via persistObjectInternal(...).- Specified by:
persistObject
in interfaceExecutionContext
- Parameters:
obj
- The objectmerging
- Whether this object (and dependents) is being merged- Returns:
- The persisted object
-
persistObjects
public Object[] persistObjects(Object... objs)
Description copied from interface:ExecutionContext
Method to persist an array of objects to the datastore. Should be called by EXTERNAL APIs (JDO/JPA) only.- Specified by:
persistObjects
in interfaceExecutionContext
- Parameters:
objs
- The objects to persist- Returns:
- The persisted objects
-
persistObjectInternal
public <T> T persistObjectInternal(T obj, FieldValues preInsertChanges, PersistableObjectType objectType, DNStateManager ownerSM, int ownerFieldNum)
Description copied from interface:ExecutionContext
Method to make an object persistent which should be called from INTERNAL (DataNucleus) calls only. All EXTERNAL (PM/EM) calls should go via persistObject(Object pc). To be used when providing the owner object details that this is part of (embedded).- Specified by:
persistObjectInternal
in interfaceExecutionContext
- Type Parameters:
T
- Type of the persistable object- Parameters:
obj
- The objectpreInsertChanges
- Any changes to make before insertingobjectType
- Type of objectownerSM
- StateManager of the owner when embedded (or attached?) (null if not embedded)ownerFieldNum
- Field number in the owner where this is embedded (or attached?) (-1 if not embedded)- Returns:
- The persisted object
-
deleteObjects
public void deleteObjects(Object... objs)
Description copied from interface:ExecutionContext
Method to delete an array of objects from the datastore.- Specified by:
deleteObjects
in interfaceExecutionContext
- Parameters:
objs
- The objects to delete
-
deleteObject
public void deleteObject(Object obj)
Description copied from interface:ExecutionContext
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 interfaceExecutionContext
- Parameters:
obj
- The object
-
deleteObjectInternal
public void deleteObjectInternal(Object obj)
Description copied from interface:ExecutionContext
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 interfaceExecutionContext
- Parameters:
obj
- Object to delete
-
makeObjectTransient
public void makeObjectTransient(Object obj, FetchPlanState state)
Description copied from interface:ExecutionContext
Method to migrate an object to transient state.- Specified by:
makeObjectTransient
in interfaceExecutionContext
- Parameters:
obj
- The objectstate
- Object containing the state of the fetch plan process (if any)
-
makeObjectTransactional
public void makeObjectTransactional(Object obj)
Description copied from interface:ExecutionContext
Method to make an object transactional.- Specified by:
makeObjectTransactional
in interfaceExecutionContext
- Parameters:
obj
- The object
-
makeObjectNontransactional
public void makeObjectNontransactional(Object obj)
Description copied from interface:ExecutionContext
Method to make the passed object nontransactional.- Specified by:
makeObjectNontransactional
in interfaceExecutionContext
- Parameters:
obj
- The object
-
attachObject
public void attachObject(DNStateManager ownerSM, Object pc, boolean sco)
Description copied from interface:ExecutionContext
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 interfaceExecutionContext
- Parameters:
ownerSM
- StateManager of the owner object that has this in a field that causes this attachpc
- The persistable objectsco
- Whether the PC object is stored without an identity (embedded/serialised)
-
attachObjectCopy
public <T> T attachObjectCopy(DNStateManager ownerSM, T pc, boolean sco)
Description copied from interface:ExecutionContext
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 interfaceExecutionContext
- Type Parameters:
T
- Type of the persistable object- Parameters:
ownerSM
- StateManager of the owner object that has this in a field that causes this attachpc
- The objectsco
- Whether it has no identity (second-class object)- Returns:
- The attached object
-
getAttachedObjectForId
public Object getAttachedObjectForId(Object id)
Description copied from interface:ExecutionContext
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 interfaceExecutionContext
- Parameters:
id
- The id- Returns:
- The attached object
-
detachObject
public void detachObject(FetchPlanState state, Object obj)
Description copied from interface:ExecutionContext
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.- Specified by:
detachObject
in interfaceExecutionContext
- Parameters:
state
- State for the detachment processobj
- The object
-
detachObjects
public void detachObjects(FetchPlanState state, Object... pcs)
Description copied from interface:ExecutionContext
Method to detach the passed object(s).- Specified by:
detachObjects
in interfaceExecutionContext
- Parameters:
state
- State for the detachment process.pcs
- The object(s) to detach
-
detachObjectCopy
public <T> T detachObjectCopy(FetchPlanState state, T pc)
Description copied from interface:ExecutionContext
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 interfaceExecutionContext
- Type Parameters:
T
- Type of the persistable object- Parameters:
state
- State for the detachment processpc
- The object- Returns:
- The detached object
-
detachAll
public void detachAll()
Description copied from interface:ExecutionContext
Method to detach all objects in the context. 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 interfaceExecutionContext
-
getAttachDetachReferencedObject
public Object getAttachDetachReferencedObject(DNStateManager sm)
Description copied from interface:ExecutionContext
Access a referenced object for this StateManager during the attach/detach process. When attaching and this is the detached object this returns the newly attached object. When attaching and this is the newly attached object this returns the detached object. When detaching and this is the newly detached object this returns the attached object. When detaching and this is the attached object this returns the newly detached object.- Specified by:
getAttachDetachReferencedObject
in interfaceExecutionContext
- Parameters:
sm
- StateManager- Returns:
- The referenced object (if any)
-
setAttachDetachReferencedObject
public void setAttachDetachReferencedObject(DNStateManager sm, Object obj)
Description copied from interface:ExecutionContext
Register a referenced object against this StateManager for the attach/detach process.- Specified by:
setAttachDetachReferencedObject
in interfaceExecutionContext
- Parameters:
sm
- StateManagerobj
- The referenced object (or null to clear out any reference)
-
newInstance
public <T> T newInstance(Class<T> cls)
Method to generate an instance of an interface, abstract class, or concrete PC class.- Specified by:
newInstance
in interfaceExecutionContext
- Type Parameters:
T
- Type of the persistable object- Parameters:
cls
- The class of the interface or abstract class, or concrete class defined in MetaData- Returns:
- The instance of this type
- Throws:
NucleusUserException
- if an ImplementationCreator instance does not exist and one is needed (i.e not a concrete class passed in)
-
exists
public boolean exists(Object obj)
Method to return if the specified object exists in the datastore.- Specified by:
exists
in interfaceExecutionContext
- 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 interfaceExecutionContext
- 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 interfaceExecutionContext
- 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 interfaceExecutionContext
- 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)
Description copied from interface:ExecutionContext
Accessor for the currently managed objects for the current transaction. If the transaction is not active this returns null.- Specified by:
getManagedObjects
in interfaceExecutionContext
- Parameters:
states
- States that we want the objects forclasses
- Classes that we want the objects for- Returns:
- Collection of managed objects enlisted in the current transaction
-
findObject
public <T> T findObject(Class<T> cls, Object key)
Description copied from interface:ExecutionContext
Accessor for an object of the specified type with the provided id "key". With datastore id or single-field id the "key" is the key of the id, and with composite ids the "key" is the toString() of the id.- Specified by:
findObject
in interfaceExecutionContext
- Type Parameters:
T
- Type of the persistable- Parameters:
cls
- Class of the persistablekey
- Value of the key field for SingleFieldIdentity, or the string value of the key otherwise- Returns:
- The object for this id.
-
findObjects
public <T> List<T> findObjects(Class<T> cls, List keys)
Description copied from interface:ExecutionContext
Accessor for objects of the specified type, with the provided id "key"s. With datastore id or single-field id the "key" is the key of the id, and with composite ids the "key" is the toString() of the id.- Specified by:
findObjects
in interfaceExecutionContext
- Type Parameters:
T
- Type of the persistable- Parameters:
cls
- Class of the persistablekeys
- Values of the key field for SingleFieldIdentity, or the string value of the keys otherwise- Returns:
- The objects meeting this requirement
-
findObjectByUnique
public <T> T findObjectByUnique(Class<T> cls, String[] memberNames, Object[] memberValues)
Description copied from interface:ExecutionContext
Accessor for an object of the specified type with the provided values for a unique key. Alternative would be to have an intermediate class and do thisec.findObjectByUnique(cls).for("field1", val1).for("field2", val2).find();
- Specified by:
findObjectByUnique
in interfaceExecutionContext
- Type Parameters:
T
- Type of the persistable- Parameters:
cls
- Class of the persistablememberNames
- Name(s) of the field(s) forming the unique keymemberValues
- Value(s) of the field(s) forming the unique key- Returns:
- The object meeting this requirement
-
findObject
public Persistable findObject(Object id, boolean validate)
Description copied from interface:ExecutionContext
Shortcut to calling "findObject(id, validate, validate, null)". Note: This is used by the bytecode enhancement contract indnCopyKeyFieldsFromObjectId
- Specified by:
findObject
in interfaceExecutionContext
- Specified by:
findObject
in interfaceExecutionContextReference
- Parameters:
id
- The id of the objectvalidate
- Whether to validate the id- Returns:
- The object
-
findObject
public Persistable findObject(Object id, FieldValues fv, Class cls, boolean ignoreCache, boolean checkInheritance)
Description copied from interface:ExecutionContext
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 interfaceExecutionContext
- 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 objectignoreCache
- true if it must ignore the cachecheckInheritance
- Whether to check the inheritance on the id of the object- Returns:
- The Object
-
findObjectsById
public Persistable[] findObjectsById(Object[] identities, boolean validate)
Description copied from interface:ExecutionContext
Accessor for objects with the specified identities.- Specified by:
findObjectsById
in interfaceExecutionContext
- Parameters:
identities
- Identities of the object(s).validate
- Whether to validate the object state- Returns:
- The Objects with these ids (same order)
-
findObject
public Persistable 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. TODO Would be nice, when using checkInheritance, to be able to specify the "id" is an instance of class X or subclass. See IdentityUtils where we have the root class- Specified by:
findObject
in interfaceExecutionContext
- Parameters:
id
- Id of the object.validate
- Whether to validate the object statecheckInheritance
- 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 :-- The class uses SingleFieldIdentity and the key is the value of the key field
- In all other cases the key is the String form of the object id instance
- Specified by:
newObjectId
in interfaceExecutionContext
- Parameters:
pcClass
- Class of the persistable object to create the identity forkey
- 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 interfaceExecutionContext
- 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(DNStateManager sm)
Method to clear an object from the list of dirty objects.- Specified by:
clearDirty
in interfaceExecutionContext
- Parameters:
sm
- StateManager
-
clearDirty
public void clearDirty()
Method to clear all objects marked as dirty (whether directly or indirectly).- Specified by:
clearDirty
in interfaceExecutionContext
-
markDirty
public void markDirty(DNStateManager sm, boolean directUpdate)
Method to mark an object (StateManager) as dirty.- Specified by:
markDirty
in interfaceExecutionContext
- Parameters:
sm
- StateManagerdirectUpdate
- 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 interfaceExecutionContext
- Returns:
- Whether to manage relationships at flush/commit.
-
getRelationshipManager
public RelationshipManager getRelationshipManager(DNStateManager sm)
Method to return the RelationshipManager for StateManager. If we are currently managing relations and StateManager has no RelationshipManager allocated then one is created.- Specified by:
getRelationshipManager
in interfaceExecutionContext
- Parameters:
sm
- StateManager- Returns:
- The RelationshipManager
-
isManagingRelations
public boolean isManagingRelations()
Returns whether this context is currently performing the manage relationships task.- Specified by:
isManagingRelations
in interfaceExecutionContext
- Returns:
- Whether in the process of managing relations
-
getObjectsToBeFlushed
public List<DNStateManager> getObjectsToBeFlushed()
Convenience method to inspect the list of objects with outstanding changes to flush.- Specified by:
getObjectsToBeFlushed
in interfaceExecutionContext
- Returns:
- StateManagers for the objects to be flushed.
-
isFlushing
public boolean isFlushing()
Returns whether the context is in the process of flushing.- Specified by:
isFlushing
in interfaceExecutionContext
- Returns:
- true if the context 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 interfaceExecutionContext
-
flushInternal
public void flushInternal(boolean flushToDatastore)
This method flushes all dirty, new, and deleted instances to the datastore.- Specified by:
flushInternal
in interfaceExecutionContext
- 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
-
getOperationQueue
public OperationQueue getOperationQueue()
Description copied from interface:ExecutionContext
Accessor for the operation queue. The queue can be null if there are no operations queued (txn not active, not optimistic, no ops arrived yet).- Specified by:
getOperationQueue
in interfaceExecutionContext
- Returns:
- The operation queue (typically for collections/maps)
-
addOperationToQueue
public void addOperationToQueue(Operation oper)
Description copied from interface:ExecutionContext
Method to add an operation to the queue.- Specified by:
addOperationToQueue
in interfaceExecutionContext
- Parameters:
oper
- The operation to add
-
flushOperationsForBackingStore
public void flushOperationsForBackingStore(Store backingStore, DNStateManager sm)
Description copied from interface:ExecutionContext
Method to flush all queued operations for the specified backing store (if any).- Specified by:
flushOperationsForBackingStore
in interfaceExecutionContext
- Parameters:
backingStore
- The backing storesm
- StateManager
-
operationQueueIsActive
public boolean operationQueueIsActive()
Description copied from interface:ExecutionContext
Accessor for whether the operation queue is currently active. Will return false if not delaying flush, or not in a transaction, or flushing.- Specified by:
operationQueueIsActive
in interfaceExecutionContext
- Returns:
- Whether the operation queue is active for adding operations
-
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 interfaceExecutionContext
- Parameters:
id
- The identity- Returns:
- Whether it is modified/new/deleted in this transaction
-
markFieldsForUpdateInLevel2Cache
public void markFieldsForUpdateInLevel2Cache(Object id, boolean[] fields)
Description copied from interface:ExecutionContext
Method to mark the object with specifed id to have the supplied fields updated in the L2 cache at commit.- Specified by:
markFieldsForUpdateInLevel2Cache
in interfaceExecutionContext
- Parameters:
id
- Id of the objectfields
- The fields to update
-
isRunningDetachAllOnCommit
public boolean isRunningDetachAllOnCommit()
Accessor for whether this context is currently running detachAllOnCommit.- Specified by:
isRunningDetachAllOnCommit
in interfaceExecutionContext
- 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.
-
getLevel2CacheRetrieveMode
protected String getLevel2CacheRetrieveMode()
-
getLevel2CacheStoreMode
protected String getLevel2CacheStoreMode()
-
putObjectIntoLevel1Cache
public void putObjectIntoLevel1Cache(DNStateManager sm)
Convenience method to add an object to the L1 cache.- Specified by:
putObjectIntoLevel1Cache
in interfaceExecutionContext
- Parameters:
sm
- StateManager
-
putObjectIntoLevel2Cache
public void putObjectIntoLevel2Cache(DNStateManager sm, boolean updateIfPresent)
Description copied from interface:ExecutionContext
Method to add/update the managed object into the L2 cache as long as it isn't modified in the current transaction.- Specified by:
putObjectIntoLevel2Cache
in interfaceExecutionContext
- Parameters:
sm
- StateManager for the objectupdateIfPresent
- Whether to update it in the L2 cache if already present
-
getL2CacheableObject
protected CachedPC getL2CacheableObject(DNStateManager sm, CachedPC currentCachedPC)
Convenience method to convert the object managed by StateManager into a form suitable for caching in an L2 cache.- Parameters:
sm
- StateManager for the objectcurrentCachedPC
- Current L2 cached object (if any) to use for updating- Returns:
- The cacheable form of the object
-
putObjectsIntoLevel2Cache
protected void putObjectsIntoLevel2Cache(Set<DNStateManager> sms)
Method to put the passed objects into the L2 cache. Performs the "put" in batches- Parameters:
sms
- StateManagers whose objects are to be cached
-
putObjectIntoLevel2CacheInternal
protected void putObjectIntoLevel2CacheInternal(DNStateManager sm, boolean updateIfPresent)
Convenience method to add/update an object in the L2 cache.- Parameters:
sm
- StateManager 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 interfaceExecutionContext
- 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 interfaceExecutionContext
- 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 interfaceExecutionContext
- Parameters:
id
- The identity- Returns:
- Whether an object exists in the cache(s) with this identity
-
getObjectFromCache
public Persistable getObjectFromCache(Object id)
Convenience method to access an object in the cache. Firstly looks in the L1 cache for this context, and if not found looks in the L2 cache.- Specified by:
getObjectFromCache
in interfaceExecutionContext
- Parameters:
id
- Id of the object- Returns:
- Persistable object (with connected StateManager).
-
getObjectsFromCache
public Persistable[] getObjectsFromCache(Object[] ids)
Convenience method to access objects in the cache. Firstly looks in the L1 cache for this context, and if not found looks in the L2 cache.- Specified by:
getObjectsFromCache
in interfaceExecutionContext
- Parameters:
ids
- Ids of the objects- Returns:
- Persistable objects (with connected StateManagers), or null.
-
getObjectFromLevel1Cache
protected Persistable 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 StateManager).
-
getObjectFromLevel2Cache
protected Persistable 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 StateManager).
-
getObjectFromLevel2CacheForUnique
protected Persistable getObjectFromLevel2CacheForUnique(CacheUniqueKey uniKey)
Convenience method to access the identity that corresponds to a unique key, in the Level 2 cache.- Parameters:
uniKey
- The CacheUniqueKey to use in lookups- Returns:
- Identity of the associated object
-
getObjectsFromLevel2Cache
protected Map<Object,Persistable> 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 StateManager) keyed by their id if found in the L2 cache
-
replaceObjectId
public void replaceObjectId(Persistable 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 interfaceExecutionContext
- Parameters:
pc
- The Persistable objectoldID
- the old id it was known bynewID
- 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 interfaceExecutionContext
- Parameters:
className
- Name of the class- Returns:
- Setting for serialize read
-
getExtent
public <T> Extent<T> getExtent(Class<T> 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 interfaceExecutionContext
- Type Parameters:
T
- Type of the persistable object- Parameters:
pcClass
- The class to querysubclasses
- 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.
-
getCallbackHandler
public CallbackHandler getCallbackHandler()
Retrieve the callback handler for this context. If the callback handler hasn't yet been created, this will create it.- Specified by:
getCallbackHandler
in interfaceExecutionContext
- Returns:
- the callback handler
-
closeCallbackHandler
public void closeCallbackHandler()
Close the callback handler and disconnect any registered listeners.- Specified by:
closeCallbackHandler
in interfaceExecutionContext
-
assertIsOpen
protected void assertIsOpen()
Method to assert if this context is open. Throws a NucleusUserException if the context is closed.
-
assertClassPersistable
public void assertClassPersistable(Class cls)
Method to assert if the specified class is Persistence Capable.- Specified by:
assertClassPersistable
in interfaceExecutionContext
- Parameters:
cls
- The class to check- Throws:
ClassNotPersistableException
- if class is not persistableNoPersistenceInformationException
- 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
-
hasPersistenceInformationForClass
public boolean hasPersistenceInformationForClass(Class cls)
Utility method to check if the specified class has reachable metadata or annotations.- Specified by:
hasPersistenceInformationForClass
in interfaceExecutionContext
- 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 interfaceExecutionContext
- 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 interfaceExecutionContext
- Parameters:
cls
- The classname
- Name of the group- Returns:
- The FetchGroup
- Throws:
NucleusUserException
- if the class is not persistable
-
getFetchGroupsWithName
public Set<FetchGroup> getFetchGroupsWithName(String name)
Accessor for the fetch groups for the specified name.- Specified by:
getFetchGroupsWithName
in interfaceExecutionContext
- Parameters:
name
- Name of the group- Returns:
- The FetchGroup
-
registerEmbeddedRelation
public ExecutionContext.EmbeddedOwnerRelation registerEmbeddedRelation(DNStateManager ownerSM, int ownerMemberNum, PersistableObjectType objectType, DNStateManager embSM)
Description copied from interface:ExecutionContext
Method to register an embedded relation for the specified member of the owner StateManager where the embedded StateManager is stored.- Specified by:
registerEmbeddedRelation
in interfaceExecutionContext
- Parameters:
ownerSM
- Owner StateManagerownerMemberNum
- Member number that is embeddedobjectType
- Type of object being persistedembSM
- StateManager of the embedded object- Returns:
- The EmbeddedOwnerRelation
-
deregisterEmbeddedRelation
public void deregisterEmbeddedRelation(ExecutionContext.EmbeddedOwnerRelation rel)
Description copied from interface:ExecutionContext
Method to deregister the specified embedded relation (e.g when the embedded object is disconnected).- Specified by:
deregisterEmbeddedRelation
in interfaceExecutionContext
- Parameters:
rel
- The embedded relation
-
removeEmbeddedOwnerRelation
public void removeEmbeddedOwnerRelation(DNStateManager ownerSM, int ownerFieldNum, DNStateManager embSM)
Description copied from interface:ExecutionContext
Convenience method to remove the EmbeddedOwnerRelation between the specified StateManagers.- Specified by:
removeEmbeddedOwnerRelation
in interfaceExecutionContext
- Parameters:
ownerSM
- Owner StateManagerownerFieldNum
- Field in ownerembSM
- Embedded StateManager
-
getOwnerForEmbeddedStateManager
public DNStateManager getOwnerForEmbeddedStateManager(DNStateManager embSM)
Description copied from interface:ExecutionContext
Accessor for the owner StateManager for the provided embedded StateManager.- Specified by:
getOwnerForEmbeddedStateManager
in interfaceExecutionContext
- Parameters:
embSM
- StateManager that is embedded- Returns:
- The owner StateManager that have this object embedded.
-
getOwnerInformationForEmbedded
public ExecutionContext.EmbeddedOwnerRelation getOwnerInformationForEmbedded(DNStateManager embSM)
Description copied from interface:ExecutionContext
Accessor for the owner relation for the specified embedded StateManager where it is embedded.- Specified by:
getOwnerInformationForEmbedded
in interfaceExecutionContext
- Parameters:
embSM
- StateManager that is embedded- Returns:
- The embedded relation info involving this (embedded) StateManager
-
getEmbeddedInformationForOwner
public List<ExecutionContext.EmbeddedOwnerRelation> getEmbeddedInformationForOwner(DNStateManager ownerSM)
Description copied from interface:ExecutionContext
Accessor for the relations for the specified embedded StateManager where it is embedded.- Specified by:
getEmbeddedInformationForOwner
in interfaceExecutionContext
- Parameters:
ownerSM
- StateManager that owns the embedded- Returns:
- The List of embedded relations involving this StateManager as owner
-
setStateManagerAssociatedValue
public void setStateManagerAssociatedValue(DNStateManager sm, Object key, Object value)
- Specified by:
setStateManagerAssociatedValue
in interfaceExecutionContext
-
getStateManagerAssociatedValue
public Object getStateManagerAssociatedValue(DNStateManager sm, Object key)
- Specified by:
getStateManagerAssociatedValue
in interfaceExecutionContext
-
removeStateManagerAssociatedValue
public void removeStateManagerAssociatedValue(DNStateManager sm, Object key)
- Specified by:
removeStateManagerAssociatedValue
in interfaceExecutionContext
-
containsStateManagerAssociatedValue
public boolean containsStateManagerAssociatedValue(DNStateManager sm, Object key)
- Specified by:
containsStateManagerAssociatedValue
in interfaceExecutionContext
-
-