Class CommitManager


  • public class CommitManager
    extends Object
    This class maintains a commit stack and resolves circular references.
    • 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.
      • 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.
      • 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​(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.
      • toString

        public String toString()
        Print the in progress depth.
        Overrides:
        toString in class Object