public class VersionLockingPolicy extends java.lang.Object implements OptimisticLockingPolicy, java.io.Serializable
Purpose: Used to allow a single version number to be used for optimistic locking.
| Modifier and Type | Field and Description |
|---|---|
protected Expression |
cachedExpression |
protected ClassDescriptor |
descriptor |
static int |
IN_CACHE |
static int |
IN_OBJECT |
protected int |
lockValueStored |
protected DatabaseField |
writeLockField |
| Constructor and Description |
|---|
VersionLockingPolicy()
PUBLIC:
Create a new VersionLockingPolicy.
|
VersionLockingPolicy(DatabaseField field)
PUBLIC:
Create a new VersionLockingPolicy.
|
VersionLockingPolicy(java.lang.String fieldName)
PUBLIC:
Create a new VersionLockingPolicy.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addLockFieldsToUpdateRow(AbstractRecord databaseRow,
AbstractSession session)
INTERNAL:
Add update fields for template row.
|
void |
addLockValuesToTranslationRow(ObjectLevelModifyQuery query)
INTERNAL:
This method adds the lock value to the translation row of the
passed in query.
|
Expression |
buildDeleteExpression(DatabaseTable table,
Expression mainExpression,
AbstractRecord row)
INTERNAL:
When given an expression, this method will return a new expression with
the optimistic locking values included.
|
protected Expression |
buildExpression()
INTERNAL:
Returns an expression that will be used for both the update and
delete where clause
|
Expression |
buildUpdateExpression(DatabaseTable table,
Expression mainExpression,
AbstractRecord row,
AbstractRecord row2)
INTERNAL:
When given an expression, this method will return a new expression
with the optimistic locking values included.
|
java.lang.Object |
clone()
INTERNAL:
Clone the policy
|
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 version locking filed java type, default is BigDecimal
|
protected ClassDescriptor |
getDescriptor()
INTERNAL:
|
protected java.lang.Object |
getInitialWriteValue(AbstractSession session)
INTERNAL:
returns the initial locking value
|
protected java.lang.Object |
getNewLockValue(ModifyQuery query)
INTERNAL:
This method gets the write lock value from either the cache or
the object stored in the query.
|
protected java.util.Vector |
getUnmappedFields()
INTERNAL:
This method returns any of the fields that are not mapped in
the object.
|
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)
PUBLIC:
Return the number of versions different between these objects.
|
DatabaseField |
getWriteLockField()
INTERNAL:
Return the write lock field.
|
java.lang.String |
getWriteLockFieldName()
PUBLIC:
Return the field name of the field that stores the write lock value.
|
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:
adds 1 to the value passed in
|
void |
initialize(AbstractSession session)
INTERNAL:
It is responsible for initializing the policy;
|
void |
initializeProperties()
INTERNAL:
It is responsible for initializing the policy properties;
|
boolean |
isChildWriteLockValueGreater(AbstractSession session,
java.util.Vector primaryKey,
java.lang.Class original,
ObjectChangeSet changeSet)
INTERNAL:
Update the parent write lock value if the unit of works has been incremented.
|
boolean |
isChildWriteLockValueGreater(UnitOfWorkImpl uow,
java.util.Vector primaryKey,
java.lang.Class original)
INTERNAL:
Update the parent write lock value if the unit of works has been incremented.
|
boolean |
isNewerVersion(AbstractRecord databaseRow,
java.lang.Object domainObject,
java.util.Vector primaryKey,
AbstractSession session)
INTERNAL:
Compares the value from the row and from the object (or cache).
|
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).
|
boolean |
isStoredInCache()
PUBLIC:
Return true if the lock value is stored in the cache.
|
boolean |
isStoredInObject()
PUBLIC:
Return true if the lock value is stored in the object.
|
protected java.lang.Object |
lockValueFromObject(java.lang.Object domainObject)
INTERNAL:
retrieves the lock value from the object.
|
protected DatabaseMapping |
mappingFromLockField()
INTERNAL:
returns the mapping from the writelock field.
|
void |
mergeIntoParentCache(UnitOfWorkImpl uow,
java.util.Vector primaryKey,
java.lang.Object object)
INTERNAL:
Only applicable when the value is stored in the cache.
|
void |
prepareFetchGroupForReadQuery(FetchGroup fetchGroup,
ObjectLevelReadQuery query)
INTERNAL:
Prepare fetch group for read query
|
void |
setDescriptor(ClassDescriptor descriptor)
INTERNAL:
|
void |
setIsStoredInCache(boolean isStoredInCache)
PUBLIC:
Set whether to store the lock in the cache or in the object.
|
void |
setupWriteFieldsForInsert(ObjectLevelModifyQuery query)
INTERNAL:
This method must be included in any locking policy.
|
void |
setWriteLockField(DatabaseField writeLockField)
ADVANCED:
Set the write lock field.
|
void |
setWriteLockFieldName(java.lang.String writeLockFieldName)
PUBLIC:
Set the write lock field name.
|
void |
storeInCache()
PUBLIC:
Configure the version lock value to be stored in the cache.
|
void |
storeInObject()
PUBLIC:
Configure the version lock value to be stored in the object.
|
void |
updateRowAndObjectForUpdate(ObjectLevelModifyQuery query,
java.lang.Object domainObject)
INTERNAL:
This method updates the modify row, and the domain object
with the new lock value.
|
protected void |
updateWriteLockValueForWrite(ObjectLevelModifyQuery query,
java.lang.Object lockValue)
INTERNAL:
Update the row, object and change set with the version value.
|
void |
validateDelete(int rowCount,
java.lang.Object object,
WriteObjectQuery query)
INTERNAL:
Check the row count for lock failure.
|
void |
validateUpdate(int rowCount,
java.lang.Object object,
WriteObjectQuery owner)
INTERNAL:
Check the row count for lock failure.
|
void |
writeLockValueIntoRow(ObjectLevelModifyQuery query,
java.lang.Object domainObject)
INTERNAL:
This method updates the modify row with the old lock value.
|
protected DatabaseField writeLockField
protected int lockValueStored
protected ClassDescriptor descriptor
protected transient Expression cachedExpression
public static final int IN_CACHE
public static final int IN_OBJECT
public VersionLockingPolicy()
public VersionLockingPolicy(java.lang.String fieldName)
fieldName - specifies the field name for the write
lock field.public VersionLockingPolicy(DatabaseField field)
the - write lock field.public void addLockFieldsToUpdateRow(AbstractRecord databaseRow, AbstractSession session)
addLockFieldsToUpdateRow in interface OptimisticLockingPolicypublic void addLockValuesToTranslationRow(ObjectLevelModifyQuery query)
addLockValuesToTranslationRow in interface OptimisticLockingPolicypublic Expression buildDeleteExpression(DatabaseTable table, Expression mainExpression, AbstractRecord row)
buildDeleteExpression in interface OptimisticLockingPolicyprotected Expression buildExpression()
public Expression buildUpdateExpression(DatabaseTable table, Expression mainExpression, AbstractRecord row, AbstractRecord row2)
buildUpdateExpression in interface OptimisticLockingPolicypublic java.lang.Object clone()
clone in interface OptimisticLockingPolicyclone in class java.lang.Objectpublic int compareWriteLockValues(java.lang.Object value1,
java.lang.Object value2)
compareWriteLockValues in interface OptimisticLockingPolicyprotected java.lang.Class getDefaultLockingFieldType()
public java.lang.Object getBaseValue()
getBaseValue in interface OptimisticLockingPolicyprotected ClassDescriptor getDescriptor()
protected java.lang.Object getInitialWriteValue(AbstractSession session)
protected java.lang.Object getNewLockValue(ModifyQuery query)
protected java.util.Vector getUnmappedFields()
public java.lang.Object getValueToPutInCache(AbstractRecord row, AbstractSession session)
getValueToPutInCache in interface OptimisticLockingPolicypublic int getVersionDifference(java.lang.Object currentValue,
java.lang.Object domainObject,
java.util.Vector primaryKeys,
AbstractSession session)
getVersionDifference in interface OptimisticLockingPolicycurrentValue - 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 comparisonpublic DatabaseField getWriteLockField()
getWriteLockField in interface OptimisticLockingPolicypublic java.lang.String getWriteLockFieldName()
public Expression getWriteLockUpdateExpression(ExpressionBuilder builder)
getWriteLockUpdateExpression in interface OptimisticLockingPolicypublic java.lang.Object getWriteLockValue(java.lang.Object domainObject,
java.util.Vector primaryKey,
AbstractSession session)
getWriteLockValue in interface OptimisticLockingPolicyprotected java.lang.Number incrementWriteLockValue(java.lang.Number numberValue)
public void initialize(AbstractSession session)
initialize in interface OptimisticLockingPolicypublic void initializeProperties()
initializeProperties in interface OptimisticLockingPolicypublic boolean isChildWriteLockValueGreater(AbstractSession session, java.util.Vector primaryKey, java.lang.Class original, ObjectChangeSet changeSet)
isChildWriteLockValueGreater in interface OptimisticLockingPolicypublic boolean isChildWriteLockValueGreater(UnitOfWorkImpl uow, java.util.Vector primaryKey, java.lang.Class original)
isChildWriteLockValueGreater in interface OptimisticLockingPolicypublic boolean isNewerVersion(java.lang.Object currentValue,
java.lang.Object domainObject,
java.util.Vector primaryKey,
AbstractSession session)
isNewerVersion in interface OptimisticLockingPolicypublic boolean isNewerVersion(AbstractRecord databaseRow, java.lang.Object domainObject, java.util.Vector primaryKey, AbstractSession session)
isNewerVersion in interface OptimisticLockingPolicypublic boolean isStoredInCache()
public boolean isStoredInObject()
protected java.lang.Object lockValueFromObject(java.lang.Object domainObject)
protected DatabaseMapping mappingFromLockField()
public void mergeIntoParentCache(UnitOfWorkImpl uow, java.util.Vector primaryKey, java.lang.Object object)
mergeIntoParentCache in interface OptimisticLockingPolicypublic void setDescriptor(ClassDescriptor descriptor)
setDescriptor in interface OptimisticLockingPolicypublic void setIsStoredInCache(boolean isStoredInCache)
isStoredInCache - set this to true if you would like to store lock in the cache and set it
to false if you would like to store it in the object.public void setupWriteFieldsForInsert(ObjectLevelModifyQuery query)
setupWriteFieldsForInsert in interface OptimisticLockingPolicyprotected void updateWriteLockValueForWrite(ObjectLevelModifyQuery query, java.lang.Object lockValue)
public void setWriteLockField(DatabaseField writeLockField)
public void setWriteLockFieldName(java.lang.String writeLockFieldName)
writeLockFieldName - the name of the field to lock against.public void storeInCache()
public void storeInObject()
public void updateRowAndObjectForUpdate(ObjectLevelModifyQuery query, java.lang.Object domainObject)
updateRowAndObjectForUpdate in interface OptimisticLockingPolicypublic void writeLockValueIntoRow(ObjectLevelModifyQuery query, java.lang.Object domainObject)
public void validateDelete(int rowCount,
java.lang.Object object,
WriteObjectQuery query)
validateDelete in interface OptimisticLockingPolicypublic void validateUpdate(int rowCount,
java.lang.Object object,
WriteObjectQuery owner)
validateUpdate in interface OptimisticLockingPolicypublic void prepareFetchGroupForReadQuery(FetchGroup fetchGroup, ObjectLevelReadQuery query)
prepareFetchGroupForReadQuery in interface OptimisticLockingPolicy