Class VersionLockingPolicy

    • Constructor Detail

      • VersionLockingPolicy

        public VersionLockingPolicy()
        PUBLIC: Create a new VersionLockingPolicy. Defaults to storing the lock value in the cache.
      • VersionLockingPolicy

        public VersionLockingPolicy​(String fieldName)
        PUBLIC: Create a new VersionLockingPolicy. Defaults to storing the lock value in the cache.
        Parameters:
        fieldName - specifies the field name for the write lock field.
      • VersionLockingPolicy

        public VersionLockingPolicy​(DatabaseField field)
        PUBLIC: Create a new VersionLockingPolicy. Defaults to storing the lock value in the cache.
        Parameters:
        field - the write lock field.
    • Method Detail

      • addLockValuesToTranslationRow

        public void addLockValuesToTranslationRow​(ObjectLevelModifyQuery query)
        INTERNAL: This method adds the lock value to the translation row of the passed in query. depending on the storage flag, the value is either retrieved from the cache of the object.
        Specified by:
        addLockValuesToTranslationRow in interface OptimisticLockingPolicy
      • buildExpression

        protected Expression buildExpression()
        INTERNAL: Returns an expression that will be used for both the update and delete where clause
      • compareWriteLockValues

        public int compareWriteLockValues​(Object value1,
                                          Object value2)
        INTERNAL: This method compares two writeLockValues. The writeLockValues should be non-null and of type Number. Returns: -1 if value1 is less (older) than value2; 0 if value1 equals value2; 1 if value1 is greater (newer) than value2. Throws: NullPointerException if the passed value is null; ClassCastException if the passed value is of a wrong type.
        Specified by:
        compareWriteLockValues in interface OptimisticLockingPolicy
      • getDefaultLockingFieldType

        protected Class getDefaultLockingFieldType()
        INTERNAL: Return the default version locking filed java type, default is BigDecimal
      • getBaseValue

        public Object getBaseValue()
        INTERNAL: This is the base value that is older than all other values, it is used in the place of null in some situations.
        Specified by:
        getBaseValue in interface OptimisticLockingPolicy
      • getInitialWriteValue

        protected Object getInitialWriteValue​(AbstractSession session)
        INTERNAL: returns the initial locking value
      • getLockOnChangeMode

        public OptimisticLockingPolicy.LockOnChange getLockOnChangeMode()
        ADVANCED: returns the LockOnChange mode for this policy. This mode specifies if a Optimistic Write lock should be enforced on this entity when a set of mappings are changed. Unfortunately this locking policy can not enforce an optimistic write lock unless a FK or DTF field has changed so this type returns LockOnChange.NONE
        Specified by:
        getLockOnChangeMode in interface OptimisticLockingPolicy
      • getNewLockValue

        public Object getNewLockValue​(ModifyQuery query)
        INTERNAL: This method gets the write lock value from either the cache or the object stored in the query. It then returns the new incremented value.
      • getUnmappedFields

        protected Vector getUnmappedFields()
        INTERNAL: This method returns any of the fields that are not mapped in the object. In the case of the value being stored in the cache, a vector with one value is returned. In the case of being stored in the object, an empty vector is returned.
      • getVersionDifference

        public int getVersionDifference​(Object currentValue,
                                        Object domainObject,
                                        Object primaryKeys,
                                        AbstractSession session)
        PUBLIC: Return the number of versions different between these objects.
        Specified by:
        getVersionDifference in interface OptimisticLockingPolicy
        Parameters:
        currentValue - the new lock value
        domainObject - the object containing the version to be compared to
        primaryKeys - a vector containing the primary keys of the domainObject
        session - the session to be used with the comparison
      • getWriteLockFieldName

        public String getWriteLockFieldName()
        PUBLIC: Return the field name of the field that stores the write lock value.
      • incrementWriteLockValue

        protected Number incrementWriteLockValue​(Number numberValue)
        INTERNAL: Adds 1 to the value passed in.
      • isNewerVersion

        public boolean isNewerVersion​(Object currentValue,
                                      Object domainObject,
                                      Object primaryKey,
                                      AbstractSession session)
        INTERNAL: Compares the value with the value from the object (or cache). Will return true if the currentValue is newer than the domainObject.
        Specified by:
        isNewerVersion in interface OptimisticLockingPolicy
      • isNewerVersion

        public boolean isNewerVersion​(Object firstLockFieldValue,
                                      Object secondWriteLockFieldValue)
        INTERNAL: Compares two values. Will return true if the firstLockFieldValue is newer than the secondWriteLockFieldValue.
      • isStoredInObject

        public boolean isStoredInObject()
        PUBLIC: Return true if the lock value is stored in the object.
      • lockValueFromObject

        protected Object lockValueFromObject​(Object domainObject)
        INTERNAL: Retrieves the lock value from the object.
      • getVersionMapping

        public AbstractDirectMapping getVersionMapping()
        INTERNAL: Returns the mapping that will be used to access the version value from an object.
      • mergeIntoParentCache

        public void mergeIntoParentCache​(CacheKey unitOfWorkCacheKey,
                                         CacheKey parentSessionCacheKey)
        INTERNAL: This method should merge changes from the parent into the child. #see this method in VersionLockingPolicy
        Specified by:
        mergeIntoParentCache in interface OptimisticLockingPolicy
      • setIsStoredInCache

        public void setIsStoredInCache​(boolean isStoredInCache)
        PUBLIC: Set whether to store the lock in the cache or in the object.
        Parameters:
        isStoredInCache - set this to true if you would like to store lock in the cache and set it to false if you would like to store it in the object.
      • setIsCascaded

        public void setIsCascaded​(boolean isCascaded)
        PUBLIC: Set whether to use cascade locking on the policy.
        Parameters:
        isCascaded - set this to true if you would like cascade the locking and set it to false if you would like no cascade locking.
      • updateWriteLockValueForWrite

        protected void updateWriteLockValueForWrite​(ObjectLevelModifyQuery query,
                                                    Object lockValue)
        INTERNAL: Update the row, object and change set with the version value. This handles the version being mapped in nested aggregates, writable or read-only.
      • shouldUpdateVersionOnMappingChange

        public boolean shouldUpdateVersionOnMappingChange()
        INTERNAL: Returns true if the policy has been set to set an optimistic read lock when any mapping changes.
        Specified by:
        shouldUpdateVersionOnMappingChange in interface OptimisticLockingPolicy
      • setWriteLockField

        public void setWriteLockField​(DatabaseField writeLockField)
        ADVANCED: Set the write lock field. This can be used for advanced field types, such as XML nodes, or to set the field type.
      • setWriteLockFieldName

        public void setWriteLockFieldName​(String writeLockFieldName)
        PUBLIC: Set the write lock field name.
        Parameters:
        writeLockFieldName - the name of the field to lock against.
      • storeInCache

        public void storeInCache()
        PUBLIC: Configure the version lock value to be stored in the cache. This allows for the object not to require to store its version value as an attribute. Note: if using a stateless model where the object can be passed to a client and then later updated in a different transaction context, then the version lock value should not be stored in the cache, but in the object to ensure it is the correct value for that object. This is the default.
      • storeInObject

        public void storeInObject()
        PUBLIC: Configure the version lock value to be stored in the object. The object must define a mapping and an attribute to store the version value. Note: the value will be updated internally by EclipseLink and should not be updated by the application.
      • writeLockValueIntoRow

        public void writeLockValueIntoRow​(ObjectLevelModifyQuery query,
                                          Object domainObject)
        INTERNAL: This method updates the modify row with the old lock value.