Class UnitOfWorkImpl

    • Field Detail

      • CREATION_THREAD_ID

        public final long CREATION_THREAD_ID
      • CREATION_THREAD_NAME

        public final String CREATION_THREAD_NAME
      • CREATION_THREAD_HASHCODE

        public final long CREATION_THREAD_HASHCODE
      • cloneToOriginals

        protected transient Map<Object,​Object> cloneToOriginals
        As well as used as lookup in merge algorithm for aggregates and others
      • cloneMapping

        protected Map<Object,​Object> cloneMapping
        Map of all the clones. The key contains the clone of the object.
      • newObjectsCloneToOriginal

        protected Map<Object,​Object> newObjectsCloneToOriginal
      • newObjectsOriginalToClone

        protected Map<Object,​Object> newObjectsOriginalToClone
      • primaryKeyToNewObjects

        protected Map<Object,​List<Object>> primaryKeyToNewObjects
        Map of primary key to list of new objects. Used to speedup in-memory querying.
      • newObjectsCloneToMergeOriginal

        protected Map<Object,​Object> newObjectsCloneToMergeOriginal
        Stores a map from the clone to the original merged object, as a different instance is used as the original for merges.
      • allClones

        protected Map<Object,​Object> allClones
        This member variable contains a copy of all of the clones for this particular UOW
      • objectsDeletedDuringCommit

        protected Map<Object,​Object> objectsDeletedDuringCommit
      • unregisteredNewObjects

        protected Map<Object,​Object> unregisteredNewObjects
      • unregisteredNewObjectsInParent

        protected Map<Object,​Object> unregisteredNewObjectsInParent
      • unregisteredExistingObjects

        protected Map<Object,​Object> unregisteredExistingObjects
      • newObjectsInParentOriginalToClone

        protected Map<Object,​Object> newObjectsInParentOriginalToClone
      • privateOwnedObjects

        protected Map<DatabaseMapping,​Set> privateOwnedObjects
        Cache references of private owned objects for the removal of private owned orphans
      • newObjectsInParent

        protected Map<Object,​Object> newObjectsInParent
        used to store a list of the new objects in the parent
      • unitOfWorkChangeSet

        protected UnitOfWorkChangeSet unitOfWorkChangeSet
        This method is used to store the current changeSet for this UnitOfWork.
      • containerUnitOfWork

        protected UnitOfWorkImpl containerUnitOfWork
        This is only used for EJB entity beans to manage beans accessed in a transaction context.
      • pessimisticLockedObjects

        protected Map<Object,​Object> pessimisticLockedObjects
        use to track pessimistic locked objects
      • lastUsedMergeManager

        protected transient MergeManager lastUsedMergeManager
        Used to store the list of locks that this UnitOfWork has acquired for this merge
      • batchQueries

        protected Map<ReadQuery,​ReadQuery> batchQueries
        When in transaction batch read objects must use query local to the unit of work.
      • readOnlyClasses

        protected Set<Class> readOnlyClasses
        Read-only class can be used for reference data to avoid cloning when not required.
      • wasTransactionBegunPrematurely

        protected boolean wasTransactionBegunPrematurely
        Flag indicating that the transaction for this UOW was already begun.
      • shouldNewObjectsBeCached

        protected boolean shouldNewObjectsBeCached
        Allow for double merges of new objects by putting them into the cache.
      • shouldPerformDeletesFirst

        protected boolean shouldPerformDeletesFirst
        Flag indicating that deletes should be performed before other updates.
      • shouldThrowConformExceptions

        protected int shouldThrowConformExceptions
        Flag indicating how to deal with exceptions on conforming queries.
      • validationLevel

        protected int validationLevel
        The amount of validation can be configured.
      • lifecycle

        protected int lifecycle
        With the new synchronized unit of work, need a lifecycle state variable to track birth, committed, pending_merge and death.
      • CommitTransactionPending

        public static final int CommitTransactionPending
        See Also:
        Constant Field Values
      • AfterExternalTransactionRolledBack

        public static final int AfterExternalTransactionRolledBack
        See Also:
        Constant Field Values
      • DO_NOT_THROW_CONFORM_EXCEPTIONS

        public static final int DO_NOT_THROW_CONFORM_EXCEPTIONS
        Used for Conforming Queries
        See Also:
        Constant Field Values
      • THROW_ALL_CONFORM_EXCEPTIONS

        public static final int THROW_ALL_CONFORM_EXCEPTIONS
        See Also:
        Constant Field Values
      • SmartMerge

        protected static boolean SmartMerge
        Used for merging dependent values without use of WL SessionAccessor
      • optimisticReadLockObjects

        protected Map<Object,​Object> optimisticReadLockObjects
        Kept reference of read lock objects
      • ReadLockOnly

        public static final String ReadLockOnly
        Used for read lock to determine update the version field with the same value or increment value
        See Also:
        Constant Field Values
      • modifyAllQueries

        protected List<ModifyAllQuery> modifyAllQueries
        lazy initialization done in storeModifyAllQuery. For UpdateAllQuery, only clones of all UpdateAllQuery's (deferred and non-deferred) are stored here for validation only.
      • deferredModifyAllQueries

        protected List<Object[]> deferredModifyAllQueries
        Contains deferred ModifyAllQuery's that have translation row for execution only. At commit their clones will be added to modifyAllQueries for validation afterwards. Array of the query (ModifyAllQuery) and translationRow (AbstractRecord).
      • cloneDepth

        protected int cloneDepth
        Used during the cloning process to track the recursive depth in. This will be used to determine at which point the process can begin to wait on locks without being concerned about creating deadlock situations.
      • transaction

        protected Object transaction
        PERF: Stores the JTA transaction to optimize activeUnitOfWork lookup.
      • resumeOnTransactionCompletion

        protected boolean resumeOnTransactionCompletion
        True if UnitOfWork should be resumed on completion of transaction. Used when UnitOfWork is Synchronized with external transaction control
      • shouldDiscoverNewObjects

        protected boolean shouldDiscoverNewObjects
        PERF: Allows discover new objects to be skipped if app always calls persist.
      • wasNonObjectLevelModifyQueryExecuted

        protected boolean wasNonObjectLevelModifyQueryExecuted
        True if either DataModifyQuery or ModifyAllQuery was executed. Gets reset on commit, effects DoesExistQuery behavior and reading.
      • shouldCascadeCloneToJoinedRelationship

        protected boolean shouldCascadeCloneToJoinedRelationship
        True if the value holder for the joined attribute should be triggered. Required by ejb30 fetch join.
      • isNestedUnitOfWork

        protected boolean isNestedUnitOfWork
        PERF: Cache isNestedUnitOfWork check.
      • shouldValidateExistence

        protected boolean shouldValidateExistence
        Determine if does-exist should be performed on persist.
      • commitOrder

        protected UnitOfWork.CommitOrderType commitOrder
        Allow updates and deletes to be ordered by id or changes to avoid possible deadlocks.
      • referenceMode

        protected ReferenceMode referenceMode
        This stored the reference mode for this UOW. If the reference mode is weak then this unit of work will retain only weak references to non new, non-deleted objects allowing for garbage collection. If ObjectChangeTracking is used then any objects with changes will not be garbage collected.
      • changeTrackedHardList

        protected Set<Object> changeTrackedHardList
      • unregisteredDeletedObjectsCloneToBackupAndOriginal

        protected Map<Object,​Object> unregisteredDeletedObjectsCloneToBackupAndOriginal
        Used to store objects already deleted from the db and unregistered
      • preDeleteComplete

        protected boolean preDeleteComplete
        This attribute records when the preDelete stage of Commit has completed
      • deletedPrivateOwnedObjects

        protected Map<DatabaseMapping,​List<Object>> deletedPrivateOwnedObjects
        Stores all of the private owned objects that have been removed and may need to cascade deletion
      • mergeManagerForActiveMerge

        protected transient MergeManager mergeManagerForActiveMerge
        temporarily holds a reference to a merge manager that is calling this UnitOfWork during merge
      • cascadeDeleteObjects

        protected Set<Object> cascadeDeleteObjects
        Set of objects that were deleted by database cascade delete constraints.
      • deletionDependencies

        protected Map<Object,​Set<Object>> deletionDependencies
        Used to store deleted objects that have reference to other deleted objects. This is need to delete cycles of objects in the correct order.
    • Constructor Detail

      • UnitOfWorkImpl

        public UnitOfWorkImpl()
        INTERNAL:
      • UnitOfWorkImpl

        public UnitOfWorkImpl​(AbstractSession parent,
                              ReferenceMode referenceMode)
        INTERNAL: Create and return a new unit of work with the session as its parent.
    • Method Detail

      • acquireUnitOfWork

        public UnitOfWorkImpl acquireUnitOfWork()
        PUBLIC: Return a nested unit of work for this unit of work. A nested unit of work can be used to isolate a subset of work on the unit of work, such as a dialog being open from an editor. The nested unit of work will only commit change to its objects to its parent unit of work, not the database. Only the parent unit of work will commit to the database.
        Specified by:
        acquireUnitOfWork in interface Session
        Overrides:
        acquireUnitOfWork in class AbstractSession
        See Also:
        UnitOfWorkImpl
      • addDeletedPrivateOwnedObjects

        public void addDeletedPrivateOwnedObjects​(DatabaseMapping mapping,
                                                  Object object)
        INTERNAL: Records a private owned object that has been de-referenced and will need to processed for related private owned objects.
      • addNewAggregate

        public void addNewAggregate​(Object originalObject)
        INTERNAL: Register a new aggregate object with the unit of work.
      • addObjectDeletedDuringCommit

        public void addObjectDeletedDuringCommit​(Object object,
                                                 ClassDescriptor descriptor)
        INTERNAL: Add object deleted during root commit of unit of work.
      • addReadOnlyClasses

        public void addReadOnlyClasses​(Collection classes)
        PUBLIC: Adds the classes in the given Vector to the existing set of read-only classes. Cannot be called after objects have been registered in the unit of work.
        Specified by:
        addReadOnlyClasses in interface UnitOfWork
      • addRemovedObject

        public void addRemovedObject​(Object orignal)
        INTERNAL: Register that an object was removed in a nested unit of work.
      • assignSequenceNumber

        public void assignSequenceNumber​(Object object)
                                  throws DatabaseException
        ADVANCED: Assign sequence number to the object. This allows for an object's id to be assigned before commit. It can be used if the application requires to use the object id before the object exists on the database. Normally all ids are assigned during the commit automatically.
        Specified by:
        assignSequenceNumber in interface UnitOfWork
        Throws:
        DatabaseException
      • assignSequenceNumbers

        public void assignSequenceNumbers()
                                   throws DatabaseException
        ADVANCED: Assign sequence numbers to all new objects registered in this unit of work, or any new objects reference by any objects registered. This allows for an object's id to be assigned before commit. It can be used if the application requires to use the object id before the object exists on the database. Normally all ids are assigned during the commit automatically.
        Specified by:
        assignSequenceNumbers in interface UnitOfWork
        Throws:
        DatabaseException
      • assignSequenceNumbers

        protected void assignSequenceNumbers​(Map objects)
                                      throws DatabaseException
        INTERNAL: Assign sequence numbers to all of the objects. This allows for an object's id to be assigned before commit. It can be used if the application requires to use the object id before the object exists on the database. Normally all ids are assigned during the commit automatically.
        Throws:
        DatabaseException
      • beginEarlyTransaction

        public void beginEarlyTransaction()
                                   throws DatabaseException
        PUBLIC: Tell the unit of work to begin a transaction now. By default the unit of work will begin a transaction at commit time. The default is the recommended approach, however sometimes it is necessary to start the transaction before commit time. When the unit of work commits, this transaction will be committed.
        Specified by:
        beginEarlyTransaction in interface UnitOfWork
        Throws:
        DatabaseException
        See Also:
        commit(), release()
      • buildOriginal

        public Object buildOriginal​(Object workingClone)
        INTERNAL: Unregistered new objects have no original so we must create one for commit and resume and to put into the parent. We can NEVER let the same copy of an object exist in multiple units of work.
      • calculateChanges

        public UnitOfWorkChangeSet calculateChanges​(Map registeredObjects,
                                                    UnitOfWorkChangeSet changeSet,
                                                    boolean assignSequences,
                                                    boolean shouldCloneMap)
        INTERNAL:

        This calculates changes in two passes, first on registered objects, second it discovers unregistered new objects on only those objects that changed, and calculates their changes. This also assigns sequence numbers to new objects.

      • canChangeReadOnlySet

        protected boolean canChangeReadOnlySet()
        INTERNAL: Checks whether the receiver has been used. i.e. objects have been registered.
        Returns:
        true or false depending on whether the read-only set can be changed or not.
      • checkForUnregisteredExistingObject

        public boolean checkForUnregisteredExistingObject​(Object object)
        INTERNAL: Return if the object is an existing object (but has not been registered), or a new object (that has not be persisted).
      • checkExistence

        public Object checkExistence​(Object object)
        INTERNAL: Register the object and return the clone if it is existing otherwise return null if it is new. The unit of work determines existence during registration, not during the commit.
      • checkIfAlreadyRegistered

        public Object checkIfAlreadyRegistered​(Object object,
                                               ClassDescriptor descriptor)
        INTERNAL: Return the value of the object if it already is registered, otherwise null.
      • cloneAndRegisterNewObject

        protected Object cloneAndRegisterNewObject​(Object original,
                                                   boolean isShallowClone)
        ADVANCED: Register the new object with the unit of work. This will register the new object with cloning. Normally the registerObject method should be used for all registration of new and existing objects. This version of the register method can only be used for new objects. This method should only be used if a new object is desired to be registered without an existence Check.
        See Also:
        registerObject(Object)
      • cloneAndRegisterObject

        public Object cloneAndRegisterObject​(Object original,
                                             CacheKey parentCacheKey,
                                             ClassDescriptor descriptor)
        INTERNAL: Clone and register the object. The cache key must the cache key from the session cache, as it will be used for locking. The unit of work cache key is passed to the normal cloneAndRegisterObject method.
      • cloneAndRegisterObject

        public Object cloneAndRegisterObject​(Object original,
                                             CacheKey parentCacheKey,
                                             CacheKey unitOfWorkCacheKey,
                                             ClassDescriptor descriptor)
        INTERNAL: Clone and register the object. The cache key must the cache key from the session cache, as it will be used for locking.
      • collectAndPrepareObjectsForNestedMerge

        public Map collectAndPrepareObjectsForNestedMerge()
        INTERNAL: Prepare for merge in nested uow.
      • commit

        public void commit()
                    throws DatabaseException,
                           OptimisticLockException
        PUBLIC: Commit the unit of work to its parent. For a nested unit of work this will merge any changes to its objects with its parents. For a first level unit of work it will commit all changes to its objects to the database as a single transaction. If successful the changes to its objects will be merged to its parent's objects. If the commit fails the database transaction will be rolledback, and the unit of work will be released. If the commit is successful the unit of work is released, and a new unit of work must be acquired if further changes are desired.
        Specified by:
        commit in interface UnitOfWork
        Throws:
        DatabaseException
        OptimisticLockException
        See Also:
        commitAndResumeOnFailure(), commitAndResume(), release()
      • commitAndResume

        public void commitAndResume()
                             throws DatabaseException,
                                    OptimisticLockException
        PUBLIC: Commit the unit of work to its parent. For a nested unit of work this will merge any changes to its objects with its parents. For a first level unit of work it will commit all changes to its objects to the database as a single transaction. If successful the changes to its objects will be merged to its parent's objects. If the commit fails the database transaction will be rolledback, and the unit of work will be released. The normal commit releases the unit of work, forcing a new one to be acquired if further changes are desired. The resuming feature allows for the same unit of work (and working copies) to be continued to be used.
        Specified by:
        commitAndResume in interface UnitOfWork
        Throws:
        DatabaseException
        OptimisticLockException
        See Also:
        commitAndResumeOnFailure(), commit(), release()
      • commitAndResumeOnFailure

        public void commitAndResumeOnFailure()
                                      throws DatabaseException,
                                             OptimisticLockException
        PUBLIC: Commit the unit of work to its parent. For a nested unit of work this will merge any changes to its objects with its parents. For a first level unit of work it will commit all changes to its objects to the database as a single transaction. If successful the changes to its objects will be merged to its parent's objects. If the commit fails the database transaction will be rolledback, but the unit of work will remain active. It can then be retried or released. The normal commit failure releases the unit of work, forcing a new one to be acquired if further changes are desired. The resuming feature allows for the same unit of work (and working copies) to be continued to be used if an error occurs. The UnitOfWork will also remain active if the commit is successful.
        Specified by:
        commitAndResumeOnFailure in interface UnitOfWork
        Throws:
        DatabaseException
        OptimisticLockException
        See Also:
        commit(), release()
      • commitAfterWriteChanges

        protected void commitAfterWriteChanges()
        INTERNAL: Commits a UnitOfWork where the commit process has already been initiated by all call to writeChanges().

        a.k.a finalizeCommit()

      • commitAndResumeAfterWriteChanges

        protected void commitAndResumeAfterWriteChanges()
        INTERNAL: Commits and resumes a UnitOfWork where the commit process has already been initiated by all call to writeChanges().

        a.k.a finalizeCommit()

      • commitInternallyStartedExternalTransaction

        protected boolean commitInternallyStartedExternalTransaction()
        PROTECTED: Used in commit and commit-like methods to commit internally started external transaction
      • commitNestedUnitOfWork

        protected void commitNestedUnitOfWork()
        INTERNAL: Commit the changes to any objects to the parent.
      • commitToDatabase

        protected void commitToDatabase​(boolean commitTransaction)
        INTERNAL: CommitChanges To The Database from a calculated changeSet
        Parameters:
        commitTransaction - false if called by writeChanges as intent is not to finalize the transaction.
      • commitTransaction

        public void commitTransaction()
                               throws DatabaseException
        INTERNAL: This is internal to the uow, transactions should not be used explicitly in a uow. The uow shares its parents transactions.
        Overrides:
        commitTransaction in class AbstractSession
        Throws:
        DatabaseException - most databases validate changes as they are done, normally errors do not occur on commit unless the disk fails or the connection is lost.
      • commitTransactionAfterWriteChanges

        public void commitTransactionAfterWriteChanges()
        INTERNAL: After writeChanges() everything has been done except for committing the transaction. This allows that execution path to 'catch up'.
      • acquireWriteLocks

        protected void acquireWriteLocks()
        INTERNAL: Acquire the unit of work cache write locks, if required.
      • releaseWriteLocks

        public void releaseWriteLocks()
        INTERNAL: Release the unit of work cache write locks, if acquired.
      • deepMergeClone

        public Object deepMergeClone​(Object rmiClone)
        PUBLIC: Merge the attributes of the clone into the unit of work copy. This can be used for objects that are returned from the client through RMI serialization or other serialization mechanisms, because the RMI object will be a clone this will merge its attributes correctly to preserve object identity within the unit of work and record its changes. Everything connected to this object (i.e. the entire object tree where rmiClone is the root) is also merged.
        Specified by:
        deepMergeClone in interface UnitOfWork
        Returns:
        the registered version for the clone being merged.
        See Also:
        mergeClone(Object), shallowMergeClone(Object)
      • deepUnregisterObject

        public void deepUnregisterObject​(Object clone)
        ADVANCED: Unregister the object with the unit of work. This can be used to delete an object that was just created and is not yet persistent. Delete object can also be used, but will result in inserting the object and then deleting it. The method should be used carefully because it will delete all the reachable parts.
        Specified by:
        deepUnregisterObject in interface UnitOfWork
      • discoverAllUnregisteredNewObjects

        protected void discoverAllUnregisteredNewObjects()
        INTERNAL: Search for any objects in the parent that have not been registered. These are required so that the nested unit of work does not add them to the parent clone mapping on commit, causing possible incorrect insertions if they are dereferenced.
      • discoverAllUnregisteredNewObjectsInParent

        protected void discoverAllUnregisteredNewObjectsInParent()
        INTERNAL: Search for any objects in the parent that have not been registered. These are required so that the nested unit of work does not add them to the parent clone mapping on commit, causing possible incorrect insertions if they are dereferenced.
      • discoverUnregisteredNewObjects

        public void discoverUnregisteredNewObjects​(Map clones,
                                                   Map knownNewObjects,
                                                   Map unregisteredExistingObjects,
                                                   Map visitedObjects)
        INTERNAL: Traverse the object to find references to objects not registered in this unit of work.
      • dontPerformValidation

        public void dontPerformValidation()
        ADVANCED: The unit of work performs validations such as, ensuring multiple copies of the same object don't exist in the same unit of work, ensuring deleted objects are not referred after commit, ensures that objects from the parent cache are not referred in the unit of work cache. The level of validation can be increased or decreased for debugging purposes or under advanced situation where the application requires/desires to violate clone identity in the unit of work. It is strongly suggested that clone identity not be violate in the unit of work.
        Specified by:
        dontPerformValidation in interface UnitOfWork
      • forceUpdateToVersionField

        public void forceUpdateToVersionField​(Object lockObject,
                                              boolean shouldModifyVersionField)
        ADVANCED: Set optimistic read lock on the object. This feature is override by normal optimistic lock. when the object is changed in UnitOfWork. The cloneFromUOW must be the clone of from this UnitOfWork and it must implements version locking or timestamp locking. The SQL would look like the followings. If shouldModifyVersionField is true, "UPDATE EMPLOYEE SET VERSION = 2 WHERE EMP_ID = 9 AND VERSION = 1" If shouldModifyVersionField is false, "UPDATE EMPLOYEE SET VERSION = 1 WHERE EMP_ID = 9 AND VERSION = 1"
        Specified by:
        forceUpdateToVersionField in interface UnitOfWork
      • getCommitManager

        public CommitManager getCommitManager()
        INTERNAL: The commit manager is used to resolve referential integrity on commits of multiple objects. The commit manage is lazy init from parent.
        Overrides:
        getCommitManager in class AbstractSession
      • getActiveUnitOfWork

        public UnitOfWork getActiveUnitOfWork()
        PUBLIC: Return the active unit of work for the current active external (JTS) transaction. This should only be used with JTS and will return null if no external transaction exists.
        Specified by:
        getActiveUnitOfWork in interface Session
        Overrides:
        getActiveUnitOfWork in class AbstractSession
      • getAllFromNewObjects

        public Vector getAllFromNewObjects​(Expression selectionCriteria,
                                           Class theClass,
                                           AbstractRecord translationRow,
                                           int valueHolderPolicy)
        INTERNAL: Return any new objects matching the expression. Used for in-memory querying.
      • getBackupCloneForCommit

        public Object getBackupCloneForCommit​(Object clone,
                                              ClassDescriptor descriptor)
        INTERNAL: Return the backup clone for the working clone.
      • getBackupCloneForCommit

        public Object getBackupCloneForCommit​(Object clone)
        INTERNAL: Return the backup clone for the working clone.
      • getCurrentChanges

        public UnitOfWorkChangeSet getCurrentChanges()
        ADVANCED: This method Will Calculate the changes for the UnitOfWork. Without assigning sequence numbers This is a computationally intensive operation and should be avoided unless necessary. A valid changeSet, with sequencenumbers can be collected from the UnitOfWork after the commit is complete by calling unitOfWork.getUnitOfWorkChangeSet()
        Specified by:
        getCurrentChanges in interface UnitOfWork
      • getParentIdentityMapSession

        public AbstractSession getParentIdentityMapSession​(ClassDescriptor descriptor,
                                                           boolean canReturnSelf,
                                                           boolean terminalOnly)
        INTERNAL: Returns the appropriate IdentityMap session for this descriptor. Sessions can be chained and each session can have its own Cache/IdentityMap. Entities can be stored at different levels based on Cache Isolation. This method will return the correct Session for a particular Entity class based on the Isolation Level and the attributes provided.

        Overrides:
        getParentIdentityMapSession in class AbstractSession
        Parameters:
        canReturnSelf - true when method calls itself. If the path starting at this is acceptable. Sometimes true if want to move to the first valid session, i.e. executing on ClientSession when really should be on ServerSession.
        terminalOnly - return the last session in the chain where the Enitity is stored.
        Returns:
        Session with the required IdentityMap
      • getExecutionSession

        public AbstractSession getExecutionSession​(DatabaseQuery query)
        INTERNAL: Gets the session which this query will be executed on. Generally will be called immediately before the call is translated, which is immediately before session.executeCall.

        Since the execution session also knows the correct datasource platform to execute on, it is often used in the mappings where the platform is needed for type conversion, or where calls are translated.

        Is also the session with the accessor. Will return a ClientSession if it is in transaction and has a write connection.

        Overrides:
        getExecutionSession in class AbstractSession
        Parameters:
        query - may store session name or reference class for brokers case
        Returns:
        a session with a live accessor
      • getCloneMapping

        public Map getCloneMapping()
        INTERNAL: Return the clone mapping. The clone mapping contains clone of all registered objects, this is required to store the original state of the objects when registered so that only what is changed will be committed to the database and the parent, (this is required to support parallel unit of work).
      • hasCloneMapping

        public boolean hasCloneMapping()
        INTERNAL: Return if the unit of work has any clones.
      • getCloneToOriginals

        public Map getCloneToOriginals()
        INTERNAL: Map used to avoid garbage collection in weak caches. Also, map used as lookup when originals used for merge when original in identitymap can not be found. As in a CacheIdentityMap
      • hasCloneToOriginals

        protected boolean hasCloneToOriginals()
      • getContainerBeans

        public Map getContainerBeans()
        INTERNAL: This is only used for EJB entity beans to manage beans accessed in a transaction context.
      • hasContainerBeans

        public boolean hasContainerBeans()
        INTERNAL: Return if any container beans exist. PERF: Used to avoid lazy initialization of getContainerBeans().
      • getCascadeDeleteObjects

        public Set<Object> getCascadeDeleteObjects()
        INTERNAL: Return any objects have been deleted through database cascade delete constraints.
      • setCascadeDeleteObjects

        protected void setCascadeDeleteObjects​(Set<Object> cascadeDeleteObjects)
        INTERNAL: Set any objects have been deleted through database cascade delete constraints.
      • hasCascadeDeleteObjects

        public boolean hasCascadeDeleteObjects()
        INTERNAL: Return if any objects have been deleted through database cascade delete constraints.
      • hasUnregisteredNewObjects

        public boolean hasUnregisteredNewObjects()
        INTERNAL: Return if there are any unregistered new objects. PERF: Used to avoid initialization of new objects map unless required.
      • hasNewObjects

        public boolean hasNewObjects()
        INTERNAL: Return if there are any registered new objects. This is used for both newObjectsOriginalToClone and newObjectsCloneToOriginal as they are always in synch. PERF: Used to avoid initialization of new objects map unless required.
      • getContainerUnitOfWork

        public UnitOfWorkImpl getContainerUnitOfWork()
        INTERNAL: This is only used for EJB entity beans to manage beans accessed in a transaction context.
      • getDeletedObjects

        public Map getDeletedObjects()
        INTERNAL: The deleted objects stores any objects removed during the unit of work. On commit they will all be removed from the database.
      • hasDeletedObjects

        public boolean hasDeletedObjects()
        INTERNAL: The deleted objects stores any objects removed during the unit of work. On commit they will all be removed from the database.
      • getLifecycle

        public int getLifecycle()
        INTERNAL: The life cycle tracks if the unit of work is active and is used for JTS.
      • getMergeManager

        public MergeManager getMergeManager()
        A reference to the last used merge manager. This is used to track locked objects.
      • getNewAggregates

        public Map getNewAggregates()
        INTERNAL: The map stores any new aggregates that have been cloned.
      • getNewObjectsCloneToOriginal

        public Map getNewObjectsCloneToOriginal()
        INTERNAL: The new objects stores any objects newly created during the unit of work. On commit they will all be inserted into the database.
      • getPrimaryKeyToNewObjects

        public Map<Object,​List<Object>> getPrimaryKeyToNewObjects()
        INTERNAL: The primaryKeyToNewObjects stores a list of objects for every primary key. It is used to speed up in-memory-querying.
      • getNewObjectsCloneToMergeOriginal

        public Map getNewObjectsCloneToMergeOriginal()
        INTERNAL: The stores a map from new object clones to the original object used from merge.
      • getNewObjectsInParentOriginalToClone

        public Map getNewObjectsInParentOriginalToClone()
        INTERNAL: The returns the list that will hold the new objects from the Parent UnitOfWork
      • hasNewObjectsInParentOriginalToClone

        protected boolean hasNewObjectsInParentOriginalToClone()
      • hasPrivateOwnedObjects

        public boolean hasPrivateOwnedObjects()
        INTERNAL: Return true if privateOwnedObjects is not null and not empty, false otherwise.
      • hasOptimisticReadLockObjects

        public boolean hasOptimisticReadLockObjects()
        INTERNAL: Return if there are any optimistic read locks.
      • getNewObjectsOriginalToClone

        public Map getNewObjectsOriginalToClone()
        INTERNAL: The new objects stores any objects newly created during the unit of work. On commit they will all be inserted into the database.
      • getServerPlatform

        public ServerPlatform getServerPlatform()
        INTERNAL: Marked internal as this is not customer API but helper methods for accessing the server platform from within EclipseLink's other sessions types (i.e. not DatabaseSession)
        Specified by:
        getServerPlatform in interface Session
        Overrides:
        getServerPlatform in class AbstractSession
      • getSessionTypeString

        public String getSessionTypeString()
        INTERNAL: Returns the type of session, its class.

        Override to hide from the user when they are using an internal subclass of a known class.

        A user does not need to know that their UnitOfWork is a non-deferred UnitOfWork, or that their ClientSession is an IsolatedClientSession.

        Overrides:
        getSessionTypeString in class AbstractSession
      • afterExternalTransactionRollback

        public void afterExternalTransactionRollback()
        INTERNAL: Called after external transaction rolled back.
      • releaseJTSConnection

        public void releaseJTSConnection()
        INTERNAL: Called in the end of beforeCompletion of external transaction synchronization listener. Close the managed sql connection corresponding to the external transaction.
        Overrides:
        releaseJTSConnection in class AbstractSession
      • getObjectFromNewObjects

        public Object getObjectFromNewObjects​(Class theClass,
                                              Object selectionKey)
        INTERNAL: Return any new object matching the expression. Used for in-memory querying.
      • getObjectFromNewObjects

        public Object getObjectFromNewObjects​(Expression selectionCriteria,
                                              Class theClass,
                                              AbstractRecord translationRow,
                                              int valueHolderPolicy)
        INTERNAL: Return any new object matching the expression. Used for in-memory querying.
      • getObjectsDeletedDuringCommit

        public Map getObjectsDeletedDuringCommit()
        INTERNAL: Returns all the objects which are deleted during root commit of unit of work.
      • hasObjectsDeletedDuringCommit

        protected boolean hasObjectsDeletedDuringCommit()
      • getOptimisticReadLockObjects

        public Map getOptimisticReadLockObjects()
        INTERNAL: Return optimistic read lock objects
      • getOriginalVersionOfNewObject

        public Object getOriginalVersionOfNewObject​(Object workingClone)
        INTERNAL: Return the original version of the new object (working clone).
      • getOriginalVersionOfObject

        public Object getOriginalVersionOfObject​(Object workingClone)
        ADVANCED: Return the original version of the object(clone) from the parent's identity map.
        Specified by:
        getOriginalVersionOfObject in interface UnitOfWork
      • getOriginalVersionOfObjectOrNull

        public Object getOriginalVersionOfObjectOrNull​(Object workingClone,
                                                       ObjectChangeSet changeSet,
                                                       ClassDescriptor descriptor,
                                                       AbstractSession targetSession)
        INTERNAL: Return the original version of the object(clone) from the parent's identity map. PERF: Use the change set to avoid cache lookups.
      • getOriginalVersionOfObjectOrNull

        public Object getOriginalVersionOfObjectOrNull​(Object workingClone,
                                                       ClassDescriptor descriptor)
        INTERNAL: Return the original version of the object(clone) from the parent's identity map.
      • getProperty

        public Object getProperty​(String name)
        INTERNAL: Search for and return the user defined property from this UOW, if it not found then search for the property from parent.
        Specified by:
        getProperty in interface Session
        Overrides:
        getProperty in class AbstractSession
      • getShouldThrowConformExceptions

        public int getShouldThrowConformExceptions()
        INTERNAL: Return whether to throw exceptions on conforming queries
      • getQuery

        public DatabaseQuery getQuery​(String name)
        PUBLIC: Return the query from the session pre-defined queries with the given name. This allows for common queries to be pre-defined, reused and executed by name.
        Specified by:
        getQuery in interface Session
        Overrides:
        getQuery in class AbstractSession
      • getReadOnlyClasses

        public Set getReadOnlyClasses()
        ADVANCED: Returns the set of read-only classes in this UnitOfWork.
        Specified by:
        getReadOnlyClasses in interface UnitOfWork
      • getRemovedObjects

        protected Map getRemovedObjects()
        INTERNAL: The removed objects stores any newly registered objects removed during the nested unit of work. On commit they will all be removed from the parent unit of work.
      • hasRemovedObjects

        protected boolean hasRemovedObjects()
      • hasModifyAllQueries

        protected boolean hasModifyAllQueries()
      • hasDeferredModifyAllQueries

        protected boolean hasDeferredModifyAllQueries()
      • getState

        public int getState()
        INTERNAL: Find out what the lifecycle state of this UoW is in.
      • getTransaction

        public Object getTransaction()
        INTERNAL: PERF: Return the associated external transaction. Used to optimize activeUnitOfWork lookup.
      • setTransaction

        public void setTransaction​(Object transaction)
        INTERNAL: PERF: Set the associated external transaction. Used to optimize activeUnitOfWork lookup.
      • getUnitOfWorkChangeSet

        public UnitOfWorkChangeSet getUnitOfWorkChangeSet()
        ADVANCED: Returns the currentChangeSet from the UnitOfWork. This is only valid after the UnitOfWOrk has committed successfully
        Specified by:
        getUnitOfWorkChangeSet in interface UnitOfWork
      • getUnregisteredExistingObjects

        public Map getUnregisteredExistingObjects()
        INTERNAL: Used to lazy Initialize the unregistered existing Objects collection.
        Returns:
        Map
      • getUnregisteredNewObjects

        protected Map getUnregisteredNewObjects()
        INTERNAL: This is used to store unregistered objects discovered in the parent so that the child unit of work knows not to register them on commit.
      • getUnregisteredNewObjectsInParent

        protected Map getUnregisteredNewObjectsInParent()
        INTERNAL: This is used to store unregistered objects discovered in the parent so that the child unit of work knows not to register them on commit.
      • getValidationLevel

        public int getValidationLevel()
        ADVANCED: The unit of work performs validations such as, ensuring multiple copies of the same object don't exist in the same unit of work, ensuring deleted objects are not referred after commit, ensures that objects from the parent cache are not referred in the unit of work cache. The level of validation can be increased or decreased for debugging purposes or under advanced situation where the application requires/desires to violate clone identity in the unit of work. It is strongly suggested that clone identity not be violate in the unit of work.
        Specified by:
        getValidationLevel in interface UnitOfWork
      • hasChanges

        public boolean hasChanges()
        ADVANCED: The Unit of work is capable of preprocessing to determine if any on the clone have been changed. This is computationally expensive and should be avoided on large object graphs.
        Specified by:
        hasChanges in interface UnitOfWork
      • hasModifications

        protected boolean hasModifications()
        INTERNAL: Does this unit of work have any changes or anything that requires a write to the database and a transaction to be started. Should be called after changes are calculated internally by commit.

        Note if a transaction was begun prematurely it still needs to be committed.

      • initializeIdentityMapAccessor

        public void initializeIdentityMapAccessor()
        INTERNAL: Set up the IdentityMapManager. This method allows subclasses of Session to override the default IdentityMapManager functionality.
        Overrides:
        initializeIdentityMapAccessor in class AbstractSession
      • internalRegisterObject

        public Object internalRegisterObject​(Object object,
                                             ClassDescriptor descriptor,
                                             boolean isShallowClone)
        INTERNAL: Register the object with the unit of work. This does not perform wrapping or unwrapping. This is used for internal registration in the merge manager.
      • isActive

        public boolean isActive()
        PUBLIC: Return if the unit of work is active. (i.e. has not been released).
        Specified by:
        isActive in interface UnitOfWork
      • isClassReadOnly

        public boolean isClassReadOnly​(Class theClass,
                                       ClassDescriptor descriptor)
        INTERNAL: Checks to see if the specified class or descriptor is read-only or not in this UnitOfWork.
        Overrides:
        isClassReadOnly in class AbstractSession
        Returns:
        boolean, true if the class is read-only, false otherwise.
      • isCloneNewObjectFromParent

        public boolean isCloneNewObjectFromParent​(Object clone)
        INTERNAL: Check if the object is already registered in a parent Unit Of Work
      • isCloneNewObject

        public boolean isCloneNewObject​(Object clone)
        INTERNAL: Check if the object is already registered.
      • isCommitPending

        public boolean isCommitPending()
        INTERNAL: Return if the unit of work is waiting to be committed or in the process of being committed.
      • isDead

        public boolean isDead()
        INTERNAL: Return if the unit of work is dead.
      • isInTransaction

        public boolean isInTransaction()
        PUBLIC: Return whether the session currently has a database transaction in progress.
        Overrides:
        isInTransaction in class AbstractSession
      • isMergePending

        public boolean isMergePending()
        INTERNAL: Return if the unit of work is waiting to be merged or in the process of being merged.
      • isAfterWriteChangesButBeforeCommit

        public boolean isAfterWriteChangesButBeforeCommit()
        INTERNAL: Has writeChanges() been attempted on this UnitOfWork? It may have either succeeded or failed but either way the UnitOfWork is in a highly restricted state.
      • isAfterWriteChangesFailed

        protected boolean isAfterWriteChangesFailed()
        INTERNAL: Once writeChanges has failed all a user can do really is rollback.
      • isNestedUnitOfWork

        public boolean isNestedUnitOfWork()
        PUBLIC: Return whether this session is a nested unit of work or not.
        Specified by:
        isNestedUnitOfWork in interface UnitOfWork
      • isNewObjectInParent

        public boolean isNewObjectInParent​(Object clone)
        INTERNAL: This method determines if the specified clone is new in the parent UnitOfWork
      • isObjectDeleted

        public boolean isObjectDeleted​(Object object)
        INTERNAL: Return if the object has been deleted in this unit of work.
      • isObjectNew

        public boolean isObjectNew​(Object clone)
        INTERNAL: This method is used to determine if the clone is a new Object in the UnitOfWork
      • isUnregisteredExistingObject

        public boolean isUnregisteredExistingObject​(Object object)
        INTERNAL: Return if the object is a known unregistered existing object.
      • isObjectRegistered

        public boolean isObjectRegistered​(Object clone)
        ADVANCED: Return whether the clone object is already registered.
        Specified by:
        isObjectRegistered in interface UnitOfWork
      • isOriginalNewObject

        public boolean isOriginalNewObject​(Object original)
        INTERNAL: Return whether the original object is new. It was either registered as new or discovered as a new aggregate within another new object.
      • isSmartMerge

        public static boolean isSmartMerge()
        INTERNAL: Return the status of smart merge
      • issueSQLbeforeCompletion

        public void issueSQLbeforeCompletion()
        INTERNAL: For synchronized units of work, dump SQL to database. For cases where writes occur before the end of the transaction don't commit
      • issueSQLbeforeCompletion

        public void issueSQLbeforeCompletion​(boolean commitTransaction)
        INTERNAL: For synchronized units of work, dump SQL to database. For cases where writes occur before the end of the transaction don't commit
      • issueModifyAllQueryList

        protected void issueModifyAllQueryList()
        INTERNAL: Will notify all the deferred ModifyAllQuery's (excluding UpdateAllQuery's) and deferred UpdateAllQuery's to execute.
      • isUnregisteredNewObjectInParent

        public boolean isUnregisteredNewObjectInParent​(Object originalObject)
        INTERNAL: Return if the object was existing but not registered in the parent of the nested unit of work.
      • mergeBmpAndWsEntities

        protected void mergeBmpAndWsEntities()
        INTERNAL: BMP and Websphere CMP entities have to be merged if they are registered in the unit of work. Check to see if there are any such entities and do the merge if required.
      • mergeChangesIntoParent

        protected void mergeChangesIntoParent()
        INTERNAL: Merge the changes to all objects to the parent.
      • mergeClone

        public Object mergeClone​(Object rmiClone)
        PUBLIC: Merge the attributes of the clone into the unit of work copy. This can be used for objects that are returned from the client through RMI serialization (or another serialization mechanism), because the RMI object will be a clone this will merge its attributes correctly to preserve object identity within the unit of work and record its changes. The object and its private owned parts are merged.
        Specified by:
        mergeClone in interface UnitOfWork
        Returns:
        the registered version for the clone being merged.
        See Also:
        shallowMergeClone(Object), deepMergeClone(Object)
      • mergeClone

        public Object mergeClone​(Object rmiClone,
                                 int cascadeDepth,
                                 boolean forRefresh)
        INTERNAL: Merge the attributes of the clone into the unit of work copy.
      • mergeClonesAfterCompletion

        public void mergeClonesAfterCompletion()
        INTERNAL: for synchronized units of work, merge changes into parent
      • mergeCloneWithReferences

        public Object mergeCloneWithReferences​(Object rmiClone)
        PUBLIC: Merge the attributes of the clone into the unit of work copy. This can be used for objects that are returned from the client through RMI serialization (or another serialization mechanism), because the RMI object will be a clone this will merge its attributes correctly to preserve object identity within the unit of work and record its changes. The object and its private owned parts are merged. This will include references from dependent objects to independent objects.
        Specified by:
        mergeCloneWithReferences in interface UnitOfWork
        Returns:
        the registered version for the clone being merged.
        See Also:
        shallowMergeClone(Object), deepMergeClone(Object)
      • mergeCloneWithReferences

        public Object mergeCloneWithReferences​(Object rmiClone,
                                               int cascadePolicy)
        PUBLIC: Merge the attributes of the clone into the unit of work copy. This can be used for objects that are returned from the client through RMI serialization (or another serialization mechanism), because the RMI object will be a clone this will merge its attributes correctly to preserve object identity within the unit of work and record its changes. The object and its private owned parts are merged. This will include references from dependent objects to independent objects.
        Returns:
        the registered version for the clone being merged.
        See Also:
        shallowMergeClone(Object), deepMergeClone(Object)
      • mergeCloneWithReferences

        public Object mergeCloneWithReferences​(Object rmiClone,
                                               int cascadePolicy,
                                               boolean forceCascade)
        INTERNAL: Merge the attributes of the clone into the unit of work copy. This can be used for objects that are returned from the client through RMI serialization (or another serialization mechanism), because the RMI object will be a clone this will merge its attributes correctly to preserve object identity within the unit of work and record its changes. The object and its private owned parts are merged. This will include references from dependent objects to independent objects.
        Returns:
        the registered version for the clone being merged.
        See Also:
        shallowMergeClone(Object), deepMergeClone(Object)
      • mergeCloneWithReferences

        public Object mergeCloneWithReferences​(Object rmiClone,
                                               MergeManager manager)
        INTERNAL: Merge the attributes of the clone into the unit of work copy. This can be used for objects that are returned from the client through RMI serialization (or another serialization mechanism), because the RMI object will be a clone this will merge its attributes correctly to preserve object identity within the unit of work and record its changes. The object and its private owned parts are merged. This will include references from dependent objects to independent objects.
        Returns:
        the registered version for the clone being merged.
        See Also:
        shallowMergeClone(Object), deepMergeClone(Object)
      • newInstance

        public Object newInstance​(Class theClass)
        PUBLIC: Return a new instance of the class registered in this unit of work. This can be used to ensure that new objects are registered correctly.
        Specified by:
        newInstance in interface UnitOfWork
      • performRemove

        public void performRemove​(Object toBeDeleted,
                                  Map visitedObjects)
        INTERNAL: This method will perform a delete operation on the provided objects pre-determining the objects that will be deleted by a commit of the UnitOfWork including privately owned objects. It does not execute a query for the deletion of these objects as the normal deleteobject operation does. Mainly implemented to provide EJB 3.0 deleteObject support.
      • performRemovePrivateOwnedObjectFromChangeSet

        public void performRemovePrivateOwnedObjectFromChangeSet​(Object toBeRemoved,
                                                                 Map visitedObjects)
        INTERNAL: Cascade remove the private owned object from the owned UnitOfWorkChangeSet
      • performFullValidation

        public void performFullValidation()
        ADVANCED: The unit of work performs validations such as, ensuring multiple copies of the same object don't exist in the same unit of work, ensuring deleted objects are not referred after commit, ensures that objects from the parent cache are not referred in the unit of work cache. The level of validation can be increased or decreased for debugging purposes or under advanced situation where the application requires/desires to violate clone identity in the unit of work. It is strongly suggested that clone identity not be violate in the unit of work.
        Specified by:
        performFullValidation in interface UnitOfWork
      • performPartialValidation

        public void performPartialValidation()
        ADVANCED: The unit of work performs validations such as, ensuring multiple copies of the same object don't exist in the same unit of work, ensuring deleted objects are not referred after commit, ensures that objects from the parent cache are not referred in the unit of work cache. The level of validation can be increased or decreased for debugging purposes or under advanced situation where the application requires/desires to violate clone identity in the unit of work. It is strongly suggested that clone identity not be violate in the unit of work.
        Specified by:
        performPartialValidation in interface UnitOfWork
      • populateAndRegisterObject

        protected void populateAndRegisterObject​(Object original,
                                                 Object workingClone,
                                                 CacheKey unitOfWorkCacheKey,
                                                 CacheKey parentCacheKey,
                                                 ClassDescriptor descriptor)
        INTERNAL: This method is called from clone and register. It includes the processing required to clone an object, including populating attributes, putting in UOW identitymap and building a backupclone
      • postMergeChanges

        protected void postMergeChanges​(Set classesChanged)
        INTERNAL: Remove objects from parent's identity map.
      • preMergeChanges

        protected void preMergeChanges()
        INTERNAL: Remove objects deleted during commit from clone and new object cache so that these are not merged
      • printRegisteredObjects

        public void printRegisteredObjects()
        PUBLIC: Print the objects in the unit of work. The output of this method will be logged to this unit of work's SessionLog at SEVERE level.
        Specified by:
        printRegisteredObjects in interface UnitOfWork
      • processDeleteObjectQuery

        public Object processDeleteObjectQuery​(DeleteObjectQuery deleteQuery)
        INTERNAL: This method is used to process delete queries that pass through the unitOfWork It is extracted out of the internalExecuteQuery method to reduce duplication
      • basicPrintRegisteredObjects

        protected void basicPrintRegisteredObjects()
        INTERNAL: Print the objects in the unit of work.
      • registerAllObjects

        public Vector registerAllObjects​(Collection domainObjects)
        PUBLIC: Register the objects with the unit of work. All newly created root domain objects must be registered to be inserted on commit. Also any existing objects that will be edited and were not read from this unit of work must also be registered. Once registered any changes to the objects will be committed to the database on commit.
        Specified by:
        registerAllObjects in interface UnitOfWork
        Returns:
        is the clones of the original objects, the return value must be used for editing. Editing the original is not allowed in the unit of work.
      • registerAllObjects

        public Vector registerAllObjects​(Vector domainObjects)
                                  throws DatabaseException,
                                         OptimisticLockException
        PUBLIC: Register the objects with the unit of work. All newly created root domain objects must be registered to be inserted on commit. Also any existing objects that will be edited and were not read from this unit of work must also be registered. Once registered any changes to the objects will be committed to the database on commit.
        Returns:
        is the clones of the original objects, the return value must be used for editing. Editing the original is not allowed in the unit of work.
        Throws:
        DatabaseException
        OptimisticLockException
      • registerExistingObject

        public Object registerExistingObject​(Object existingObject)
        ADVANCED: Register the existing object with the unit of work. This is a advanced API that can be used if the application can guarantee the object exists on the database. When registerObject is called the unit of work determines existence through the descriptor's doesExist setting.
        Specified by:
        registerExistingObject in interface UnitOfWork
        Returns:
        The clone of the original object, the return value must be used for editing. Editing the original is not allowed in the unit of work.
      • registerExistingObject

        public Object registerExistingObject​(Object existingObject,
                                             boolean isFromSharedCache)
        ADVANCED: Register the existing object with the unit of work. This is a advanced API that can be used if the application can guarantee the object exists on the database. When registerObject is called the unit of work determines existence through the descriptor's doesExist setting.
        Returns:
        The clone of the original object, the return value must be used for editing. Editing the original is not allowed in the unit of work.
      • registerExistingObject

        public Object registerExistingObject​(Object objectToRegister,
                                             ClassDescriptor descriptor,
                                             Object queryPrimaryKey,
                                             boolean isFromSharedCache)
        INTERNAL: Register the existing object with the unit of work. This is a advanced API that can be used if the application can guarantee the object exists on the database. When registerObject is called the unit of work determines existence through the descriptor's doesExist setting.
        Returns:
        The clone of the original object, the return value must be used for editing. Editing the original is not allowed in the unit of work.
      • registerNewContainerBean

        public Object registerNewContainerBean​(Object newObject)
        INTERNAL: Register the new container bean with the unit of work. Normally the registerObject method should be used for all registration of new and existing objects. This version of the register method can only be used for new container beans.
        See Also:
        registerObject(Object)
      • registerNewContainerBeanForCMP

        public Object registerNewContainerBeanForCMP​(Object newObject)
        INTERNAL: Register the new Bean with the unit of work. This will register the new Bean with cloning. Normally the registerObject method should be used for all registration of new and existing objects. This version of the register method can only be used for new objects.
      • registerNewObject

        public Object registerNewObject​(Object newObject)
        ADVANCED: Register the new object with the unit of work. This will register the new object without cloning. Normally the registerObject method should be used for all registration of new and existing objects. This version of the register method can only be used for new objects. This method should only be used if a new object is desired to be registered without cloning.
        Specified by:
        registerNewObject in interface UnitOfWork
        See Also:
        registerObject(Object)
      • registerNewObject

        protected Object registerNewObject​(Object implementation,
                                           ClassDescriptor descriptor)
        INTERNAL: Updated to allow passing in of the object's descriptor Register the new object with the unit of work. This will register the new object without cloning. Normally the registerObject method should be used for all registration of new and existing objects. This version of the register method can only be used for new objects. This method should only be used if a new object is desired to be registered without cloning.
        See Also:
        registerObject(Object)
      • discoverAndPersistUnregisteredNewObjects

        public void discoverAndPersistUnregisteredNewObjects​(Object object,
                                                             boolean cascadePersist,
                                                             Map newObjects,
                                                             Map unregisteredExistingObjects,
                                                             Map visitedObjects,
                                                             Set cascadeErrors)
        INTERNAL: Discover any new objects referenced from registered objects and persist them. This is similar to persist, except that it traverses (all changed or new) objects during the commit to find any unregistered new objects and persists them. Only objects referenced by cascade persist mappings will be persisted, an error will be thrown from non-cascade persist mappings to new objects (detached existing object are ok...in thoery). This is specific to EJB 3.0 support.
        Parameters:
        newObjects - any new objects found must be added to this collection.
        cascadePersist - determines if this call is cascading from a cascadePersist mapping or not.
      • registerNewObjectForPersist

        public void registerNewObjectForPersist​(Object newObject,
                                                Map visitedObjects)
        INTERNAL: Register the new object with the unit of work. This will register the new object without cloning. Checks based on existence will be completed and the create will be cascaded based on the object's mappings cascade requirements. This is specific to EJB 3.0 support.
        See Also:
        registerObject(Object)
      • wasDeleted

        public boolean wasDeleted​(Object original)
        INTERNAL: Return if the object was deleted previously (in a flush).
      • registerNotRegisteredNewObjectForPersist

        protected void registerNotRegisteredNewObjectForPersist​(Object newObject,
                                                                ClassDescriptor descriptor)
        INTERNAL: Called only by registerNewObjectForPersist method, and only if newObject is not already registered. Could be overridden in subclasses.
      • registerNewObjectClone

        protected void registerNewObjectClone​(Object clone,
                                              Object original,
                                              ClassDescriptor descriptor)
        INTERNAL: Register the working copy of a new object and its original. The user must edit the working copy and the original is used to merge into the parent. This mapping is kept both ways because lookup is required in both directions.
      • registerNewObjectInIdentityMap

        protected void registerNewObjectInIdentityMap​(Object clone,
                                                      Object original,
                                                      ClassDescriptor descriptor)
        INTERNAL: Add the new object to the cache if set to. This is useful for using mergeclone on new objects.
      • registerObject

        public Object registerObject​(Object object)
        PUBLIC: Register the object with the unit of work. All newly created root domain objects must be registered to be inserted on commit. Also any existing objects that will be edited and were not read from this unit of work must also be registered. Once registered any changes to the objects will be committed to the database on commit.
        Specified by:
        registerObject in interface UnitOfWork
        Returns:
        the clone of the original object, the return value must be used for editing, ** Editing the original is not allowed in the unit of work. **
      • registerObject

        protected Object registerObject​(Object object,
                                        ClassDescriptor descriptor)
        INTERNAL: Allows for calling method to provide the descriptor information for this object. Prevents double lookup of descriptor. Register the object with the unit of work. All newly created root domain objects must be registered to be inserted on commit. Also any existing objects that will be edited and were not read from this unit of work must also be registered. Once registered any changes to the objects will be committed to the database on commit. calling this method will also sort the objects into different different groups depending on if the object being registered is a bean or a regular Java object and if its updates are deferred, non-deferred or if all modifications are deferred.
        Returns:
        the clone of the original object, the return value must be used for editing,
      • registerOriginalNewObjectFromNestedUnitOfWork

        public void registerOriginalNewObjectFromNestedUnitOfWork​(Object originalObject,
                                                                  Object backupClone,
                                                                  Object newInstance,
                                                                  ClassDescriptor descriptor)
        INTERNAL: Register a new object from a nested unit of work into its parent.
      • registerWithTransactionIfRequired

        public void registerWithTransactionIfRequired()
        INTERNAL: Register this UnitOfWork against an external transaction controller
      • release

        public void release()
        PUBLIC: Release the unit of work. This terminates this unit of work. Because the unit of work operates on its own object space (clones) no work is required. The unit of work should no longer be used or referenced by the application beyond this point so that it can be garbage collected.
        Specified by:
        release in interface Session
        Specified by:
        release in interface UnitOfWork
        Overrides:
        release in class AbstractSession
        See Also:
        commit()
      • removeAllReadOnlyClasses

        public void removeAllReadOnlyClasses()
                                      throws ValidationException
        PUBLIC: Empties the set of read-only classes. It is illegal to call this method on nested UnitOfWork objects. A nested UnitOfWork cannot have a subset of its parent's set of read-only classes. Also removes classes which are read only because their descriptors are readonly
        Specified by:
        removeAllReadOnlyClasses in interface UnitOfWork
        Throws:
        ValidationException
      • removeForceUpdateToVersionField

        public void removeForceUpdateToVersionField​(Object lockObject)
        ADVANCED: Remove optimistic read lock from the object See forceUpdateToVersionField(Object)
        Specified by:
        removeForceUpdateToVersionField in interface UnitOfWork
      • removePrivateOwnedObject

        public void removePrivateOwnedObject​(DatabaseMapping mapping,
                                             Object privateOwnedObject)
        INTERNAL: Remove a privately owned object from the privateOwnedObjects Map. The UnitOfWork needs to keep track of privately owned objects in order to detect and remove private owned objects which are de-referenced. When an object (which is referenced) is removed from the privateOwnedObjects Map, it is no longer considered for removal from ChangeSets and the UnitOfWork identitymap.
      • revertAndResume

        public void revertAndResume()
        PUBLIC: Revert all changes made to any registered object. Clear all deleted and new objects. Revert should not be confused with release which it the normal compliment to commit. Revert is more similar to commit and resume, however reverts all changes and resumes. If you do not require to resume the unit of work release should be used instead.
        Specified by:
        revertAndResume in interface UnitOfWork
        See Also:
        commitAndResume(), release()
      • revertObject

        public Object revertObject​(Object clone,
                                   int cascadeDepth)
        INTERNAL: Revert the object's attributes from the parent. This uses merging to merge the object changes.
      • rollbackTransaction

        public void rollbackTransaction()
                                 throws DatabaseException
        INTERNAL: This is internal to the uow, transactions should not be used explicitly in a uow. The uow shares its parents transactions.
        Overrides:
        rollbackTransaction in class AbstractSession
        Throws:
        DatabaseException - if the database connection is lost or the rollback fails.
      • rollbackTransaction

        protected void rollbackTransaction​(boolean intendedToCommitTransaction)
                                    throws DatabaseException
        INTERNAL: rollbackTransaction() with a twist for external transactions.

        writeChanges() is called outside the JTA beforeCompletion(), so the accompanying exception won't propagate up and cause a rollback by itself.

        Instead must mark the transaction for rollback only here.

        If internally started external transaction or no external transaction can still rollback normally.

        Parameters:
        intendedToCommitTransaction - whether we were inside a commit or just trying to write out changes early.
        Throws:
        DatabaseException
      • scanForConformingInstances

        public Map<Object,​Object> scanForConformingInstances​(Expression selectionCriteria,
                                                                   Class referenceClass,
                                                                   AbstractRecord arguments,
                                                                   ObjectLevelReadQuery query)
        INTERNAL: Scans the UnitOfWork identity map for conforming instances.

        Later this method can be made recursive to check all parent units of work also.

        Parameters:
        selectionCriteria - must be cloned and specially prepared for conforming
        Returns:
        Map to facilitate merging with conforming instances returned from a query on the database.
      • setAllClonesCollection

        protected void setAllClonesCollection​(Map objects)
        INTERNAL: Used to set the collections of all objects in the UnitOfWork.
        Parameters:
        objects -
      • setCloneMapping

        protected void setCloneMapping​(Map cloneMapping)
        INTERNAL: Set the clone mapping. The clone mapping contains clone of all registered objects, this is required to store the original state of the objects when registered so that only what is changed will be committed to the database and the parent, (this is required to support parallel unit of work).
      • setContainerBeans

        protected void setContainerBeans​(Map containerBeans)
        INTERNAL: This is only used for EJB entity beans to manage beans accessed in a transaction context.
      • setContainerUnitOfWork

        protected void setContainerUnitOfWork​(UnitOfWorkImpl containerUnitOfWork)
        INTERNAL: This is only used for EJB entity beans to manage beans accessed in a transaction context.
      • setDead

        public void setDead()
        INTERNAL: set UoW lifecycle state variable to DEATH
      • setDeletedObjects

        protected void setDeletedObjects​(Map deletedObjects)
        INTERNAL: The deleted objects stores any objects removed during the unit of work. On commit they will all be removed from the database.
      • setLifecycle

        protected void setLifecycle​(int lifecycle)
        INTERNAL: The life cycle tracks if the unit of work is active and is used for JTS.
      • setMergeManager

        public void setMergeManager​(MergeManager mergeManager)
        INTERNAL: A reference to the last used merge manager. This is used to track locked objects.
      • setNewObjectsCloneToOriginal

        protected void setNewObjectsCloneToOriginal​(Map newObjects)
        INTERNAL: The new objects stores any objects newly created during the unit of work. On commit they will all be inserted into the database.
      • setupPrimaryKeyToNewObjects

        protected void setupPrimaryKeyToNewObjects()
        INTERNAL: Create the map of primary key to new objects used to speed up in-memory querying.
      • addNewObjectToPrimaryKeyToNewObjects

        protected void addNewObjectToPrimaryKeyToNewObjects​(Object newObject)
        INTERNAL: Extracts the primary key from a new object and puts it in primaryKeyToNewObjects.
      • addNewObjectToPrimaryKeyToNewObjects

        protected void addNewObjectToPrimaryKeyToNewObjects​(Object newObject,
                                                            ClassDescriptor descriptor)
        INTERNAL: Extracts the primary key from a new object and puts it in primaryKeyToNewObjects. Allows passing of the ClassDescriptor.
      • removeObjectFromPrimaryKeyToNewObjects

        protected void removeObjectFromPrimaryKeyToNewObjects​(Object object)
        INTERNAL: Extracts the primary key and removes an object from primaryKeyToNewObjects.
      • removeObjectFromPrimaryKeyToNewObjects

        protected void removeObjectFromPrimaryKeyToNewObjects​(Object object,
                                                              Object primaryKey)
        INTERNAL: Removes an object from primaryKeyToNewObjects.
      • setNewObjectsOriginalToClone

        protected void setNewObjectsOriginalToClone​(Map newObjects)
        INTERNAL: The new objects stores any objects newly created during the unit of work. On commit they will all be inserted into the database.
      • setObjectsDeletedDuringCommit

        public void setObjectsDeletedDuringCommit​(Map deletedObjects)
        INTERNAL: Set the objects that have been deleted.
      • setParent

        public void setParent​(AbstractSession parent)
        INTERNAL: Set the parent. This is a unit of work if nested, otherwise a database session or client session.
      • setPendingMerge

        public void setPendingMerge()
        INTERNAL: set UoW lifecycle state variable to PENDING_MERGE
      • setPreDeleteComplete

        public void setPreDeleteComplete​(boolean preDeleteComplete)
        Parameters:
        preDeleteComplete - the preDeleteComplete to set
      • setReadOnlyClasses

        public void setReadOnlyClasses​(List<Class> classes)
        INTERNAL: Gives a new set of read-only classes to the receiver. This set of classes given are checked that subclasses of a read-only class are also in the read-only set provided.
      • setRemovedObjects

        protected void setRemovedObjects​(Map removedObjects)
        INTERNAL: The removed objects stores any newly registered objects removed during the nested unit of work. On commit they will all be removed from the parent unit of work.
      • setResumeUnitOfWorkOnTransactionCompletion

        public void setResumeUnitOfWorkOnTransactionCompletion​(boolean resumeUnitOfWork)
        INTERNAL: Set if this UnitofWork should be resumed after the end of the transaction Used when UnitOfWork is synchronized with external transaction control
      • shouldDiscoverNewObjects

        public boolean shouldDiscoverNewObjects()
        INTERNAL: Set if this UnitofWork should discover new objects on commit.
      • setShouldDiscoverNewObjects

        public void setShouldDiscoverNewObjects​(boolean shouldDiscoverNewObjects)
        INTERNAL: Set if this UnitofWork should discover new objects on commit.
      • setShouldCascadeCloneToJoinedRelationship

        public void setShouldCascadeCloneToJoinedRelationship​(boolean shouldCascadeCloneToJoinedRelationship)
        INTERNAL: True if the value holder for the joined attribute should be triggered. Required by ejb30 fetch join.
      • shouldForceReadFromDB

        public boolean shouldForceReadFromDB​(ObjectBuildingQuery query,
                                             Object primaryKey)
        INTERNAL: Calculate whether we should read directly from the database to the UOW. This may be necessary in subclasses of UnitOfWork that have special behavior
        See Also:
        RepeatableWriteUnitOfWork
      • setShouldNewObjectsBeCached

        public void setShouldNewObjectsBeCached​(boolean shouldNewObjectsBeCached)
        ADVANCED: By default new objects are not cached until the exist on the database. Occasionally if mergeClone is used on new objects and is required to allow multiple merges on the same new object, then if the new objects are not cached, each mergeClone will be interpretted as a different new object. By setting new objects to be cached mergeClone can be performed multiple times before commit. New objects cannot be cached unless they have a valid assigned primary key before being registered. New object with non-null invalid primary keys such as 0 or '' can cause problems and should not be used with this option.
        Specified by:
        setShouldNewObjectsBeCached in interface UnitOfWork
      • setShouldPerformDeletesFirst

        public void setShouldPerformDeletesFirst​(boolean shouldPerformDeletesFirst)
        ADVANCED: By default deletes are performed last in a unit of work. Sometimes you may want to have the deletes performed before other actions.
        Specified by:
        setShouldPerformDeletesFirst in interface UnitOfWork
      • setShouldThrowConformExceptions

        public void setShouldThrowConformExceptions​(int shouldThrowExceptions)
        ADVANCED: Conforming queries can be set to provide different levels of detail about the exceptions they encounter There are two levels: DO_NOT_THROW_CONFORM_EXCEPTIONS = 0; THROW_ALL_CONFORM_EXCEPTIONS = 1;
        Specified by:
        setShouldThrowConformExceptions in interface UnitOfWork
      • setSmartMerge

        public static void setSmartMerge​(boolean option)
        INTERNAL: Set smart merge flag. This feature is used in WL to merge dependent values without SessionAccessor
      • setSynchronized

        public void setSynchronized​(boolean synched)
        INTERNAL: Set isSynchronized flag to indicate that this session is a synchronized unit of work.
        Overrides:
        setSynchronized in class AbstractSession
      • setUnitOfWorkChangeSet

        public void setUnitOfWorkChangeSet​(UnitOfWorkChangeSet unitOfWorkChangeSet)
        INTERNAL: Sets the current UnitOfWork change set to be the one passed in.
      • setUnregisteredExistingObjects

        protected void setUnregisteredExistingObjects​(Map newUnregisteredExistingObjects)
        INTERNAL: Used to set the unregistered existing objects vector used when validation has been turned off.
        Parameters:
        newUnregisteredExistingObjects - Map
      • setUnregisteredNewObjects

        protected void setUnregisteredNewObjects​(Map newObjects)
        INTERNAL:
      • setUnregisteredNewObjectsInParent

        protected void setUnregisteredNewObjectsInParent​(Map newObjects)
        INTERNAL:
      • setValidationLevel

        public void setValidationLevel​(int validationLevel)
        ADVANCED: The unit of work performs validations such as, ensuring multiple copies of the same object don't exist in the same unit of work, ensuring deleted objects are not referred after commit, ensures that objects from the parent cache are not referred in the unit of work cache. The level of validation can be increased or decreased for debugging purposes or under advanced situation where the application requires/desires to violate clone identity in the unit of work. It is strongly suggested that clone identity not be violate in the unit of work.
        Specified by:
        setValidationLevel in interface UnitOfWork
      • setWasTransactionBegunPrematurely

        public void setWasTransactionBegunPrematurely​(boolean wasTransactionBegunPrematurely)
        INTERNAL: Set a flag in the root UOW to indicate that a pess. locking or non-selecting SQL query was executed and forced a transaction to be started.
      • shallowMergeClone

        public Object shallowMergeClone​(Object rmiClone)
        PUBLIC: Merge the attributes of the clone into the unit of work copy. This can be used for objects that are returned from the client through RMI serialization (or other serialization mechanisms), because the RMI object will be a clone this will merge its attributes correctly to preserve object identity within the unit of work and record its changes. Only direct attributes are merged.
        Specified by:
        shallowMergeClone in interface UnitOfWork
        Returns:
        the registered version for the clone being merged.
        See Also:
        mergeClone(Object), deepMergeClone(Object)
      • shallowUnregisterObject

        public void shallowUnregisterObject​(Object clone)
        ADVANCED: Unregister the object with the unit of work. This can be used to delete an object that was just created and is not yet persistent. Delete object can also be used, but will result in inserting the object and then deleting it. The method will only unregister the clone, none of its parts.
        Specified by:
        shallowUnregisterObject in interface UnitOfWork
      • shouldCascadeCloneToJoinedRelationship

        public boolean shouldCascadeCloneToJoinedRelationship()
        INTERNAL: True if the value holder for the joined attribute should be triggered. Required by ejb30 fetch join.
      • shouldNewObjectsBeCached

        public boolean shouldNewObjectsBeCached()
        ADVANCED: By default new objects are not cached until the exist on the database. Occasionally if mergeClone is used on new objects and is required to allow multiple merges on the same new object, then if the new objects are not cached, each mergeClone will be interpretted as a different new object. By setting new objects to be cached mergeClone can be performed multiple times before commit. New objects cannot be cached unless they have a valid assigned primary key before being registered. New object with non-null invalid primary keys such as 0 or '' can cause problems and should not be used with this option.
        Specified by:
        shouldNewObjectsBeCached in interface UnitOfWork
      • shouldValidateExistence

        public boolean shouldValidateExistence()
        Return the default to determine if does-exist should be performed on persist.
      • setShouldValidateExistence

        public void setShouldValidateExistence​(boolean shouldValidateExistence)
        Set the default to determine if does-exist should be performed on persist.
      • shouldPerformDeletesFirst

        public boolean shouldPerformDeletesFirst()
        ADVANCED: By default all objects are inserted and updated in the database before any object is deleted. If this flag is set to true, deletes will be performed before inserts and updates
        Specified by:
        shouldPerformDeletesFirst in interface UnitOfWork
      • shouldPerformFullValidation

        public boolean shouldPerformFullValidation()
        ADVANCED: The unit of work performs validations such as, ensuring multiple copies of the same object don't exist in the same unit of work, ensuring deleted objects are not referred after commit, ensures that objects from the parent cache are not refered in the unit of work cache. The level of validation can be increased or decreased for debugging purposes or under advanced situation where the application requires/desires to violate clone identity in the unit of work. It is strongly suggested that clone identity not be violate in the unit of work.
        Specified by:
        shouldPerformFullValidation in interface UnitOfWork
      • shouldPerformNoValidation

        public boolean shouldPerformNoValidation()
        ADVANCED: The unit of work performs validations such as, ensuring multiple copies of the same object don't exist in the same unit of work, ensuring deleted objects are not referred after commit, ensures that objects from the parent cache are not refered in the unit of work cache. The level of validation can be increased or decreased for debugging purposes or under advanced situation where the application requires/desires to violate clone identity in the unit of work. It is strongly suggested that clone identity not be violated in the unit of work.
        Specified by:
        shouldPerformNoValidation in interface UnitOfWork
      • shouldPerformPartialValidation

        public boolean shouldPerformPartialValidation()
        ADVANCED: The unit of work performs validations such as, ensuring multiple copies of the same object don't exist in the same unit of work, ensuring deleted objects are not refered after commit, ensures that objects from the parent cache are not refered in the unit of work cache. The level of validation can be increased or decreased for debugging purposes or under advanced situation where the application requires/desires to violate clone identity in the unit of work. It is strongly suggested that clone identity not be violate in the unit of work.
        Specified by:
        shouldPerformPartialValidation in interface UnitOfWork
      • shouldResumeUnitOfWorkOnTransactionCompletion

        public boolean shouldResumeUnitOfWorkOnTransactionCompletion()
        INTERNAL: Returns true if this UnitofWork should be resumed after the end of the transaction Used when UnitOfWork is synchronized with external transaction control
      • shouldStoreBypassCache

        public boolean shouldStoreBypassCache()
        INTERNAL: This is a JPA setting that is off by default in regular EclipseLink. It's used to avoid updating the shared cache when the cacheStoreMode property is set to BYPASS.
        See Also:
        RepeatableWriteUnitOfWork
      • storeModifyAllQuery

        public void storeModifyAllQuery​(DatabaseQuery query)
        INTERNAL: Store the ModifyAllQuery's from the UoW in the list. They are always deferred to commit time
      • storeDeferredModifyAllQuery

        public void storeDeferredModifyAllQuery​(DatabaseQuery query,
                                                AbstractRecord translationRow)
        INTERNAL: Store the deferred UpdateAllQuery's from the UoW in the list for execution.
      • synchronizeAndResume

        public void synchronizeAndResume()
        INTERNAL Synchronize the clones and update their backup copies. Called after commit and commit and resume.
      • resumeUnitOfWork

        public void resumeUnitOfWork()
        INTERNAL: Resume the unit of work state after a flush, or resume operation. This will occur on commitAndResume, JPA commit and JPA flush.
      • undeleteObject

        protected void undeleteObject​(Object object)
        INTERNAL: This method is used to transition an object from the deleted objects list to be simply be register.
      • unregisterObject

        public void unregisterObject​(Object clone)
        PUBLIC: Unregister the object with the unit of work. This can be used to delete an object that was just created and is not yet persistent. Delete object can also be used, but will result in inserting the object and then deleting it. The method will only unregister the object and its privately owned parts
        Specified by:
        unregisterObject in interface UnitOfWork
      • unregisterObject

        public void unregisterObject​(Object clone,
                                     int cascadeDepth)
        INTERNAL: Unregister the object with the unit of work. This can be used to delete an object that was just created and is not yet persistent. Delete object can also be used, but will result in inserting the object and then deleting it.
      • unregisterObject

        public void unregisterObject​(Object clone,
                                     int cascadeDepth,
                                     boolean forDetach)
        INTERNAL: Unregister the object with the unit of work. This can be used to delete an object that was just created and is not yet persistent. Delete object can also be used, but will result in inserting the object and then deleting it.
      • updateChangeTrackersIfRequired

        public void updateChangeTrackersIfRequired​(Object objectToWrite,
                                                   ObjectChangeSet changeSetToWrite,
                                                   UnitOfWorkImpl uow,
                                                   ClassDescriptor descriptor)
        INTERNAL: This method is used internally to update the tracked objects if required
      • updateDerivedIds

        protected Object updateDerivedIds​(Object clone,
                                          ClassDescriptor descriptor)
        INTERNAL: On persist and flush operations we must update any derived id fields.
      • validateObjectSpace

        public void validateObjectSpace()
        ADVANCED: This can be used to help debugging an object-space corruption. An object-space corruption is when your application has incorrectly related a clone to an original object. This method will validate that all registered objects are in a correct state and throw an error if not, it will contain the full stack of object references in the error message. If you call this method after each register or change you perform it will pin-point where the error was made.
        Specified by:
        validateObjectSpace in interface UnitOfWork
      • wasTransactionBegunPrematurely

        public boolean wasTransactionBegunPrematurely()
        INTERNAL: Indicates if a transaction was begun by a pessimistic locking or non-selecting query. Traverse to the root UOW to get value.
      • writeChanges

        public void writeChanges()
        ADVANCED: Writes all changes now before commit(). The commit process will begin and all changes will be written out to the datastore, but the datastore transaction will not be committed, nor will changes be merged into the global cache.

        A subsequent commit (on UnitOfWork or global transaction) will be required to finalize the commit process.

        As the commit process has begun any attempt to register objects, or execute object-level queries will generate an exception. Report queries, non-caching queries, and data read/modify queries are allowed.

        On exception any global transaction will be rolled back or marked rollback only. No recovery of this UnitOfWork will be possible.

        Can only be called once. It can not be used to write out changes in an incremental fashion.

        Use to partially commit a transaction outside of a JTA transaction's callbacks. Allows you to get back any exception directly.

        Use to commit a UnitOfWork in two stages.

        Specified by:
        writeChanges in interface UnitOfWork
      • writesCompleted

        public void writesCompleted()
        INTERNAL: This method notifies the accessor that a particular sets of writes has completed. This notification can be used for such thing as flushing the batch mechanism
        Overrides:
        writesCompleted in class AbstractSession
      • getBatchQueries

        public Map<ReadQuery,​ReadQuery> getBatchQueries()
        INTERNAL: When in transaction batch read objects must use query local to the unit of work.
      • setBatchQueries

        public void setBatchQueries​(Map<ReadQuery,​ReadQuery> batchQueries)
        INTERNAL: When in transaction batch read objects must use query local to the unit of work.
      • getPessimisticLockedObjects

        public Map getPessimisticLockedObjects()
        INTERNAL:
      • addToChangeTrackedHardList

        public void addToChangeTrackedHardList​(Object obj)
      • addPessimisticLockedClone

        public void addPessimisticLockedClone​(Object clone)
        INTERNAL:
      • addPrivateOwnedObject

        public void addPrivateOwnedObject​(DatabaseMapping mapping,
                                          Object privateOwnedObject)
        INTERNAL: Add a privately owned object to the privateOwnedObjectsMap. The UnitOfWork needs to keep track of privately owned objects in order to detect and remove private owned objects which are de-referenced.
      • isPessimisticLocked

        public boolean isPessimisticLocked​(Object clone)
        INTERNAL: Return if the clone has been pessimistic locked in this unit of work.
      • hasPessimisticLockedObjects

        public boolean hasPessimisticLockedObjects()
        INTERNAL: Return true if there are any pessimistic locked objects in this unit of work, false otherwise.
      • isPreDeleteComplete

        public boolean isPreDeleteComplete()
        Returns:
        the preDeleteComplete
      • setWasNonObjectLevelModifyQueryExecuted

        public void setWasNonObjectLevelModifyQueryExecuted​(boolean wasNonObjectLevelModifyQueryExecuted)
        INTERNAL: True if either DataModifyQuery or ModifyAllQuery was executed. In absense of transaction the query execution starts one, therefore the flag may only be true in transaction, it's reset on commit or rollback.
      • wasNonObjectLevelModifyQueryExecuted

        public boolean wasNonObjectLevelModifyQueryExecuted()
        INTERNAL: True if either DataModifyQuery or ModifyAllQuery was executed.
      • shouldReadFromDB

        public boolean shouldReadFromDB()
        INTERNAL: Indicates whether readObject should return the object read from the db in case there is no object in uow cache (as opposed to fetching the object from parent's cache). Note that wasNonObjectLevelModifyQueryExecuted()==true implies inTransaction()==true.
      • clear

        public void clear​(boolean shouldClearCache)
        INTERNAL: This method will clear all registered objects from this UnitOfWork. If parameter value is 'true' then the cache(s) are cleared, too.
      • clearForClose

        public void clearForClose​(boolean shouldClearCache)
        INTERNAL: Call this method if the uow will no longer be used for committing transactions: all the change sets will be dereferenced, and (optionally) the cache cleared. If the uow is not released, but rather kept around for ValueHolders, then identity maps shouldn't be cleared: the parameter value should be 'false'. The lifecycle set to Birth so that uow ValueHolder still could be used. Alternatively, if called from release method then everything should go and therefore parameter value should be 'true'. In this case lifecycle won't change - uow.release (optionally) calls this method when it (uow) is already dead. The reason for calling this method from release is to free maximum memory right away: the uow might still be referenced by objects using UOWValueHolders (though they shouldn't be around they still might). We defer a clear() call to release() if the uow lifecycle is 1,2 or 4 (*Pending).
      • shouldClearForCloseOnRelease

        public boolean shouldClearForCloseOnRelease()
        INTERNAL: Indicates whether clearForClose method should be called by release method.
      • createMap

        protected Map createMap()
        This method is used internally to create a map to hold the persistenceContexts. A weak map is returned if ReferenceMode is weak.
      • createMap

        protected Map createMap​(int size)
        This method is used internally to create a map to hold the persistenceContexts. A weak map is returned if ReferenceMode is weak.
        Parameters:
        size -
      • cloneMap

        protected Map cloneMap​(Map map)
        This method is used internally to clone a map that holds the persistenceContexts. A weak map is returned if ReferenceMode is weak.
      • getChangeTrackedHardList

        public Set<Object> getChangeTrackedHardList()
        INTERNAL: Return the list of object with changes. This is used in weak reference mode to avoid garbage collection of changed objects.
      • getReference

        public Object getReference​(Class theClass,
                                   Object id)
        Get an instance, whose state may be lazily fetched. If the requested instance does not exist in the database, null is returned, or the object will fail when accessed. The instance will be lazy when it does not exist in the cache, and supports fetch groups.
        Specified by:
        getReference in interface UnitOfWork
        Parameters:
        id - The primary key of the object, either as a List, singleton, IdClass or an instance of the object.
      • verifyMutexThreadIntegrityBeforeRelease

        public boolean verifyMutexThreadIntegrityBeforeRelease()
        INTERNAL: 272022: Avoid releasing locks on the wrong server thread. If the current thread and the active thread on the mutex do not match - switch them Before we release acquired locks (do the same as we do for mergeClonesBeforeCompletion()) Check that the current thread is the active thread on all lock managers by checking the cached lockThread on the mergeManager. If we find that these 2 threads are different - then all threads in the acquired locks list are different. Switch the activeThread on the mutex to this current thread for each lock.
        Returns:
        true if threads were switched
      • getDeletionDependencies

        public Map<Object,​Set<Object>> getDeletionDependencies()
        INTERNAL: Return deleted objects that have reference to other deleted objects. This is need to delete cycles of objects in the correct order.
      • addDeletionDependency

        public void addDeletionDependency​(Object target,
                                          Object source)
        INTERNAL: Record deleted objects that have reference to other deleted objects. This is need to delete cycles of objects in the correct order.
      • getDeletionDependencies

        public Set<Object> getDeletionDependencies​(Object deletedObject)
        INTERNAL: Return references to other deleted objects for this deleted object. This is need to delete cycles of objects in the correct order.