EclipseLink 1.0_1.0M2 API Reference - Incubation

org.eclipse.persistence.descriptors
Class TimestampLockingPolicy

java.lang.Object
  extended by org.eclipse.persistence.descriptors.VersionLockingPolicy
      extended by org.eclipse.persistence.descriptors.TimestampLockingPolicy
All Implemented Interfaces:
java.io.Serializable

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
static int LOCAL_TIME
           
protected  int retrieveTimeFrom
           
static int SERVER_TIME
           
 
Fields inherited from class org.eclipse.persistence.descriptors.VersionLockingPolicy
cachedExpression, descriptor, IN_CACHE, IN_OBJECT, isCascaded, lockMapping, lockValueStored, writeLockField
 
Constructor Summary
TimestampLockingPolicy()
          PUBLIC: Create a new TimestampLockingPolicy.
TimestampLockingPolicy(java.lang.String fieldName)
          PUBLIC: Create a new TimestampLockingPolicy.
 
Method Summary
 int compareWriteLockValues(java.lang.Object value1, java.lang.Object value2)
          INTERNAL: This method compares two writeLockValues.
 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.
protected  java.lang.Class getDefaultLockingFieldType()
          INTERNAL: Return the default timestamp locking filed java type, default is Timestamp.
protected  java.lang.Object getInitialWriteValue(AbstractSession session)
          INTERNAL: returns the initial locking value
 java.lang.Object getNewLockValue(ModifyQuery query)
          INTERNAL: Returns the new Timestamp value.
 java.lang.Object getValueToPutInCache(AbstractRecord row, AbstractSession session)
          INTERNAL: Return the value that should be stored in the identity map.
 int getVersionDifference(java.lang.Object currentValue, java.lang.Object domainObject, java.util.Vector primaryKeys, AbstractSession session)
          INTERNAL: Return the number of versions different between these objects.
 Expression getWriteLockUpdateExpression(ExpressionBuilder builder)
          INTERNAL: Retrun an expression that updates the write lock
 java.lang.Object getWriteLockValue(java.lang.Object domainObject, java.util.Vector primaryKey, AbstractSession session)
          INTERNAL: This method will return the optimistic lock value for the object
protected  java.lang.Number incrementWriteLockValue(java.lang.Number numberValue)
          INTERNAL: Timestamp versioning should not be able to do this.
 boolean isChildWriteLockValueGreater(AbstractSession session, java.util.Vector primaryKey, java.lang.Class original, ObjectChangeSet changeSet)
          INTERNAL: Update the parent write lock value if the objectChangeSet's is greater.
 boolean isNewerVersion(java.lang.Object currentValue, java.lang.Object domainObject, java.util.Vector primaryKey, AbstractSession session)
          INTERNAL: Compares the value with the value from the object (or cache).
 void setUsesServerTime(boolean usesServerTime)
          PUBLIC: Set if policy uses server time.
 void useLocalTime()
          PUBLIC: set this policy to get the time from the local machine.
 void useServerTime()
          PUBLIC: set this policy to get the time from the server.
 boolean usesLocalTime()
          PUBLIC: Return true if policy uses local time.
 boolean usesServerTime()
          PUBLIC: Return true if policy uses server time.
 
Methods inherited from class org.eclipse.persistence.descriptors.VersionLockingPolicy
addLockFieldsToUpdateRow, addLockValuesToTranslationRow, buildDeleteExpression, buildExpression, buildUpdateExpression, clone, getDescriptor, getUnmappedFields, getWriteLockField, getWriteLockFieldName, initialize, initializeProperties, isCascaded, isStoredInCache, isStoredInObject, lockValueFromObject, mergeIntoParentCache, setDescriptor, setIsCascaded, setIsStoredInCache, setupWriteFieldsForInsert, setWriteLockField, setWriteLockFieldName, storeInCache, storeInObject, supportsWriteLockValuesComparison, updateRowAndObjectForUpdate, updateWriteLockValueForWrite, validateDelete, validateUpdate, writeLockValueIntoRow
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.
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.

Overrides:
compareWriteLockValues in class VersionLockingPolicy

getDefaultLockingFieldType

protected java.lang.Class getDefaultLockingFieldType()
INTERNAL: Return the default timestamp locking filed java type, default is Timestamp.

Overrides:
getDefaultLockingFieldType in class VersionLockingPolicy

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.

Overrides:
getBaseValue in class VersionLockingPolicy

getInitialWriteValue

protected java.lang.Object getInitialWriteValue(AbstractSession session)
INTERNAL: returns the initial locking value

Overrides:
getInitialWriteValue in class VersionLockingPolicy

getNewLockValue

public java.lang.Object getNewLockValue(ModifyQuery query)
INTERNAL: Returns the new Timestamp value.

Overrides:
getNewLockValue in class VersionLockingPolicy

getValueToPutInCache

public java.lang.Object getValueToPutInCache(AbstractRecord row,
                                             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.

Overrides:
getValueToPutInCache in class VersionLockingPolicy

getVersionDifference

public int getVersionDifference(java.lang.Object currentValue,
                                java.lang.Object domainObject,
                                java.util.Vector primaryKeys,
                                AbstractSession session)
INTERNAL: Return the number of versions different between these objects.

Overrides:
getVersionDifference in class VersionLockingPolicy
Parameters:
currentValue - the new lock value
domainObject - the object containing the version to be compared to
primaryKeys - a vector containing the primary keys of the domainObject
session - the session to be used with the comparison

getWriteLockValue

public java.lang.Object getWriteLockValue(java.lang.Object domainObject,
                                          java.util.Vector primaryKey,
                                          AbstractSession session)
INTERNAL: This method will return the optimistic lock value for the object

Overrides:
getWriteLockValue in class VersionLockingPolicy

getWriteLockUpdateExpression

public Expression getWriteLockUpdateExpression(ExpressionBuilder builder)
INTERNAL: Retrun an expression that updates the write lock

Overrides:
getWriteLockUpdateExpression in class VersionLockingPolicy

incrementWriteLockValue

protected java.lang.Number incrementWriteLockValue(java.lang.Number numberValue)
INTERNAL: Timestamp versioning should not be able to do this. Override the superclass behaviour.

Overrides:
incrementWriteLockValue in class VersionLockingPolicy

isChildWriteLockValueGreater

public boolean isChildWriteLockValueGreater(AbstractSession session,
                                            java.util.Vector primaryKey,
                                            java.lang.Class original,
                                            ObjectChangeSet changeSet)
INTERNAL: Update the parent write lock value if the objectChangeSet's is greater.

Overrides:
isChildWriteLockValueGreater in class VersionLockingPolicy

isNewerVersion

public boolean isNewerVersion(java.lang.Object currentValue,
                              java.lang.Object domainObject,
                              java.util.Vector primaryKey,
                              AbstractSession session)
INTERNAL: Compares the value with the value from the object (or cache). Will return true if the object is newer.

Overrides:
isNewerVersion in class VersionLockingPolicy

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.


EclipseLink 1.0_1.0M2 API Reference - Incubation