java.lang.Object
org.eclipse.persistence.descriptors.VersionLockingPolicy
org.eclipse.persistence.descriptors.AbstractTsLockingPolicy<T>
- All Implemented Interfaces:
Serializable,Cloneable,org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
- Direct Known Subclasses:
InstantLockingPolicy,LocalDateTimeLockingPolicy,TimestampLockingPolicy
Common timestamp version policy used for optimistic locking.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.LockOnChange -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intLocal time.static final intTime from the server.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.AbstractTsLockingPolicy(String fieldName) Creates an instance of timestamp version policy used for optimistic locking.AbstractTsLockingPolicy(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.static AbstractTsLockingPolicy<?> AbstractTsLockingPolicy factory method.<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.<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) Timestamp 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) INTERNAL: 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).voidsetUsesServerTime(boolean useServer) Set time source policy.voidSet time source policy to get the time from the local machine.voidSet time source policy to get the time from the server.booleanReturn whether time source policy uses local time.booleanReturn whether time source policy uses server time.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
-
Field Details
-
SERVER_TIME
public static final int SERVER_TIMETime from the server.- See Also:
-
LOCAL_TIME
public static final int LOCAL_TIMELocal time.- See Also:
-
-
Constructor Details
-
AbstractTsLockingPolicy
public AbstractTsLockingPolicy()Creates an instance of timestamp version policy used for optimistic locking. Defaults to using the time retrieved from the server. -
AbstractTsLockingPolicy
Creates an instance of timestamp version policy used for optimistic locking. Defaults to using the time retrieved from the server.- Parameters:
fieldName- the field where the write lock value will be stored
-
AbstractTsLockingPolicy
public AbstractTsLockingPolicy(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
-
create
public static AbstractTsLockingPolicy<?> create(String typeName, org.eclipse.persistence.internal.helper.DatabaseField field) AbstractTsLockingPolicy factory method.- Parameters:
typeName- rawMetadataClassnamefield- version field
-
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) 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:
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
Timestamp versioning should not be able to do this. Override the superclass behavior.- Overrides:
incrementWriteLockValuein classVersionLockingPolicy- Parameters:
value- the source value
-
setUsesServerTime
public void setUsesServerTime(boolean useServer) Set time source policy.- Parameters:
useServer- set this policy to get the time from the server whentrueor from the local machine whenfalse
-
useLocalTime
public void useLocalTime()Set time source policy to get the time from the local machine. -
useServerTime
public void useServerTime()Set time source policy to get the time from the server. -
usesLocalTime
public boolean usesLocalTime()Return whether time source policy uses local time.- Returns:
- value of
truewhen policy uses local time orfalseotherwise.
-
usesServerTime
public boolean usesServerTime()Return whether time source policy uses server time.- Returns:
- value of
truewhen policy uses server time orfalseotherwise.
-