Class FieldsLockingPolicy

    • Constructor Detail

      • FieldsLockingPolicy

        public FieldsLockingPolicy()
        PUBLIC: Create a new field locking policy. A field locking policy is based on locking on a subset of fields by comparing with their previous values to detect field-level collisions. Note: the unit of work must be used for all updates when using field locking.
    • Method Detail

      • buildAllNonPrimaryKeyFields

        protected List buildAllNonPrimaryKeyFields()
        INTERNAL: Returns the fields that should be compared in the where clause. In this case, it is all the fields, except for the primary key and class indicator fields. This is called during lazy initialization.
      • supportsWriteLockValuesComparison

        public boolean supportsWriteLockValuesComparison()
        INTERNAL: Indicates whether compareWriteLockValues method is supported by the policy. Numeric or timestamp lock values could be compared: for every pair of values v1 and v2 - either v1<v2; or v1==v2; or v1>v2. However it's impossible to compare values for FieldsLockingPolicy for two reasons: 1. there is no "linear order": v1<v2 and v>v2 is not defined: either v1==v2 or v1!=v2; 2. locking value is not a single field which is not part of mapped object value but rather a set of object's mapped fields. That means any object's mapped attribute change is potentially a change of the locking value. For ChangedFieldsLockingPolicy every mapped attribute's change is a change of locking value. The pattern used by versioning: "if the original locking value is unchanged then the object hasn't been changed outside of the application", which allows to distinguish between the change made inside and outside the application, doesn't work for fields locking. It degenerates into useless pattern: "if the original locking value is unchanged then the object hasn't been changed". Use compareWriteLockValues method only if this method returns true.
        Specified by:
        supportsWriteLockValuesComparison in interface OptimisticLockingPolicy
      • compareWriteLockValues

        public int compareWriteLockValues​(Object value1,
                                          Object value2)
        INTERNAL: This method shouldn't be called if supportsWriteLockValuesComparison() returns false. This method compares two writeLockValues. The writeLockValues should be non-null and of the correct type. 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
      • getAllNonPrimaryKeyFields

        protected List<DatabaseField> getAllNonPrimaryKeyFields()
        INTERNAL: Returns the fields that should be compared in the where clause. In this case, it is all the fields, except for the primary key and class indicator field.
      • getAllNonPrimaryKeyFields

        protected List<DatabaseField> getAllNonPrimaryKeyFields​(DatabaseTable table)
        INTERNAL: filter the fields based on the passed in table. Only return fields of this table.
      • 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
      • 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
      • isCascaded

        public boolean isCascaded()
        PUBLIC: Return true if the policy uses cascade locking. Currently, not supported on this policy at this time.
        Specified by:
        isCascaded in interface OptimisticLockingPolicy
      • isPrimaryKey

        protected boolean isPrimaryKey​(DatabaseField dbField)
        INTERNAL: Returns whether or not this field is a primary key. This method will also return true for secondary table primarykeys
      • 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
      • setAllNonPrimaryKeyFields

        protected void setAllNonPrimaryKeyFields​(List allNonPrimaryKeyFields)
        INTERNAL: Set method for all the primary keys
      • setLockOnChangeMode

        public void setLockOnChangeMode​(OptimisticLockingPolicy.LockOnChange lockOnChangeMode)
        ADVANCED: Sets the LockOnChange mode for this policy. This mode specifies if a Optimistic Write lock should be enforced on this entity when set of mappings are changed. Unfortunately this locking policy can not always force an optimistic lock unless the core fields have changed
        Specified by:
        setLockOnChangeMode in interface OptimisticLockingPolicy
      • shouldUpdateVersionOnOwnedMappingChange

        public boolean shouldUpdateVersionOnOwnedMappingChange()
        INTERNAL: Returns true if the policy has been set to set an optimistic read lock when a owning mapping changes. Unfortunately this locking policy can not always force an optimistic lock unless the core fields have changed
        Specified by:
        shouldUpdateVersionOnOwnedMappingChange in interface OptimisticLockingPolicy
      • shouldUpdateVersionOnMappingChange

        public boolean shouldUpdateVersionOnMappingChange()
        INTERNAL: Returns true if the policy has been set to set an optimistic read lock when any mapping changes. Unfortunately this locking policy can not always force an optimistic lock unless the core fields have changed
        Specified by:
        shouldUpdateVersionOnMappingChange in interface OptimisticLockingPolicy
      • verifyUsage

        protected void verifyUsage​(AbstractSession session)
        INTERNAL: throw an exception if not inside a unit of work at this point