Class CommitManager
- java.lang.Object
-
- org.eclipse.persistence.internal.sessions.CommitManager
-
public class CommitManager extends Object
This class maintains a commit stack and resolves circular references.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
commitDepth
Counter used to keep track of commit depth for non-UOW writes.protected List<Class>
commitOrder
Order based on mapping foreign key constraints on how to insert objects by class.protected Map<Object,Integer>
commitState
This tracks the commit state for the objects, PENDING, PRE, POST, COMPLETE.protected static Integer
COMPLETE
The commit is complete for the object.protected Map<DatabaseMapping,List<Object[]>>
dataModifications
Map of modification events used to defer insertion into m-m, dc, join tables.protected Map<DatabaseTable,List<Object[]>>
deferredCalls
Map of deferred calls groups by their table.protected static Integer
IGNORE
This object should be ignored.protected boolean
isActive
The commit manager is active while writing a set of objects (UOW), it is not active when writing a single object (DB session).protected List
objectsToDelete
List of orphaned objects pending deletion.protected static Integer
POST
The commit is in progress, and the row has been written.protected static Integer
PRE
The commit is in progress, but the row has not been written.protected AbstractSession
session
protected Map
shallowCommits
Set of objects that had partial row written to resolve constraints.
-
Constructor Summary
Constructors Constructor Description CommitManager(AbstractSession session)
Create the commit manager on the session.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDataModificationEvent(DatabaseMapping mapping, Object[] event)
Add the data query to be performed at the end of the commit.void
addDeferredCall(DatabaseTable table, DatasourceCall call, DatabaseQueryMechanism mechanism)
Add the data query to be performed at the end of the commit.void
addObjectToDelete(Object objectToDelete)
Deletion are cached until the end.protected void
commitAllObjectsForClassWithChangeSet(UnitOfWorkChangeSet uowChangeSet, Class theClass)
Commit all of the objects of the class type in the change set.void
commitAllObjectsWithChangeSet(UnitOfWorkChangeSet uowChangeSet)
Commit all of the objects as a single transaction.protected void
commitChangedObjectsForClassWithChangeSet(UnitOfWorkChangeSet uowChangeSet, Class theClass)
Commit changed of the objects of the class type in the change set.protected void
commitNewObjectsForClassWithChangeSet(UnitOfWorkChangeSet uowChangeSet, Class theClass)
Commit all of the objects of the class type in the change set.void
deleteAllObjects(Class theClass, List objects, AbstractSession session)
Delete all of the objects with the matching class.void
deleteAllObjects(List objects)
delete all of the objects as a single transaction.List<Class>
getCommitOrder()
Return the order in which objects should be committed to the database.protected Map<Object,Integer>
getCommitState()
Return the map of states of the objects being committed.protected Map<DatabaseMapping,List<Object[]>>
getDataModifications()
Used to store data queries to be performed at the end of the commit.protected Map<DatabaseTable,List<Object[]>>
getDeferredCalls()
Used to store calls to be performed at the end of the commit.List
getObjectsToDelete()
Deletion are cached until the end.protected AbstractSession
getSession()
Return the session that this is managing commits for.protected Map
getShallowCommits()
Return any objects that have been shallow committed during this commit process.protected boolean
hasDataModifications()
protected boolean
hasDeferredCalls()
protected boolean
hasObjectsToDelete()
void
initializeCommitOrder()
Reset the commit order from the session's descriptors.boolean
isActive()
Return if the commit manager is active.boolean
isCommitCompleted(Object object)
Return if the object has been committed.boolean
isCommitCompletedInPostOrIgnore(Object object)
Return if the object has been committed.boolean
isCommitInPostModify(Object object)
Return if the object is being in progress of being post modify commit.boolean
isCommitInPreModify(Object objectOrChangeSet)
Return if the object is being in progress of being pre modify commit.boolean
isProcessedCommit(Object object)
Return if the object has been processed.boolean
isShallowCommitted(Object object)
Return if the object is shallow committed.void
markCommitCompleted(Object object)
Mark the commit of the object as being fully completed.void
markIgnoreCommit(Object object)
void
markPostModifyCommitInProgress(Object object)
Add an object as being in progress of being committed.void
markPreModifyCommitInProgress(Object object)
Add an object as being in progress of being committed.void
markShallowCommit(Object object)
Mark the object as shallow committed.void
reinitialize()
Reset the commits.void
setCommitOrder(List commitOrder)
Set the order in which objects should be committed to the database.protected void
setDataModifications(Map<DatabaseMapping,List<Object[]>> dataModifications)
Used to store data queries to be performed at the end of the commit.void
setIsActive(boolean isActive)
Set if the commit manager is active.protected void
setObjectsToDelete(List objectsToDelete)
Deletion are cached until the end.protected void
setSession(AbstractSession session)
Set the session that this is managing commits for.protected void
setShallowCommits(Map shallowCommits)
Set any objects that have been shallow committed during this commit process.String
toString()
Print the in progress depth.
-
-
-
Field Detail
-
commitOrder
protected List<Class> commitOrder
Order based on mapping foreign key constraints on how to insert objects by class.
-
commitState
protected Map<Object,Integer> commitState
This tracks the commit state for the objects, PENDING, PRE, POST, COMPLETE. The key is the object and the value is the state.
-
PRE
protected static final Integer PRE
The commit is in progress, but the row has not been written.
-
POST
protected static final Integer POST
The commit is in progress, and the row has been written.
-
COMPLETE
protected static final Integer COMPLETE
The commit is complete for the object.
-
IGNORE
protected static final Integer IGNORE
This object should be ignored.
-
shallowCommits
protected Map shallowCommits
Set of objects that had partial row written to resolve constraints.
-
session
protected AbstractSession session
-
isActive
protected boolean isActive
The commit manager is active while writing a set of objects (UOW), it is not active when writing a single object (DB session).
-
dataModifications
protected Map<DatabaseMapping,List<Object[]>> dataModifications
Map of modification events used to defer insertion into m-m, dc, join tables.
-
deferredCalls
protected Map<DatabaseTable,List<Object[]>> deferredCalls
Map of deferred calls groups by their table. This is used to defer multiple table writes for batching and deadlock avoidance.
-
objectsToDelete
protected List objectsToDelete
List of orphaned objects pending deletion.
-
commitDepth
protected int commitDepth
Counter used to keep track of commit depth for non-UOW writes.
-
-
Constructor Detail
-
CommitManager
public CommitManager(AbstractSession session)
Create the commit manager on the session. It must be initialized later on after the descriptors have been added.
-
-
Method Detail
-
addDataModificationEvent
public void addDataModificationEvent(DatabaseMapping mapping, Object[] event)
Add the data query to be performed at the end of the commit. This is done to decrease dependencies and avoid deadlock.
-
addDeferredCall
public void addDeferredCall(DatabaseTable table, DatasourceCall call, DatabaseQueryMechanism mechanism)
Add the data query to be performed at the end of the commit. This is done to decrease dependencies and avoid deadlock.
-
addObjectToDelete
public void addObjectToDelete(Object objectToDelete)
Deletion are cached until the end.
-
commitAllObjectsWithChangeSet
public void commitAllObjectsWithChangeSet(UnitOfWorkChangeSet uowChangeSet) throws RuntimeException, DatabaseException, OptimisticLockException
Commit all of the objects as a single transaction. This should commit the object in the correct order to maintain referential integrity.
-
commitAllObjectsForClassWithChangeSet
protected void commitAllObjectsForClassWithChangeSet(UnitOfWorkChangeSet uowChangeSet, Class theClass)
Commit all of the objects of the class type in the change set. This allows for the order of the classes to be processed optimally.
-
commitNewObjectsForClassWithChangeSet
protected void commitNewObjectsForClassWithChangeSet(UnitOfWorkChangeSet uowChangeSet, Class theClass)
Commit all of the objects of the class type in the change set. This allows for the order of the classes to be processed optimally.
-
commitChangedObjectsForClassWithChangeSet
protected void commitChangedObjectsForClassWithChangeSet(UnitOfWorkChangeSet uowChangeSet, Class theClass)
Commit changed of the objects of the class type in the change set. This allows for the order of the classes to be processed optimally.
-
deleteAllObjects
public void deleteAllObjects(List objects) throws RuntimeException, DatabaseException, OptimisticLockException
delete all of the objects as a single transaction. This should delete the object in the correct order to maintain referential integrity.
-
deleteAllObjects
public void deleteAllObjects(Class theClass, List objects, AbstractSession session)
Delete all of the objects with the matching class.
-
getCommitOrder
public List<Class> getCommitOrder()
Return the order in which objects should be committed to the database. This order is based on ownership in the descriptors and is require for referential integrity. The commit order is a vector of vectors, where the first vector is all root level classes, the second is classes owned by roots and so on.
-
getCommitState
protected Map<Object,Integer> getCommitState()
Return the map of states of the objects being committed. The states are defined as static Integers (PENDING, PRE, POST, COMPLETE).
-
hasDataModifications
protected boolean hasDataModifications()
-
getDataModifications
protected Map<DatabaseMapping,List<Object[]>> getDataModifications()
Used to store data queries to be performed at the end of the commit. This is done to decrease dependencies and avoid deadlock.
-
hasDeferredCalls
protected boolean hasDeferredCalls()
-
getDeferredCalls
protected Map<DatabaseTable,List<Object[]>> getDeferredCalls()
Used to store calls to be performed at the end of the commit. This is done for multiple table descriptors to allow batching and avoid deadlock.
-
hasObjectsToDelete
protected boolean hasObjectsToDelete()
-
getObjectsToDelete
public List getObjectsToDelete()
Deletion are cached until the end.
-
getSession
protected AbstractSession getSession()
Return the session that this is managing commits for.
-
getShallowCommits
protected Map getShallowCommits()
Return any objects that have been shallow committed during this commit process.
-
initializeCommitOrder
public void initializeCommitOrder()
Reset the commit order from the session's descriptors. This uses the constraint dependencies in the descriptor's mappings, to decide which descriptors are dependent on which other descriptors. Multiple computations of the commit order should produce the same ordering. This is done to improve performance on unit of work writes through decreasing the stack size, and acts as a deadlock avoidance mechanism.
-
isActive
public boolean isActive()
Return if the commit manager is active.
-
isProcessedCommit
public boolean isProcessedCommit(Object object)
Return if the object has been processed. This should be called by any query that is writing an object, if true the query should not write the object.
-
isCommitCompleted
public boolean isCommitCompleted(Object object)
Return if the object has been committed. This should be called by any query that is writing an object, if true the query should not write the object.
-
isCommitCompletedInPostOrIgnore
public boolean isCommitCompletedInPostOrIgnore(Object object)
Return if the object has been committed. This should be called by any query that is writing an object, if true the query should not write the object.
-
isCommitInPostModify
public boolean isCommitInPostModify(Object object)
Return if the object is being in progress of being post modify commit. This should be called by any query that is writing an object.
-
isCommitInPreModify
public boolean isCommitInPreModify(Object objectOrChangeSet)
Return if the object is being in progress of being pre modify commit. This should be called by any query that is writing an object, if true the query must force a shallow insert of the object if it is new.
-
isShallowCommitted
public boolean isShallowCommitted(Object object)
Return if the object is shallow committed. This is required to resolve bidirectional references.
-
markCommitCompleted
public void markCommitCompleted(Object object)
Mark the commit of the object as being fully completed. This should be called by any query that has finished writing an object.
-
markIgnoreCommit
public void markIgnoreCommit(Object object)
-
markPostModifyCommitInProgress
public void markPostModifyCommitInProgress(Object object)
Add an object as being in progress of being committed. This should be called by any query that is writing an object.
-
markPreModifyCommitInProgress
public void markPreModifyCommitInProgress(Object object)
Add an object as being in progress of being committed. This should be called by any query that is writing an object.
-
markShallowCommit
public void markShallowCommit(Object object)
Mark the object as shallow committed. This is required to resolve bidirectional references.
-
reinitialize
public void reinitialize()
Reset the commits. This must be done before a new commit process is begun.
-
setCommitOrder
public void setCommitOrder(List commitOrder)
Set the order in which objects should be committed to the database. This order is based on ownership in the descriptors and is require for referential integrity. The commit order is a vector of vectors, where the first vector is all root level classes, the second is classes owned by roots and so on.
-
setDataModifications
protected void setDataModifications(Map<DatabaseMapping,List<Object[]>> dataModifications)
Used to store data queries to be performed at the end of the commit. This is done to decrease dependencies and avoid deadlock.
-
setIsActive
public void setIsActive(boolean isActive)
Set if the commit manager is active.
-
setObjectsToDelete
protected void setObjectsToDelete(List objectsToDelete)
Deletion are cached until the end.
-
setSession
protected void setSession(AbstractSession session)
Set the session that this is managing commits for.
-
setShallowCommits
protected void setShallowCommits(Map shallowCommits)
Set any objects that have been shallow committed during this commit process.
-
-