Class RepeatableWriteUnitOfWork

    • Field Detail

      • cumulativeUOWChangeSet

        protected UnitOfWorkChangeSet cumulativeUOWChangeSet
        Used to store the final UnitOfWorkChangeSet for merge into the shared cache
      • shouldTerminateTransaction

        protected boolean shouldTerminateTransaction
        Used to determine if UnitOfWork should commit and rollback transactions. This is used when an EntityTransaction is controlling the transaction.
      • shouldStoreBypassCache

        protected boolean shouldStoreBypassCache
        Used to determine if we should bypass any merge into the cache. This is a JPA flag and is true when the cacheStoreMode property is set to BYPASS. Otherwise, EclipseLink behaves as it usually would.
      • flushClearCache

        protected transient String flushClearCache
        The FlashClearCache mode to be used. Initialized by setUnitOfWorkChangeSet method in case it's null; commitAndResume sets this attribute back to null. Relevant only in case call to flush method followed by call to clear method.
        See Also:
        FlushClearCache
      • isWithinFlush

        protected boolean isWithinFlush
        Track whether we are already in a flush().
      • classesToBeInvalidated

        protected transient Set<ClassDescriptor> classesToBeInvalidated
        Contains classes that should be invalidated in the shared cache on commit. Used only in case fushClearCache == FlushClearCache.DropInvalidate: clear method copies contents of updatedObjectsClasses to this set, adding classes of deleted objects, too; on commit the classes contained here are invalidated in the shared cache and the set is cleared. Relevant only in case call to flush method followed by call to clear method. Works together with flushClearCache.
      • discoverUnregisteredNewObjectsWithoutPersist

        protected boolean discoverUnregisteredNewObjectsWithoutPersist
        Alters the behaviour of the RWUOW commit to function like the UOW with respect to Entity lifecycle
    • Constructor Detail

      • RepeatableWriteUnitOfWork

        public RepeatableWriteUnitOfWork()
    • Method Detail

      • shouldDiscoverUnregisteredNewObjectsWithoutPersist

        public boolean shouldDiscoverUnregisteredNewObjectsWithoutPersist()
        Returns:
        the discoverUnregisteredNewObjectsWithoutPersist
      • setDiscoverUnregisteredNewObjectsWithoutPersist

        public void setDiscoverUnregisteredNewObjectsWithoutPersist​(boolean discoverUnregisteredNewObjectsWithoutPersist)
        Parameters:
        discoverUnregisteredNewObjectsWithoutPersist - the discoverUnregisteredNewObjectsWithoutPersist to set
      • 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.
        Overrides:
        clear in class UnitOfWorkImpl
      • clearForClose

        public void clearForClose​(boolean shouldClearCache)
        INTERNAL: Call this method if the uow will no longer used for committing transactions: all the changes 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).
        Overrides:
        clearForClose in class UnitOfWorkImpl
      • getClassesToBeInvalidated

        public Set<ClassDescriptor> getClassesToBeInvalidated()
        INTERNAL: Return classes that should be invalidated in the shared cache on commit. Used only in case fushClearCache == FlushClearCache.DropInvalidate: clear method copies contents of updatedObjectsClasses to this set, adding classes of deleted objects, too; on commit the classes contained here are invalidated in the shared cache and the set is cleared. Relevant only in case call to flush method followed by call to clear method. Works together with flushClearCache.
      • getCumulativeUOWChangeSet

        public UnitOfWorkChangeSet getCumulativeUOWChangeSet()
        INTERNAL: Get the final UnitOfWorkChangeSet for merge into the shared cache.
      • setCumulativeUOWChangeSet

        public void setCumulativeUOWChangeSet​(UnitOfWorkChangeSet cumulativeUOWChangeSet)
        INTERNAL: Set the final UnitOfWorkChangeSet for merge into the shared cache.
      • shouldForceReadFromDB

        public boolean shouldForceReadFromDB​(ObjectBuildingQuery query,
                                             Object primaryKey)
        INTERNAL: Calculate whether we should read directly from the database to the UOW. This will be necessary, if a flush and a clear have been called on this unit of work In that case, there will be changes in the database that are not in the shared cache, so a read in this UOW should get info directly form the DB
        Overrides:
        shouldForceReadFromDB in class UnitOfWorkImpl
        See Also:
        RepeatableWriteUnitOfWork
      • shouldClearForCloseOnRelease

        public boolean shouldClearForCloseOnRelease()
        INTERNAL: Indicates whether clearForClose method should be called by release method.
        Overrides:
        shouldClearForCloseOnRelease in class UnitOfWorkImpl
      • checkHierarchyForDescriptor

        protected ClassDescriptor checkHierarchyForDescriptor​(Class theClass)
        Check to see if the descriptor of a superclass can be used to describe this class By default, in JPA, classes must have specific descriptors to be considered entities In this implementation, we check whether the inheritance policy has been configured to allow superclass descriptors to describe subclasses that do not have a descriptor themselves
        Overrides:
        checkHierarchyForDescriptor in class AbstractSession
        Parameters:
        theClass -
        Returns:
        ClassDescriptor
      • discoverUnregisteredNewObjects

        public void discoverUnregisteredNewObjects​(Map clones,
                                                   Map newObjects,
                                                   Map unregisteredExistingObjects,
                                                   Map visitedObjects)
        INTERNAL: Traverse the object to find references to objects not registered in this unit of work. Any unregistered new objects found will be persisted or an error will be thrown depending on the mapping's cascade persist. References to deleted objects will also currently cause them to be undeleted.
        Overrides:
        discoverUnregisteredNewObjects in class UnitOfWorkImpl
      • 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.
        Overrides:
        isAfterWriteChangesButBeforeCommit in class UnitOfWorkImpl
      • isObjectDeleted

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

        public void issueSQLbeforeCompletion()
        INTERNAL: For synchronized units of work, dump SQL to database
        Overrides:
        issueSQLbeforeCompletion in class UnitOfWorkImpl
      • mergeChangesIntoParent

        protected void mergeChangesIntoParent()
        INTERNAL: Merge the changes to all objects to the parent.
        Overrides:
        mergeChangesIntoParent in class UnitOfWorkImpl
      • writeChanges

        public void writeChanges()
        INTERNAL: This will flush all changes to the database, and create or merge into the cumulativeUOWChangeSet.
        Specified by:
        writeChanges in interface UnitOfWork
        Overrides:
        writeChanges in class UnitOfWorkImpl
      • 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
        Overrides:
        registerNewObject in class UnitOfWorkImpl
        See Also:
        UnitOfWorkImpl.registerObject(Object)
      • registerNotRegisteredNewObjectForPersist

        protected void registerNotRegisteredNewObjectForPersist​(Object newObject,
                                                                ClassDescriptor descriptor)
        INTERNAL: Called only by registerNewObjectForPersist method, and only if newObject is not already registered. If newObject is found in unregisteredDeletedObjectsCloneToBackupAndOriginal then it's re-registered, otherwise the superclass method called.
        Overrides:
        registerNotRegisteredNewObjectForPersist in class UnitOfWorkImpl
      • 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 UnitOfWorkImpl
        Throws:
        DatabaseException - if the database connection is lost or the rollback fails.
      • rollbackTransaction

        protected void rollbackTransaction​(boolean intendedToCommitTransaction)
                                    throws DatabaseException
        INTERNAL: This is internal to the uow, transactions should not be used explicitly in a uow. The uow shares its parents transactions. Called in JTA this should not set the transaction to rollback.
        Overrides:
        rollbackTransaction in class UnitOfWorkImpl
        Parameters:
        intendedToCommitTransaction - whether we were inside a commit or just trying to write out changes early.
        Throws:
        DatabaseException
      • synchronizeAndResume

        public void synchronizeAndResume()
        INTERNAL Synchronize the clones and update their backup copies. Called after commit and commit and resume.
        Overrides:
        synchronizeAndResume in class UnitOfWorkImpl
      • wasDeleted

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

        protected Object cloneAndRegisterNewObject​(Object original,
                                                   boolean isShallowClone)
        INTERNAL: To avoid putting the original object into the shared cache, and therefore, impede the 'detaching' of the original after commit, a clone of the original should be registered not the actual original object. This is a JPA override to traditional EclipseLink behavior.
        Overrides:
        cloneAndRegisterNewObject in class UnitOfWorkImpl
        See Also:
        UnitOfWorkImpl.registerObject(Object)
      • getUnregisteredDeletedCloneForOriginal

        public Object getUnregisteredDeletedCloneForOriginal​(Object original)
        INTERNAL: Called only by UnitOfWorkIdentityMapAccessor.getAndCloneCacheKeyFromParent method. Return unregisteredDeletedClone corresponding to the passed original, or null
      • 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 UnitOfWorkImpl
        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.
      • setShouldStoreByPassCache

        public void setShouldStoreByPassCache​(boolean shouldStoreBypassCache)
      • setShouldTerminateTransaction

        public void setShouldTerminateTransaction​(boolean shouldTerminateTransaction)
      • clearFlushClearCache

        public void clearFlushClearCache()
        INTERNAL: Clears invalidation list.
      • getFlushClearCache

        public String getFlushClearCache()
        Return the FlashClearCache mode to be used. Relevant only in case call to flush method followed by call to clear method.
        See Also:
        FlushClearCache
      • setFlushClearCache

        public void setFlushClearCache​(String flushClearCache)
        Set the FlashClearCache mode to be used. Relevant only in case call to flush method followed by call to clear method.
        See Also:
        FlushClearCache
      • isWithinFlush

        public boolean isWithinFlush()
        Return whether we are already performing a flush() call
        Returns: