public class ExecutionContextImpl extends Object implements ExecutionContext, TransactionEventListener
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).
An ExecutionContext has a single transaction (the "current" transaction). The transaction can be "active" (if begin() has been called on it) or "inactive".
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.
You may note that we have various fields here storing ObjectProvider-related information such as which ObjectProvider is embedded into which ObjectProvider etc, or the managed relations for an ObjectProvider. These are stored here to avoid adding a reference to the storage of each and every ObjectProvider, since we could potentially have a very large number of ObjectProviders (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 the ObjectProvider.
This class is NOT thread-safe. Use ExecutionContextThreadedImpl if you want to *attempt* to have multithreaded PM/EMs.
ExecutionContext.EmbeddedOwnerRelation, ExecutionContext.LifecycleListener
Modifier and Type | Field and Description |
---|---|
protected Level1Cache |
cache
Level 1 Cache, essentially a Map of ObjectProvider keyed by the id.
|
protected Map<ObjectProvider,Map<?,?>> |
opAssociatedValuesMapByOP
Map of associated values for the ObjectProvider.
|
OPTION_JTA_AUTOJOIN, OPTION_PASSWORD, OPTION_USERNAME
Constructor and Description |
---|
ExecutionContextImpl(PersistenceNucleusContext ctx,
Object owner,
Map<String,Object> options)
Constructor.
|
Modifier and Type | Method and 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 |
addObjectProviderToCache(ObjectProvider op)
Method to add the object managed by the specified ObjectProvider to the (L1) cache.
|
void |
addOperationToQueue(Operation oper)
Method to add an operation to the queue.
|
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 context 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.
|
<T> T |
attachObjectCopy(ObjectProvider ownerOP,
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(ObjectProvider op)
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 |
containsObjectProviderAssociatedValue(ObjectProvider op,
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(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.
|
<T> T |
findObject(Class<T> cls,
Object key)
Accessor for an object of the specified type with the provided id "key".
|
Object |
findObject(Object id,
boolean validate)
Shortcut to calling "findObject(id, validate, validate, null)".
|
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.
|
<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.
|
ObjectProvider |
findObjectProvider(Object pc)
Method to return the ObjectProvider for an object (if managed).
|
ObjectProvider |
findObjectProvider(Object pc,
boolean persist)
Find the ObjectProvider for the specified object, persisting it if required.
|
ObjectProvider |
findObjectProviderForEmbedded(Object value,
ObjectProvider owner,
AbstractMemberMetaData mmd)
Method to find the ObjectProvider for the passed embedded persistable object.
|
ObjectProvider |
findObjectProviderOfOwnerForAttachingObject(Object pc) |
<T> List<T> |
findObjects(Class<T> cls,
List keys)
Accessor for objects of the specified type, with the provided id "key"s.
|
Object[] |
findObjectsById(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.
|
void |
flushOperationsForBackingStore(Store backingStore,
ObjectProvider op)
Method to flush all queued operations for the specified backing store (if any).
|
Object |
getAttachDetachReferencedObject(ObjectProvider op)
Access a referenced object for this ObjectProvider 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.
|
List<ExecutionContext.EmbeddedOwnerRelation> |
getEmbeddedInformationForOwner(ObjectProvider ownerOP)
Accessor for the relations for the specified embedded ObjectProvider 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 FetchPlan
|
FlushMode |
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(ObjectProvider op,
CachedPC currentCachedPC)
Convenience method to convert the object managed by the ObjectProvider 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 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 the usage is multi-threaded.
|
PersistenceNucleusContext |
getNucleusContext()
Accessor for the context in which this execution context 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.
|
protected Object |
getObjectFromLevel2Cache(Object id)
Convenience method to access an object in the Level 2 cache.
|
protected Object |
getObjectFromLevel2CacheForUnique(CacheUniqueKey uniKey)
Convenience method to access the identity that corresponds to a unique key, in the Level 2 cache.
|
Object |
getObjectProviderAssociatedValue(ObjectProvider op,
Object key) |
Object[] |
getObjectsFromCache(Object[] ids)
Convenience method to access objects in the 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.
|
OperationQueue |
getOperationQueue()
Accessor for the operation queue.
|
Object |
getOwner()
Accessor for the owner of this ExecutionContext.
|
List<ExecutionContext.EmbeddedOwnerRelation> |
getOwnerInformationForEmbedded(ObjectProvider embOP)
Accessor for the relations for the specified embedded ObjectProvider where it is embedded.
|
ObjectProvider[] |
getOwnersForEmbeddedObjectProvider(ObjectProvider embOP)
Accessor for the owning ObjectProviders for the managed object when stored embedded.
|
Map<String,Object> |
getProperties()
Accessor for the defined properties.
|
Object |
getProperty(String name)
Accessor for a property.
|
RelationshipManager |
getRelationshipManager(ObjectProvider op)
Method to return the RelationshipManager for the 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.
|
String |
getStringProperty(String name)
Accessor for a String property value.
|
Set<String> |
getSupportedProperties()
Accessor for the supported property names.
|
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.
|
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 in the process of 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 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.
|
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,
ObjectProvider ownerOP,
int ownerFieldNum,
int objectType)
Method to make an object persistent which should be called from internal calls only.
|
<T> T |
persistObjectInternal(T 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.
|
ExecutionContext.EmbeddedOwnerRelation |
registerEmbeddedRelation(ObjectProvider ownerOP,
int ownerFieldNum,
ObjectProvider embOP)
Method to register an embedded relation for the specified memberf of the owner ObjectProvider
where the embedded ObjectProvider 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(ObjectProvider ownerOP,
int ownerFieldNum,
ObjectProvider embOP)
Convenience method to remove the EmbeddedOwnerRelation between the specified ObjectProviders.
|
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 |
removeObjectProviderAssociatedValue(ObjectProvider op,
Object key) |
void |
removeObjectProviderFromCache(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 |
setAttachDetachReferencedObject(ObjectProvider op,
Object obj)
Register a referenced object against this ObjectProvider 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 |
setObjectProviderAssociatedValue(ObjectProvider op,
Object key,
Object value) |
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 |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getApiAdapter, getLock, getMetaDataManager, getStoreManager, getTypeManager, persistObjectInternal
protected Level1Cache cache
protected Map<ObjectProvider,Map<?,?>> opAssociatedValuesMapByOP
public ExecutionContextImpl(PersistenceNucleusContext ctx, Object owner, Map<String,Object> options)
ctx
- NucleusContextowner
- Owning object (for bytecode enhancement contract, PersistenceManager)options
- Any options affecting startupNucleusUserException
- if an error occurs allocating the necessary requested componentspublic void initialise(Object owner, Map<String,Object> options)
initialise
in interface ExecutionContext
public void close()
close
in interface ExecutionContext
public void registerExecutionContextListener(ExecutionContextListener listener)
ExecutionContext
registerExecutionContextListener
in interface ExecutionContext
listener
- The listenerpublic void deregisterExecutionContextListener(ExecutionContextListener listener)
ExecutionContext
deregisterExecutionContextListener
in interface ExecutionContext
listener
- The listenerprotected void setLevel2Cache(boolean flag)
flag
- Whether to enable/disable itpublic boolean isClosed()
isClosed
in interface ExecutionContext
protected org.datanucleus.ExecutionContextImpl.ThreadContextInfo acquireThreadContextInfo()
You must call releaseThreadContextInfo()
when you don't need it anymore,
since we use reference counting. Use a try...finally-block for this purpose.
getThreadContextInfo()
protected org.datanucleus.ExecutionContextImpl.ThreadContextInfo getThreadContextInfo()
acquireThreadContextInfo()
protected void releaseThreadContextInfo()
acquireThreadContextInfo()
.acquireThreadContextInfo()
public void transactionStarted()
TransactionEventListener
transactionStarted
in interface TransactionEventListener
public void transactionPreFlush()
TransactionEventListener
transactionPreFlush
in interface TransactionEventListener
public void transactionFlushed()
TransactionEventListener
transactionFlushed
in interface TransactionEventListener
public void transactionPreCommit()
TransactionEventListener
transactionPreCommit
in interface TransactionEventListener
public void transactionCommitted()
TransactionEventListener
transactionCommitted
in interface TransactionEventListener
public void transactionPreRollBack()
TransactionEventListener
transactionPreRollBack
in interface TransactionEventListener
public void transactionRolledBack()
TransactionEventListener
transactionRolledBack
in interface TransactionEventListener
public void transactionEnded()
TransactionEventListener
transactionEnded
in interface TransactionEventListener
public void transactionSetSavepoint(String name)
TransactionEventListener
transactionSetSavepoint
in interface TransactionEventListener
name
- Name of the savepointpublic void transactionReleaseSavepoint(String name)
TransactionEventListener
transactionReleaseSavepoint
in interface TransactionEventListener
name
- Name of the savepointpublic void transactionRollbackToSavepoint(String name)
TransactionEventListener
transactionRollbackToSavepoint
in interface TransactionEventListener
name
- Name of the savepointpublic ManagerStatistics getStatistics()
ExecutionContext
getStatistics
in interface ExecutionContext
protected void initialiseLevel1Cache()
NucleusUserException
- if an error occurs setting up the L1 cachepublic Level1Cache getLevel1Cache()
getLevel1Cache
in interface ExecutionContext
public ClassLoaderResolver getClassLoaderResolver()
ExecutionContext
getClassLoaderResolver
in interface ExecutionContext
public LockManager getLockManager()
ExecutionContext
getLockManager
in interface ExecutionContext
public FetchPlan getFetchPlan()
ExecutionContext
getFetchPlan
in interface ExecutionContext
public PersistenceNucleusContext getNucleusContext()
ExecutionContext
getNucleusContext
in interface ExecutionContext
public Object getOwner()
getOwner
in interface ExecutionContextReference
getOwner
in interface ExecutionContext
public void setProperties(Map props)
ExecutionContext
setProperties
in interface ExecutionContext
props
- The propertiespublic void setProperty(String name, Object value)
ExecutionContext
setProperty
in interface ExecutionContext
name
- Name of the propertyvalue
- Value to setpublic Map<String,Object> getProperties()
ExecutionContext
getProperties
in interface ExecutionContext
public Boolean getBooleanProperty(String name)
ExecutionContext
getBooleanProperty
in interface ExecutionContext
name
- Name of the propertypublic Integer getIntProperty(String name)
ExecutionContext
getIntProperty
in interface ExecutionContext
name
- Name of the propertypublic String getStringProperty(String name)
ExecutionContext
getStringProperty
in interface ExecutionContext
name
- Name of the propertypublic Object getProperty(String name)
ExecutionContext
getProperty
in interface ExecutionContext
name
- Name of the propertypublic Set<String> getSupportedProperties()
ExecutionContext
getSupportedProperties
in interface ExecutionContext
public boolean getMultithreaded()
getMultithreaded
in interface ExecutionContext
public FlushMode getFlushMode()
ExecutionContext
getFlushMode
in interface ExecutionContext
public boolean isDelayDatastoreOperationsEnabled()
isDelayDatastoreOperationsEnabled
in interface ExecutionContext
public boolean isInserting(Object pc)
isInserting
in interface ExecutionContext
pc
- the object to verify the statuspublic Transaction getTransaction()
getTransaction
in interface ExecutionContext
public void enlistInTransaction(ObjectProvider op)
enlistInTransaction
in interface ExecutionContext
op
- The ObjectProviderpublic void evictFromTransaction(ObjectProvider op)
evictFromTransaction
in interface ExecutionContext
op
- The ObjectProviderpublic boolean isEnlistedInTransaction(Object id)
isEnlistedInTransaction
in interface ExecutionContext
id
- Identity for the objectpublic Object getAttachedObjectForId(Object id)
getAttachedObjectForId
in interface ExecutionContext
id
- The idpublic void addObjectProviderToCache(ObjectProvider op)
addObjectProviderToCache
in interface ExecutionContext
op
- The ObjectProviderpublic void removeObjectProviderFromCache(ObjectProvider op)
removeObjectProviderFromCache
in interface ExecutionContext
op
- The ObjectProviderpublic ObjectProvider findObjectProvider(Object pc)
findObjectProvider
in interface ExecutionContext
pc
- The object we are checkingNucleusUserException
- if the persistable object is managed by a different ExecutionContextpublic ObjectProvider findObjectProvider(Object pc, boolean persist)
findObjectProvider
in interface ExecutionContext
pc
- The persistable objectpersist
- persists the object if not yet persisted.public ObjectProvider findObjectProviderForEmbedded(Object value, ObjectProvider owner, AbstractMemberMetaData mmd)
ExecutionContext
findObjectProviderForEmbedded
in interface ExecutionContext
value
- The embedded objectowner
- The owner ObjectProvider (if known).mmd
- Metadata for the field of the ownerpublic ObjectProvider findObjectProviderOfOwnerForAttachingObject(Object pc)
findObjectProviderOfOwnerForAttachingObject
in interface ExecutionContext
public void processNontransactionalUpdate()
processNontransactionalUpdate
in interface ExecutionContext
protected void processNontransactionalAtomicChanges()
public void evictObject(Object obj)
evictObject
in interface ExecutionContext
obj
- The objectNucleusException
- if an error occurs evicting the objectpublic void evictObjects(Class cls, boolean subclasses)
evictObjects
in interface ExecutionContext
cls
- Type of persistable objectsubclasses
- Whether to include subclassespublic void evictAllObjects()
evictAllObjects
in interface ExecutionContext
public void refreshObject(Object obj)
refreshObject
in interface ExecutionContext
obj
- The Objectpublic void refreshAllObjects()
refreshAllObjects
in interface ExecutionContext
NucleusUserException
- thrown if instances could not be refreshed.public void retrieveObject(Object obj, boolean fgOnly)
retrieveObject
in interface ExecutionContext
obj
- The objectfgOnly
- Whether to retrieve the current fetch group fields onlypublic Object persistObject(Object obj, boolean merging)
persistObject
in interface ExecutionContext
obj
- The objectmerging
- Whether this object (and dependents) is being mergedNucleusUserException
- if the object is managed by a different managerpublic Object[] persistObjects(Object... objs)
persistObjects
in interface ExecutionContext
objs
- The objects to persistNucleusUserException
- Thrown if an error occurs during the persist process.
Any exception could have several nested exceptions for each failed object persistpublic <T> T persistObjectInternal(T obj, FieldValues preInsertChanges, ObjectProvider ownerOP, int ownerFieldNum, int objectType)
persistObjectInternal
in interface ExecutionContext
T
- Type of the persistable objectobj
- The objectpreInsertChanges
- Any changes to make before insertingownerOP
- ObjectProvider of the owner when embeddedownerFieldNum
- 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)NucleusUserException
- if the object is managed by a different managerpublic <T> T persistObjectInternal(T pc, ObjectProvider ownerOP, int ownerFieldNum, int objectType)
persistObjectInternal
in interface ExecutionContext
T
- Type of the persistable objectpc
- The objectownerOP
- ObjectProvider of the owner when embeddedownerFieldNum
- 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)public void deleteObjects(Object... objs)
deleteObjects
in interface ExecutionContext
objs
- The objectsNucleusUserException
- Thrown if an error occurs during the deletion process. Any exception could have several nested exceptions for each failed object deletionpublic void deleteObject(Object obj)
deleteObject
in interface ExecutionContext
obj
- The objectpublic void deleteObjectInternal(Object obj)
deleteObjectInternal
in interface ExecutionContext
obj
- Object to deletepublic void makeObjectTransient(Object obj, FetchPlanState state)
makeObjectTransient
in interface ExecutionContext
obj
- The objectstate
- Object containing the state of the fetch plan process (if any)NucleusException
- When an error occurs in making the object transientpublic void makeObjectTransactional(Object obj)
makeObjectTransactional
in interface ExecutionContext
obj
- The objectNucleusException
- Thrown when an error occurspublic void makeObjectNontransactional(Object obj)
makeObjectNontransactional
in interface ExecutionContext
obj
- The objectpublic void attachObject(ObjectProvider ownerOP, Object pc, boolean sco)
attachObject
in interface ExecutionContext
ownerOP
- ObjectProvider 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)public <T> T attachObjectCopy(ObjectProvider ownerOP, T pc, boolean sco)
attachObjectCopy
in interface ExecutionContext
T
- Type of the persistable objectownerOP
- ObjectProvider of the owner object that has this in a field that causes this attachpc
- The objectsco
- Whether it has no identity (second-class object)public void detachObject(FetchPlanState state, Object obj)
detachObject
in interface ExecutionContext
state
- State for the detachment processobj
- The objectpublic void detachObjects(FetchPlanState state, Object... pcs)
ExecutionContext
detachObjects
in interface ExecutionContext
state
- State for the detachment process.pcs
- The object(s) to detachpublic <T> T detachObjectCopy(FetchPlanState state, T pc)
detachObjectCopy
in interface ExecutionContext
T
- Type of the persistable objectstate
- State for the detachment processpc
- The objectpublic void detachAll()
detachAll
in interface ExecutionContext
public Object getAttachDetachReferencedObject(ObjectProvider op)
ExecutionContext
getAttachDetachReferencedObject
in interface ExecutionContext
op
- Object providerpublic void setAttachDetachReferencedObject(ObjectProvider op, Object obj)
ExecutionContext
setAttachDetachReferencedObject
in interface ExecutionContext
op
- The ObjectProviderobj
- The referenced object (or null to clear out any reference)public <T> T newInstance(Class<T> cls)
newInstance
in interface ExecutionContext
T
- Type of the persistable objectcls
- The class of the interface or abstract class, or concrete class defined in MetaDatapublic boolean exists(Object obj)
exists
in interface ExecutionContext
obj
- The (persistable) objectpublic Set getManagedObjects()
getManagedObjects
in interface ExecutionContext
public Set getManagedObjects(Class[] classes)
getManagedObjects
in interface ExecutionContext
classes
- Classes that we want the enlisted objects forpublic Set getManagedObjects(String[] states)
getManagedObjects
in interface ExecutionContext
states
- States that we want the enlisted objects forpublic Set getManagedObjects(String[] states, Class[] classes)
getManagedObjects
in interface ExecutionContext
states
- States that we want the enlisted objects forclasses
- Classes that we want the enlisted objects forpublic <T> T findObject(Class<T> cls, Object key)
findObject
in interface ExecutionContext
T
- Type of the persistablecls
- Class of the persistablekey
- Value of the key field for SingleFieldIdentity, or the string value of the key otherwisepublic <T> List<T> findObjects(Class<T> cls, List keys)
ExecutionContext
findObjects
in interface ExecutionContext
T
- Type of the persistablecls
- Class of the persistablekeys
- Values of the key field for SingleFieldIdentity, or the string value of the keys otherwisepublic <T> T findObjectByUnique(Class<T> cls, String[] memberNames, Object[] memberValues)
ExecutionContext
ec.findObjectByUnique(cls).for("field1", val1).for("field2", val2).find();
findObjectByUnique
in interface ExecutionContext
T
- Type of the persistablecls
- Class of the persistablememberNames
- Name(s) of the field(s) forming the unique keymemberValues
- Value(s) of the field(s) forming the unique keypublic Object findObject(Object id, boolean validate)
ExecutionContext
dnCopyKeyFieldsFromObjectId
findObject
in interface ExecutionContextReference
findObject
in interface ExecutionContext
id
- The id of the objectvalidate
- Whether to validate the idpublic Object findObject(Object id, FieldValues fv, Class cls, boolean ignoreCache, boolean checkInheritance)
findObject
in interface ExecutionContext
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 objectpublic Object[] findObjectsById(Object[] identities, boolean validate)
findObjectsById
in interface ExecutionContext
identities
- Ids of the object(s).validate
- Whether to validate the object stateNucleusObjectNotFoundException
- if an object doesn't exist in the datastorepublic Object findObject(Object id, boolean validate, boolean checkInheritance, String objectClassName)
findObject
in interface ExecutionContext
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)NucleusObjectNotFoundException
- if the object doesn't exist in the datastorepublic Object newObjectId(Class pcClass, Object key)
newObjectId
in interface ExecutionContext
pcClass
- Class of the persistable object to create the identity forkey
- Value of the key for SingleFieldIdentity (or the toString value)public Object newObjectId(String className, Object pc)
newObjectId
in interface ExecutionContext
className
- Name of the class of the object.pc
- The persistable object. Used for application-identitypublic void clearDirty(ObjectProvider op)
clearDirty
in interface ExecutionContext
op
- The ObjectProviderpublic void clearDirty()
clearDirty
in interface ExecutionContext
public void markDirty(ObjectProvider op, boolean directUpdate)
markDirty
in interface ExecutionContext
op
- ObjectProviderdirectUpdate
- Whether the object has had a direct update made on it (if known)public boolean getManageRelations()
getManageRelations
in interface ExecutionContext
public RelationshipManager getRelationshipManager(ObjectProvider op)
getRelationshipManager
in interface ExecutionContext
op
- ObjectProviderpublic boolean isManagingRelations()
isManagingRelations
in interface ExecutionContext
public List<ObjectProvider> getObjectsToBeFlushed()
getObjectsToBeFlushed
in interface ExecutionContext
public boolean isFlushing()
isFlushing
in interface ExecutionContext
public void flush()
flush
in interface ExecutionContext
public void flushInternal(boolean flushToDatastore)
flushInternal
in interface ExecutionContext
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 datastoreNucleusOptimisticException
- when optimistic locking error(s) occurpublic OperationQueue getOperationQueue()
ExecutionContext
getOperationQueue
in interface ExecutionContext
public void addOperationToQueue(Operation oper)
ExecutionContext
addOperationToQueue
in interface ExecutionContext
oper
- The operation to addpublic void flushOperationsForBackingStore(Store backingStore, ObjectProvider op)
ExecutionContext
flushOperationsForBackingStore
in interface ExecutionContext
backingStore
- The backing storeop
- ObjectProviderpublic boolean operationQueueIsActive()
ExecutionContext
operationQueueIsActive
in interface ExecutionContext
public void postBegin()
public void preCommit()
public boolean isObjectModifiedInTransaction(Object id)
isObjectModifiedInTransaction
in interface ExecutionContext
id
- The identitypublic void markFieldsForUpdateInLevel2Cache(Object id, boolean[] fields)
ExecutionContext
markFieldsForUpdateInLevel2Cache
in interface ExecutionContext
id
- Id of the objectfields
- The fields to updatepublic boolean isRunningDetachAllOnCommit()
isRunningDetachAllOnCommit
in interface ExecutionContext
public void postCommit()
public void preRollback()
public void postRollback()
protected String getLevel2CacheRetrieveMode()
protected String getLevel2CacheStoreMode()
public void putObjectIntoLevel1Cache(ObjectProvider op)
putObjectIntoLevel1Cache
in interface ExecutionContext
op
- The ObjectProviderprotected void putObjectIntoLevel2Cache(ObjectProvider op, boolean updateIfPresent)
op
- ObjectProvider for the objectupdateIfPresent
- Whether to update it in the L2 cache if already presentprotected CachedPC getL2CacheableObject(ObjectProvider op, CachedPC currentCachedPC)
op
- ObjectProvider for the objectcurrentCachedPC
- Current L2 cached object (if any) to use for updatingprotected void putObjectsIntoLevel2Cache(Set<ObjectProvider> ops)
ops
- The ObjectProviders whose objects are to be cachedprotected void putObjectIntoLevel2CacheInternal(ObjectProvider op, boolean updateIfPresent)
op
- ObjectProvider of the object to add.updateIfPresent
- Whether to update the L2 cache if it is presentpublic void removeObjectFromLevel1Cache(Object id)
removeObjectFromLevel1Cache
in interface ExecutionContext
id
- The Persistable object idpublic void removeObjectFromLevel2Cache(Object id)
removeObjectFromLevel2Cache
in interface ExecutionContext
id
- Identity of the objectpublic boolean hasIdentityInCache(Object id)
hasIdentityInCache
in interface ExecutionContext
id
- The identitypublic Object getObjectFromCache(Object id)
getObjectFromCache
in interface ExecutionContext
id
- Id of the objectpublic Object[] getObjectsFromCache(Object[] ids)
getObjectsFromCache
in interface ExecutionContext
ids
- Ids of the objectspublic Object getObjectFromLevel1Cache(Object id)
id
- Id of the objectprotected Object getObjectFromLevel2Cache(Object id)
id
- Id of the objectprotected Object getObjectFromLevel2CacheForUnique(CacheUniqueKey uniKey)
uniKey
- The CacheUniqueKey to use in lookupsprotected Map getObjectsFromLevel2Cache(Collection ids)
ids
- Collection of ids to retrievepublic void replaceObjectId(Object pc, Object oldID, Object newID)
replaceObjectId
in interface ExecutionContext
pc
- The Persistable objectoldID
- the old id it was known bynewID
- the new idpublic boolean getSerializeReadForClass(String className)
getSerializeReadForClass
in interface ExecutionContext
className
- Name of the classpublic <T> Extent<T> getExtent(Class<T> pcClass, boolean subclasses)
getExtent
in interface ExecutionContext
T
- Type of the persistable objectpcClass
- The class to querysubclasses
- Whether to include subclasses in the query.public CallbackHandler getCallbackHandler()
getCallbackHandler
in interface ExecutionContext
public void closeCallbackHandler()
closeCallbackHandler
in interface ExecutionContext
protected void assertIsOpen()
public void assertClassPersistable(Class cls)
assertClassPersistable
in interface ExecutionContext
cls
- The class to checkClassNotPersistableException
- if class is not persistableNoPersistenceInformationException
- if no metadata/annotations are found for classprotected void assertDetachable(Object object)
object
- The object to checkprotected void assertNotDetached(Object object)
object
- The object to checkprotected void assertActiveTransaction()
protected void assertHasImplementationCreator()
NucleusUserException
- if an ImplementationCreator instance does not existpublic boolean hasPersistenceInformationForClass(Class cls)
hasPersistenceInformationForClass
in interface ExecutionContext
cls
- The class to checkprotected FetchGroupManager getFetchGroupManager()
public void addInternalFetchGroup(FetchGroup grp)
addInternalFetchGroup
in interface ExecutionContext
grp
- The groupprotected void removeInternalFetchGroup(FetchGroup grp)
grp
- The grouppublic FetchGroup getInternalFetchGroup(Class cls, String name)
getInternalFetchGroup
in interface ExecutionContext
cls
- The classname
- Name of the groupNucleusUserException
- if the class is not persistablepublic Set<FetchGroup> getFetchGroupsWithName(String name)
getFetchGroupsWithName
in interface ExecutionContext
name
- Name of the grouppublic ExecutionContext.EmbeddedOwnerRelation registerEmbeddedRelation(ObjectProvider ownerOP, int ownerFieldNum, ObjectProvider embOP)
ExecutionContext
registerEmbeddedRelation
in interface ExecutionContext
ownerOP
- Owner ObjectProviderownerFieldNum
- Member number that is embeddedembOP
- ObjectProvider of the embedded objectpublic void deregisterEmbeddedRelation(ExecutionContext.EmbeddedOwnerRelation rel)
ExecutionContext
deregisterEmbeddedRelation
in interface ExecutionContext
rel
- The embedded relationpublic void removeEmbeddedOwnerRelation(ObjectProvider ownerOP, int ownerFieldNum, ObjectProvider embOP)
ExecutionContext
removeEmbeddedOwnerRelation
in interface ExecutionContext
ownerOP
- Owner ObjectProviderownerFieldNum
- Field in ownerembOP
- Embedded ObjectProviderpublic ObjectProvider[] getOwnersForEmbeddedObjectProvider(ObjectProvider embOP)
getOwnersForEmbeddedObjectProvider
in interface ExecutionContext
embOP
- The ObjectProvider that is embedded that we are looking for the owners forpublic List<ExecutionContext.EmbeddedOwnerRelation> getOwnerInformationForEmbedded(ObjectProvider embOP)
ExecutionContext
getOwnerInformationForEmbedded
in interface ExecutionContext
embOP
- The ObjectProvider that is embeddedpublic List<ExecutionContext.EmbeddedOwnerRelation> getEmbeddedInformationForOwner(ObjectProvider ownerOP)
ExecutionContext
getEmbeddedInformationForOwner
in interface ExecutionContext
ownerOP
- The ObjectProvider that owns the embeddedpublic void setObjectProviderAssociatedValue(ObjectProvider op, Object key, Object value)
setObjectProviderAssociatedValue
in interface ExecutionContext
public Object getObjectProviderAssociatedValue(ObjectProvider op, Object key)
getObjectProviderAssociatedValue
in interface ExecutionContext
public void removeObjectProviderAssociatedValue(ObjectProvider op, Object key)
removeObjectProviderAssociatedValue
in interface ExecutionContext
public boolean containsObjectProviderAssociatedValue(ObjectProvider op, Object key)
containsObjectProviderAssociatedValue
in interface ExecutionContext
Copyright © 2019. All rights reserved.