Class TimestampLockingPolicy
- java.lang.Object
-
- org.eclipse.persistence.descriptors.VersionLockingPolicy
-
- org.eclipse.persistence.descriptors.TimestampLockingPolicy
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
public class TimestampLockingPolicy extends VersionLockingPolicy
Purpose: Used to allow a single version timestamp to be used for optimistic locking.
- See Also:
- Serialized Form
- Since:
- TOPLink/Java 2.0
-
-
Field Summary
Fields Modifier and Type Field Description static intLOCAL_TIMEprotected intretrieveTimeFromstatic intSERVER_TIME-
Fields inherited from class org.eclipse.persistence.descriptors.VersionLockingPolicy
cachedExpression, descriptor, IN_CACHE, IN_OBJECT, isCascaded, lockMapping, lockOnChangeMode, lockValueStored, writeLockField
-
-
Constructor Summary
Constructors Constructor Description TimestampLockingPolicy()PUBLIC: Create a new TimestampLockingPolicy.TimestampLockingPolicy(java.lang.String fieldName)PUBLIC: Create a new TimestampLockingPolicy.TimestampLockingPolicy(org.eclipse.persistence.internal.helper.DatabaseField field)INTERNAL: Create a new TimestampLockingPolicy.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareWriteLockValues(java.lang.Object value1, java.lang.Object value2)INTERNAL: This method compares two writeLockValues.java.lang.ObjectgetBaseValue()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 java.lang.ClassgetDefaultLockingFieldType()INTERNAL: Return the default timestamp locking filed java type, default is Timestamp.protected java.lang.ObjectgetInitialWriteValue(org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: returns the initial locking valuejava.lang.ObjectgetNewLockValue(ModifyQuery query)INTERNAL: Returns the new Timestamp value.java.lang.ObjectgetValueToPutInCache(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.intgetVersionDifference(java.lang.Object currentValue, java.lang.Object domainObject, java.lang.Object primaryKeys, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Return the number of versions different between these objects.ExpressiongetWriteLockUpdateExpression(ExpressionBuilder builder, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Return an expression that updates the write lockjava.lang.ObjectgetWriteLockValue(java.lang.Object domainObject, java.lang.Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: This method will return the optimistic lock value for the object.protected java.lang.NumberincrementWriteLockValue(java.lang.Number numberValue)INTERNAL: Timestamp versioning should not be able to do this.booleanisNewerVersion(java.lang.Object firstLockFieldValue, java.lang.Object secondWriteLockFieldValue)INTERNAL: Compares two values.booleanisNewerVersion(java.lang.Object currentValue, java.lang.Object domainObject, java.lang.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 databaseRow, java.lang.Object domainObject, java.lang.Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Compares the value from the row and from the object (or cache).voidsetUsesServerTime(boolean usesServerTime)PUBLIC: Set if policy uses server time.voiduseLocalTime()PUBLIC: set this policy to get the time from the local machine.voiduseServerTime()PUBLIC: set this policy to get the time from the server.booleanusesLocalTime()PUBLIC: Return true if policy uses local time.booleanusesServerTime()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 Detail
-
retrieveTimeFrom
protected int retrieveTimeFrom
-
SERVER_TIME
public static final int SERVER_TIME
- See Also:
- Constant Field Values
-
LOCAL_TIME
public static final int LOCAL_TIME
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TimestampLockingPolicy
public TimestampLockingPolicy()
PUBLIC: Create a new TimestampLockingPolicy. Defaults to using the time retrieved from the server.
-
TimestampLockingPolicy
public TimestampLockingPolicy(java.lang.String fieldName)
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 Detail
-
compareWriteLockValues
public int compareWriteLockValues(java.lang.Object value1, java.lang.Object value2)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:
compareWriteLockValuesin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy- Overrides:
compareWriteLockValuesin classVersionLockingPolicy
-
getDefaultLockingFieldType
protected java.lang.Class getDefaultLockingFieldType()
INTERNAL: Return the default timestamp locking filed java type, default is Timestamp.- Overrides:
getDefaultLockingFieldTypein classVersionLockingPolicy
-
getBaseValue
public java.lang.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:
getBaseValuein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy- Overrides:
getBaseValuein classVersionLockingPolicy
-
getInitialWriteValue
protected java.lang.Object getInitialWriteValue(org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: returns the initial locking value- Overrides:
getInitialWriteValuein classVersionLockingPolicy
-
getNewLockValue
public java.lang.Object getNewLockValue(ModifyQuery query)
INTERNAL: Returns the new Timestamp value.- Overrides:
getNewLockValuein classVersionLockingPolicy
-
getValueToPutInCache
public java.lang.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:
getValueToPutInCachein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy- Overrides:
getValueToPutInCachein classVersionLockingPolicy
-
getVersionDifference
public int getVersionDifference(java.lang.Object currentValue, java.lang.Object domainObject, java.lang.Object primaryKeys, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Return the number of versions different between these objects.- Specified by:
getVersionDifferencein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy- Overrides:
getVersionDifferencein 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 java.lang.Object getWriteLockValue(java.lang.Object domainObject, java.lang.Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: This method will return the optimistic lock value for the object.- Specified by:
getWriteLockValuein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy- Overrides:
getWriteLockValuein 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:
getWriteLockUpdateExpressionin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy- Overrides:
getWriteLockUpdateExpressionin classVersionLockingPolicy
-
incrementWriteLockValue
protected java.lang.Number incrementWriteLockValue(java.lang.Number numberValue)
INTERNAL: Timestamp versioning should not be able to do this. Override the superclass behavior.- Overrides:
incrementWriteLockValuein classVersionLockingPolicy
-
isNewerVersion
public boolean isNewerVersion(java.lang.Object currentValue, java.lang.Object domainObject, java.lang.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
-
isNewerVersion
public boolean isNewerVersion(org.eclipse.persistence.internal.sessions.AbstractRecord databaseRow, java.lang.Object domainObject, java.lang.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:
isNewerVersionin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy- Overrides:
isNewerVersionin classVersionLockingPolicy
-
isNewerVersion
public boolean isNewerVersion(java.lang.Object firstLockFieldValue, java.lang.Object secondWriteLockFieldValue)INTERNAL: Compares two values. Will return true if the firstLockFieldValue is newer than the secondWriteLockFieldValue.- Overrides:
isNewerVersionin 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.
-
-