Class TimestampLockingPolicy
java.lang.Object
org.eclipse.persistence.descriptors.VersionLockingPolicy
org.eclipse.persistence.descriptors.TimestampLockingPolicy
- All Implemented Interfaces:
Serializable
,Cloneable
,org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
Purpose: Used to allow a single version timestamp to be 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
Modifier and TypeFieldDescriptionstatic final int
protected int
static final int
Fields inherited from class org.eclipse.persistence.descriptors.VersionLockingPolicy
cachedExpression, descriptor, IN_CACHE, IN_OBJECT, isCascaded, lockMapping, lockOnChangeMode, lockValueStored, writeLockField
-
Constructor Summary
ConstructorDescriptionPUBLIC: Create a new TimestampLockingPolicy.TimestampLockingPolicy
(String fieldName) PUBLIC: Create a new TimestampLockingPolicy.TimestampLockingPolicy
(org.eclipse.persistence.internal.helper.DatabaseField field) INTERNAL: Create a new TimestampLockingPolicy. -
Method Summary
Modifier and TypeMethodDescriptionint
compareWriteLockValues
(Object value1, Object value2) INTERNAL: This method compares two writeLockValues.INTERNAL: This is the base value that is older than all other values, it is used in the place of null in some situations.protected Class
INTERNAL: Return the default timestamp locking filed java type, default is Timestamp.protected Object
getInitialWriteValue
(org.eclipse.persistence.internal.sessions.AbstractSession session) INTERNAL: returns the initial locking valuegetNewLockValue
(ModifyQuery query) INTERNAL: Returns the new Timestamp value.getValueToPutInCache
(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.int
getVersionDifference
(Object currentValue, Object domainObject, Object primaryKeys, org.eclipse.persistence.internal.sessions.AbstractSession session) INTERNAL: Return the number of versions different between these objects.getWriteLockUpdateExpression
(ExpressionBuilder builder, org.eclipse.persistence.internal.sessions.AbstractSession session) INTERNAL: Return an expression that updates the write lockgetWriteLockValue
(Object domainObject, Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session) INTERNAL: This method will return the optimistic lock value for the object.protected Number
incrementWriteLockValue
(Number numberValue) INTERNAL: Timestamp versioning should not be able to do this.boolean
isNewerVersion
(Object firstLockFieldValue, Object secondWriteLockFieldValue) INTERNAL: Compares two values.boolean
isNewerVersion
(Object currentValue, Object domainObject, Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session) INTERNAL: Compares the value with the value from the object (or cache).boolean
isNewerVersion
(org.eclipse.persistence.internal.sessions.AbstractRecord databaseRow, Object domainObject, Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session) INTERNAL: Compares the value from the row and from the object (or cache).void
setUsesServerTime
(boolean usesServerTime) PUBLIC: Set if policy uses server time.void
PUBLIC: set this policy to get the time from the local machine.void
PUBLIC: set this policy to get the time from the server.boolean
PUBLIC: Return true if policy uses local time.boolean
PUBLIC: Return true if policy uses server time.Methods inherited from class org.eclipse.persistence.descriptors.VersionLockingPolicy
addLockFieldsToUpdateRow, addLockValuesToTranslationRow, buildDeleteExpression, buildExpression, buildUpdateExpression, clone, getDescriptor, getLockOnChangeMode, getUnmappedFields, 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
-
retrieveTimeFrom
protected int retrieveTimeFrom -
SERVER_TIME
public static final int SERVER_TIME- See Also:
-
LOCAL_TIME
public static final int LOCAL_TIME- See Also:
-
-
Constructor Details
-
TimestampLockingPolicy
public TimestampLockingPolicy()PUBLIC: Create a new TimestampLockingPolicy. Defaults to using the time retrieved from the server. -
TimestampLockingPolicy
PUBLIC: Create a new TimestampLockingPolicy. Defaults to using the time retrieved from the server.- Parameters:
fieldName
- the field where the write lock value will be stored.
-
TimestampLockingPolicy
public TimestampLockingPolicy(org.eclipse.persistence.internal.helper.DatabaseField field) INTERNAL: Create a new TimestampLockingPolicy. Defaults to using the time retrieved from the server.- Parameters:
field
- the field where the write lock value will be stored.
-
-
Method Details
-
compareWriteLockValues
INTERNAL: This method compares two writeLockValues. The writeLockValues should be non-null and of type java.sql.Timestamp. 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 interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
- Overrides:
compareWriteLockValues
in classVersionLockingPolicy
-
getDefaultLockingFieldType
INTERNAL: Return the default timestamp locking filed java type, default is Timestamp.- Overrides:
getDefaultLockingFieldType
in classVersionLockingPolicy
-
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 interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
- Overrides:
getBaseValue
in classVersionLockingPolicy
-
getInitialWriteValue
protected Object getInitialWriteValue(org.eclipse.persistence.internal.sessions.AbstractSession session) INTERNAL: returns the initial locking value- Overrides:
getInitialWriteValue
in classVersionLockingPolicy
-
getNewLockValue
INTERNAL: Returns the new Timestamp value.- Overrides:
getNewLockValue
in classVersionLockingPolicy
-
getValueToPutInCache
public Object getValueToPutInCache(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. If the value is stored in the object, then return a null.- Specified by:
getValueToPutInCache
in interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
- Overrides:
getValueToPutInCache
in classVersionLockingPolicy
-
getVersionDifference
public int getVersionDifference(Object currentValue, Object domainObject, Object primaryKeys, org.eclipse.persistence.internal.sessions.AbstractSession session) INTERNAL: Return the number of versions different between these objects.- Specified by:
getVersionDifference
in interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
- Overrides:
getVersionDifference
in classVersionLockingPolicy
- Parameters:
currentValue
- the new lock valuedomainObject
- the object containing the version to be compared toprimaryKeys
- a vector containing the primary keys of the domainObjectsession
- the session to be used with the comparison
-
getWriteLockValue
public Object getWriteLockValue(Object domainObject, Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session) INTERNAL: This method will return the optimistic lock value for the object.- Specified by:
getWriteLockValue
in interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
- Overrides:
getWriteLockValue
in classVersionLockingPolicy
-
getWriteLockUpdateExpression
public Expression getWriteLockUpdateExpression(ExpressionBuilder builder, org.eclipse.persistence.internal.sessions.AbstractSession session) INTERNAL: Return an expression that updates the write lock- Specified by:
getWriteLockUpdateExpression
in interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
- Overrides:
getWriteLockUpdateExpression
in classVersionLockingPolicy
-
incrementWriteLockValue
INTERNAL: Timestamp versioning should not be able to do this. Override the superclass behavior.- Overrides:
incrementWriteLockValue
in classVersionLockingPolicy
-
isNewerVersion
public boolean isNewerVersion(Object currentValue, 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:
isNewerVersion
in interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
- Overrides:
isNewerVersion
in classVersionLockingPolicy
-
isNewerVersion
public boolean isNewerVersion(org.eclipse.persistence.internal.sessions.AbstractRecord databaseRow, Object domainObject, Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session) INTERNAL: Compares the value from the row and from the object (or cache). Will return true if the row is newer than the object.- Specified by:
isNewerVersion
in interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
- Overrides:
isNewerVersion
in classVersionLockingPolicy
-
isNewerVersion
INTERNAL: Compares two values. Will return true if the firstLockFieldValue is newer than the secondWriteLockFieldValue.- Overrides:
isNewerVersion
in classVersionLockingPolicy
-
setUsesServerTime
public void setUsesServerTime(boolean usesServerTime) PUBLIC: Set if policy uses server time. -
useLocalTime
public void useLocalTime()PUBLIC: set this policy to get the time from the local machine. -
useServerTime
public void useServerTime()PUBLIC: set this policy to get the time from the server. -
usesLocalTime
public boolean usesLocalTime()PUBLIC: Return true if policy uses local time. -
usesServerTime
public boolean usesServerTime()PUBLIC: Return true if policy uses server time.
-