Top Description Fields Constructors Methods
org.eclipse.persistence.descriptors

public Class TimestampLockingPolicy

extends VersionLockingPolicy
Class Inheritance
Imports
org.eclipse.persistence.internal.sessions.*, java.sql.Timestamp, org.eclipse.persistence.expressions.*, org.eclipse.persistence.internal.helper.*, org.eclipse.persistence.queries.*, org.eclipse.persistence.exceptions.*

Purpose: Used to allow a single version timestamp to be used for optimistic locking.

Since
TOPLink/Java 2.0

Field Summary

Modifier and TypeField and Description
public static final int
protected int
public static final int
Inherited from org.eclipse.persistence.descriptors.VersionLockingPolicy:
cachedExpressiondescriptorIN_CACHEIN_OBJECTisCascadedlockMappinglockOnChangeModelockValueStoredwriteLockField

Constructor Summary

AccessConstructor and Description
public
TimestampLockingPolicy()

PUBLIC: Create a new TimestampLockingPolicy.

public
TimestampLockingPolicy(String
the field where the write lock value will be stored.
fieldName
)

PUBLIC: Create a new TimestampLockingPolicy.

public
TimestampLockingPolicy(DatabaseField
the field where the write lock value will be stored.
field
)

INTERNAL: Create a new TimestampLockingPolicy.

Method Summary

Modifier and TypeMethod and Description
public int
public <T> T
getBaseValue()

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.getBaseValue.

Implements org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.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.
protected <T> Class<T>
getDefaultLockingFieldType()

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.getDefaultLockingFieldType.

INTERNAL: Return the default timestamp locking filed java type, default is Timestamp.
protected <T> T
public <T> T
public <T> T
public int
getVersionDifference(Object
the new lock value
currentValue
,
Object
the object containing the version to be compared to
domainObject
,
Object
a vector containing the primary keys of the domainObject
primaryKeys
,
AbstractSession
the session to be used with the comparison
session
)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.getVersionDifference.

Implements org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.getVersionDifference.

INTERNAL: Return the number of versions different between these objects.
public Expression
public <T> T
getWriteLockValue(Object domainObject, Object primaryKey, AbstractSession session)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.getWriteLockValue.

Implements org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.getWriteLockValue.

INTERNAL: This method will return the optimistic lock value for the object.
protected Number
incrementWriteLockValue(Number numberValue)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.incrementWriteLockValue.

INTERNAL: Timestamp versioning should not be able to do this.
public boolean
isNewerVersion(Object currentValue, Object domainObject, Object primaryKey, AbstractSession session)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.isNewerVersion.

Implements org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.isNewerVersion.

INTERNAL: Compares the value with the value from the object (or cache).
public boolean
isNewerVersion(AbstractRecord databaseRow, Object domainObject, Object primaryKey, AbstractSession session)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.isNewerVersion.

Implements org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.isNewerVersion.

INTERNAL: Compares the value from the row and from the object (or cache).
public boolean
isNewerVersion(Object firstLockFieldValue, Object secondWriteLockFieldValue)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.isNewerVersion.

INTERNAL: Compares two values.
public void
setUsesServerTime(boolean usesServerTime)

PUBLIC: Set if policy uses server time.

public void
useLocalTime()

PUBLIC: set this policy to get the time from the local machine.

public void
useServerTime()

PUBLIC: set this policy to get the time from the server.

public boolean
usesLocalTime()

PUBLIC: Return true if policy uses local time.

public boolean
usesServerTime()

PUBLIC: Return true if policy uses server time.

Inherited from org.eclipse.persistence.descriptors.VersionLockingPolicy:
addLockFieldsToUpdateRowaddLockValuesToTranslationRowbuildDeleteExpressionbuildExpressionbuildUpdateExpressionclonegetDescriptorgetLockOnChangeModegetUnmappedFieldsgetVersionMappinggetWriteLockFieldgetWriteLockFieldNameinitializeinitializePropertiesisCascadedisStoredInCacheisStoredInObjectlockValueFromObjectmergeIntoParentCachemergeIntoParentCachesetDescriptorsetIsCascadedsetIsStoredInCachesetLockOnChangeModesetupWriteFieldsForInsertsetWriteLockFieldsetWriteLockFieldNameshouldUpdateVersionOnMappingChangeshouldUpdateVersionOnOwnedMappingChangestoreInCachestoreInObjectsupportsWriteLockValuesComparisonupdateObjectWithWriteValueupdateRowAndObjectForUpdateupdateWriteLockValueForWritevalidateDeletevalidateUpdatewriteLockValueIntoRow

Field Detail

LOCAL_TIMEback to summary
public static final int LOCAL_TIME
retrieveTimeFromback to summary
protected int retrieveTimeFrom
SERVER_TIMEback to summary
public static final int SERVER_TIME

Constructor Detail

TimestampLockingPolicyback to summary
public TimestampLockingPolicy()

PUBLIC: Create a new TimestampLockingPolicy. Defaults to using the time retrieved from the server.

TimestampLockingPolicyback to summary
public TimestampLockingPolicy(String fieldName)

PUBLIC: Create a new TimestampLockingPolicy. Defaults to using the time retrieved from the server.

