java.lang.Object
org.eclipse.persistence.descriptors.VersionLockingPolicy
org.eclipse.persistence.descriptors.JavaTimeLockingPolicy<T>
- All Implemented Interfaces:
Serializable,Cloneable,org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
- Direct Known Subclasses:
InstantLockingPolicy,LocalDateTimeLockingPolicy
Common
VersionLockingPolicy based on java.time classes
used for optimistic locking.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumTime-stamp source policy.Nested classes/interfaces inherited from interface org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.LockOnChange -
Field Summary
Fields inherited from class org.eclipse.persistence.descriptors.VersionLockingPolicy
cachedExpression, descriptor, IN_CACHE, IN_OBJECT, isCascaded, lockMapping, lockOnChangeMode, lockValueStored, writeLockField -
Constructor Summary
ConstructorsConstructorDescriptionCreates an instance of timestamp version policy used for optimistic locking.JavaTimeLockingPolicy(org.eclipse.persistence.internal.helper.DatabaseField field) Creates an instance of timestamp version policy used for optimistic locking. -
Method Summary
Modifier and TypeMethodDescriptionintcompareWriteLockValues(Object value1, Object value2) INTERNAL: This method compares two writeLockValues.<C> CINTERNAL: Return base value that is older than all other values, it is used in the place ofnullin some situations.protected <C> Class<C> INTERNAL: Return the default timestamp locking filed java type.protected <C> CgetInitialWriteValue(org.eclipse.persistence.internal.sessions.AbstractSession session) INTERNAL: Return initial locking value.<C> CgetNewLockValue(ModifyQuery query) INTERNAL: This method gets the write lock value from either the cache or the object stored in the query.Get time-stamp source policy.<C> CgetValueToPutInCache(org.eclipse.persistence.internal.sessions.AbstractRecord row, org.eclipse.persistence.internal.sessions.AbstractSession session) INTERNAL: Return the value that should be stored in the identity map.getWriteLockUpdateExpression(ExpressionBuilder builder, org.eclipse.persistence.internal.sessions.AbstractSession session) Return an expression that updates the write lock.<C> CgetWriteLockValue(Object domainObject, Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session) INTERNAL: Return the optimistic lock value for the object.protected NumberincrementWriteLockValue(Number value) Time-stamp versioning should not be able to do this.booleanisNewerVersion(Object first, Object second) INTERNAL: Compares two version values.booleanisNewerVersion(Object current, Object domainObject, Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session) Compares the value with the value from the object (or cache).booleanisNewerVersion(org.eclipse.persistence.internal.sessions.AbstractRecord row, Object domainObject, Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session) INTERNAL: Compares two version values from the row and from the object (or cache).voidsetTimeSource(JavaTimeLockingPolicy.TimeSource timeSource) Set time-stamp source policy.Methods inherited from class org.eclipse.persistence.descriptors.VersionLockingPolicy
addLockFieldsToUpdateRow, addLockValuesToTranslationRow, buildDeleteExpression, buildExpression, buildUpdateExpression, clone, getDescriptor, getLockOnChangeMode, getUnmappedFields, getVersion, getVersionDifference, getVersionMapping, getWriteLockField, getWriteLockFieldName, initialize, initializeProperties, isCascaded, isStoredInCache, isStoredInObject, lockValueFromObject, mergeIntoParentCache, mergeIntoParentCache, setDescriptor, setIsCascaded, setIsStoredInCache, setLockOnChangeMode, setupWriteFieldsForInsert, setWriteLockField, setWriteLockFieldName, shouldUpdateVersionOnMappingChange, shouldUpdateVersionOnOwnedMappingChange, storeInCache, storeInObject, supportsWriteLockValuesComparison, updateObjectWithWriteValue, updateRowAndObjectForUpdate, updateWriteLockValueForWrite, validateDelete, validateUpdate, writeLockValueIntoRow
-
Constructor Details
-
JavaTimeLockingPolicy
public JavaTimeLockingPolicy()Creates an instance of timestamp version policy used for optimistic locking. Defaults to using the time retrieved from the server. -
JavaTimeLockingPolicy
public JavaTimeLockingPolicy(org.eclipse.persistence.internal.helper.DatabaseField field) Creates an instance of timestamp version policy used for optimistic locking. Defaults to using the time retrieved from the server.- Parameters:
field- the field where the write lock value will be stored
-
-
Method Details
-
compareWriteLockValues
Description copied from class:VersionLockingPolicyINTERNAL: This method compares two writeLockValues. The writeLockValues should be non-null and ofLocalDateTime,InstantorTimestamptype.- Specified by:
compareWriteLockValuesin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy- Overrides:
compareWriteLockValuesin classVersionLockingPolicy- Parameters:
value1- the 1st value to comparevalue2- the 2nd value to compare- Returns:
-1if value1 is less (older) than value2,0if value1 equals value2,1if value1 is greater (newer) than value2.
-
getDefaultLockingFieldType
Description copied from class:VersionLockingPolicyINTERNAL: Return the default timestamp locking filed java type.- Overrides:
getDefaultLockingFieldTypein classVersionLockingPolicy- Returns:
- the default timestamp locking filed java type
-
getBaseValue
public <C> C getBaseValue()Description copied from class:VersionLockingPolicyINTERNAL: Return base value that is older than all other values, it is used in the place ofnullin some situations.- Specified by:
getBaseValuein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy- Overrides:
getBaseValuein classVersionLockingPolicy- Returns:
- timestamp base value
-
getInitialWriteValue
protected <C> C getInitialWriteValue(org.eclipse.persistence.internal.sessions.AbstractSession session) Description copied from class:VersionLockingPolicyINTERNAL: Return initial locking value.- Overrides:
getInitialWriteValuein classVersionLockingPolicy- Parameters:
session- the database session- Returns:
- the initial locking value
-
getNewLockValue
Description copied from class:VersionLockingPolicyINTERNAL: 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.- Overrides:
getNewLockValuein classVersionLockingPolicy- Parameters:
query- modify query- Returns:
- the new timestamp value
-
getValueToPutInCache
public <C> C getValueToPutInCache(org.eclipse.persistence.internal.sessions.AbstractRecord row, org.eclipse.persistence.internal.sessions.AbstractSession session) Description copied from class:VersionLockingPolicyINTERNAL: Return the value that should be stored in the identity map. If the value is stored in the object, then return a null.- Specified by:
getValueToPutInCachein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy- Overrides:
getValueToPutInCachein classVersionLockingPolicy- Parameters:
row- the data row, e.g. database rowsession- the database session- Returns:
- the value that should be stored in the identity map
-
getWriteLockValue
public <C> C getWriteLockValue(Object domainObject, Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session) Description copied from class:VersionLockingPolicyINTERNAL: Return the optimistic lock value for the object.- Specified by:
getWriteLockValuein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy- Overrides:
getWriteLockValuein classVersionLockingPolicy- Parameters:
domainObject- the domain object (entity instance)primaryKey- the primary keysession- the database session- Returns:
- the optimistic lock value for the object
-
isNewerVersion
public boolean isNewerVersion(Object current, Object domainObject, Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session) Compares the value with the value from the object (or cache). Will return true if the currentValue is newer than the domainObject.- Specified by:
isNewerVersionin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy- Overrides:
isNewerVersionin classVersionLockingPolicy- Parameters:
current- the current valuedomainObject- the domain object (entity instance)primaryKey- the primary keysession- the database session- Returns:
- value of
trueif thefirstis newer than thesecondorfalseotherwise
-
isNewerVersion
public boolean isNewerVersion(org.eclipse.persistence.internal.sessions.AbstractRecord row, Object domainObject, Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session) Description copied from class:VersionLockingPolicyINTERNAL: Compares two version values from the row and from the object (or cache).- Specified by:
isNewerVersionin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy- Overrides:
isNewerVersionin classVersionLockingPolicy- Parameters:
row- the data row, e.g. database rowdomainObject- the domain object (entity instance)primaryKey- the primary keysession- the database session- Returns:
- value of
trueif thefirstis newer than thesecondorfalseotherwise
-
isNewerVersion
Description copied from class:VersionLockingPolicyINTERNAL: Compares two version values. Will return true if the firstLockFieldValue is newer than the secondWriteLockFieldValue.- Overrides:
isNewerVersionin classVersionLockingPolicy- Parameters:
first- first version valuesecond- second version value- Returns:
- value of
trueif thefirstis newer than thesecondorfalseotherwise
-
getWriteLockUpdateExpression
public Expression getWriteLockUpdateExpression(ExpressionBuilder builder, org.eclipse.persistence.internal.sessions.AbstractSession session) Return an expression that updates the write lock.- Specified by:
getWriteLockUpdateExpressionin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy- Overrides:
getWriteLockUpdateExpressionin classVersionLockingPolicy- Parameters:
builder- the expression buildersession- the database session
-
incrementWriteLockValue
Time-stamp versioning should not be able to do this. Override the superclass behavior.- Overrides:
incrementWriteLockValuein classVersionLockingPolicy- Parameters:
value- the source value
-
setTimeSource
Set time-stamp source policy.- Parameters:
timeSource- set this policy to retrieve the time-stamp from the server when set toJavaTimeLockingPolicy.TimeSource.Serveror from the local machine when set toJavaTimeLockingPolicy.TimeSource.Local
-
getTimeSource
Get time-stamp source policy.- Returns:
- the time-stamp source policy
-