Parameters
fieldName:String

the field where the write lock value will be stored.

TimestampLockingPolicyback to summary
public TimestampLockingPolicy(DatabaseField field)

INTERNAL: Create a new TimestampLockingPolicy. Defaults to using the time retrieved from the server.

Parameters
field:DatabaseField

the field where the write lock value will be stored.

Method Detail

compareWriteLockValuesback to summary
public int compareWriteLockValues(Object value1, Object value2)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.compareWriteLockValues.

Implements org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.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.

Annotations
@Override
getBaseValueback to summary
public <T> T getBaseValue()

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.getBaseValue.

Implements org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.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.

Annotations
@Override
@SuppressWarnings:unchecked
getDefaultLockingFieldTypeback to summary
protected <T> Class<T> getDefaultLockingFieldType()

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.getDefaultLockingFieldType.

INTERNAL: Return the default timestamp locking filed java type, default is Timestamp.

Annotations
@Override
@SuppressWarnings:unchecked
getInitialWriteValueback to summary
protected <T> T getInitialWriteValue(AbstractSession session)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.getInitialWriteValue.

INTERNAL: returns the initial locking value

Annotations
@Override
@SuppressWarnings:unchecked
getNewLockValueback to summary
public <T> T getNewLockValue(ModifyQuery query)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.getNewLockValue.

INTERNAL: Returns the new Timestamp value.

Annotations
@Override
getValueToPutInCacheback to summary
public <T> T getValueToPutInCache(AbstractRecord row, AbstractSession session)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.getValueToPutInCache.

Implements org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.getValueToPutInCache.

INTERNAL: Return the value that should be stored in the identity map. If the value is stored in the object, then return a null.

Annotations
@Override
@SuppressWarnings:unchecked
getVersionDifferenceback to summary
public int getVersionDifference(Object currentValue, Object domainObject, Object primaryKeys, AbstractSession session)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.getVersionDifference.

Implements org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.getVersionDifference.

INTERNAL: Return the number of versions different between these objects.

Parameters
currentValue:Object

Doc from org.eclipse.persistence.descriptors.VersionLockingPolicy.getVersionDifference.

the new lock value

domainObject:Object

Doc from org.eclipse.persistence.descriptors.VersionLockingPolicy.getVersionDifference.

the object containing the version to be compared to

primaryKeys:Object

Doc from org.eclipse.persistence.descriptors.VersionLockingPolicy.getVersionDifference.

a vector containing the primary keys of the domainObject

session:AbstractSession

Doc from org.eclipse.persistence.descriptors.VersionLockingPolicy.getVersionDifference.

the session to be used with the comparison

Annotations
@Override
getWriteLockUpdateExpressionback to summary
public Expression getWriteLockUpdateExpression(ExpressionBuilder builder, AbstractSession session)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.getWriteLockUpdateExpression.

Implements org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.getWriteLockUpdateExpression.

INTERNAL: Return an expression that updates the write lock

Annotations
@Override
getWriteLockValueback to summary
public <T> T getWriteLockValue(Object domainObject, Object primaryKey, AbstractSession session)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.getWriteLockValue.

Implements org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.getWriteLockValue.

INTERNAL: This method will return the optimistic lock value for the object.

Annotations
@Override
@SuppressWarnings:unchecked
incrementWriteLockValueback to summary
protected Number incrementWriteLockValue(Number numberValue)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.incrementWriteLockValue.

INTERNAL: Timestamp versioning should not be able to do this. Override the superclass behavior.

Annotations
@Override
isNewerVersionback to summary
public boolean isNewerVersion(Object currentValue, Object domainObject, Object primaryKey, AbstractSession session)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.isNewerVersion.

Implements org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.isNewerVersion.

INTERNAL: Compares the value with the value from the object (or cache). Will return true if the currentValue is newer than the domainObject.

Annotations
@Override
isNewerVersionback to summary
public boolean isNewerVersion(AbstractRecord databaseRow, Object domainObject, Object primaryKey, AbstractSession session)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.isNewerVersion.

Implements org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.isNewerVersion.

INTERNAL: Compares the value from the row and from the object (or cache). Will return true if the row is newer than the object.

Annotations
@Override
isNewerVersionback to summary
public boolean isNewerVersion(Object firstLockFieldValue, Object secondWriteLockFieldValue)

Overrides org.eclipse.persistence.descriptors.VersionLockingPolicy.isNewerVersion.

INTERNAL: Compares two values. Will return true if the firstLockFieldValue is newer than the secondWriteLockFieldValue.

Annotations
@Override
setUsesServerTimeback to summary
public void setUsesServerTime(boolean usesServerTime)

PUBLIC: Set if policy uses server time.

useLocalTimeback to summary
public void useLocalTime()

PUBLIC: set this policy to get the time from the local machine.

useServerTimeback to summary
public void useServerTime()

PUBLIC: set this policy to get the time from the server.

usesLocalTimeback to summary
public boolean usesLocalTime()

PUBLIC: Return true if policy uses local time.

usesServerTimeback to summary
public boolean usesServerTime()

PUBLIC: Return true if policy uses server time.