public class VersionLockingPolicy extends Object implements OptimisticLockingPolicy, 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(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.
|
Object |
clone()
INTERNAL:
Clone the policy
|
int |
compareWriteLockValues(Object value1,
Object value2)
INTERNAL:
This method compares two writeLockValues.
|
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 Class |
getDefaultLockingFieldType()
INTERNAL:
Return the default version locking filed java type, default is BigDecimal
|
protected ClassDescriptor |
getDescriptor()
INTERNAL:
|
protected Object |
getInitialWriteValue(AbstractSession session)
INTERNAL:
returns the initial locking value
|
protected Object |
getNewLockValue(ModifyQuery query)
INTERNAL:
This method gets the write lock value from either the cache or
the object stored in the query.
|
protected Vector |
getUnmappedFields()
INTERNAL:
This method returns any of the fields that are not mapped in
the object.
|
Object |
getValueToPutInCache(AbstractRecord row,
AbstractSession session)
INTERNAL:
Return the value that should be stored in the identity map.
|
int |
getVersionDifference(Object currentValue,
Object domainObject,
Vector primaryKeys,
AbstractSession session)
PUBLIC:
Return the number of versions different between these objects.
|
DatabaseField |
getWriteLockField()
INTERNAL:
Return the write lock field.
|
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
|
Object |
getWriteLockValue(Object domainObject,
Vector primaryKey,
AbstractSession session)
INTERNAL:
This method will return the optimistic lock value for the object
|
protected Number |
incrementWriteLockValue(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,
Vector primaryKey,
Class original,
ObjectChangeSet changeSet)
INTERNAL:
Update the parent write lock value if the unit of works has been incremented.
|
boolean |
isChildWriteLockValueGreater(UnitOfWorkImpl uow,
Vector primaryKey,
Class original)
INTERNAL:
Update the parent write lock value if the unit of works has been incremented.
|
boolean |
isNewerVersion(AbstractRecord databaseRow,
Object domainObject,
Vector primaryKey,
AbstractSession session)
INTERNAL:
Compares the value from the row and from the object (or cache).
|
boolean |
isNewerVersion(Object currentValue,
Object domainObject,
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 Object |
lockValueFromObject(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,
Vector primaryKey,
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(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,
Object domainObject)
INTERNAL:
This method updates the modify row, and the domain object
with the new lock value.
|
protected void |
updateWriteLockValueForWrite(ObjectLevelModifyQuery query,
Object lockValue)
INTERNAL:
Update the row, object and change set with the version value.
|
void |
validateDelete(int rowCount,
Object object,
WriteObjectQuery query)
INTERNAL:
Check the row count for lock failure.
|
void |
validateUpdate(int rowCount,
Object object,
WriteObjectQuery owner)
INTERNAL:
Check the row count for lock failure.
|
void |
writeLockValueIntoRow(ObjectLevelModifyQuery query,
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(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 OptimisticLockingPolicy
public void addLockValuesToTranslationRow(ObjectLevelModifyQuery query)
addLockValuesToTranslationRow
in interface OptimisticLockingPolicy
public Expression buildDeleteExpression(DatabaseTable table, Expression mainExpression, AbstractRecord row)
buildDeleteExpression
in interface OptimisticLockingPolicy
protected Expression buildExpression()
public Expression buildUpdateExpression(DatabaseTable table, Expression mainExpression, AbstractRecord row, AbstractRecord row2)
buildUpdateExpression
in interface OptimisticLockingPolicy
public Object clone()
clone
in interface OptimisticLockingPolicy
clone
in class Object
public int compareWriteLockValues(Object value1, Object value2)
compareWriteLockValues
in interface OptimisticLockingPolicy
protected Class getDefaultLockingFieldType()
public Object getBaseValue()
getBaseValue
in interface OptimisticLockingPolicy
protected ClassDescriptor getDescriptor()
protected Object getInitialWriteValue(AbstractSession session)
protected Object getNewLockValue(ModifyQuery query)
protected Vector getUnmappedFields()
public Object getValueToPutInCache(AbstractRecord row, AbstractSession session)
getValueToPutInCache
in interface OptimisticLockingPolicy
public int getVersionDifference(Object currentValue, Object domainObject, Vector primaryKeys, AbstractSession session)
getVersionDifference
in interface OptimisticLockingPolicy
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 comparisonpublic DatabaseField getWriteLockField()
getWriteLockField
in interface OptimisticLockingPolicy
public String getWriteLockFieldName()
public Expression getWriteLockUpdateExpression(ExpressionBuilder builder)
getWriteLockUpdateExpression
in interface OptimisticLockingPolicy
public Object getWriteLockValue(Object domainObject, Vector primaryKey, AbstractSession session)
getWriteLockValue
in interface OptimisticLockingPolicy
protected Number incrementWriteLockValue(Number numberValue)
public void initialize(AbstractSession session)
initialize
in interface OptimisticLockingPolicy
public void initializeProperties()
initializeProperties
in interface OptimisticLockingPolicy
public boolean isChildWriteLockValueGreater(AbstractSession session, Vector primaryKey, Class original, ObjectChangeSet changeSet)
isChildWriteLockValueGreater
in interface OptimisticLockingPolicy
public boolean isChildWriteLockValueGreater(UnitOfWorkImpl uow, Vector primaryKey, Class original)
isChildWriteLockValueGreater
in interface OptimisticLockingPolicy
public boolean isNewerVersion(Object currentValue, Object domainObject, Vector primaryKey, AbstractSession session)
isNewerVersion
in interface OptimisticLockingPolicy
public boolean isNewerVersion(AbstractRecord databaseRow, Object domainObject, Vector primaryKey, AbstractSession session)
isNewerVersion
in interface OptimisticLockingPolicy
public boolean isStoredInCache()
public boolean isStoredInObject()
protected Object lockValueFromObject(Object domainObject)
protected DatabaseMapping mappingFromLockField()
public void mergeIntoParentCache(UnitOfWorkImpl uow, Vector primaryKey, Object object)
mergeIntoParentCache
in interface OptimisticLockingPolicy
public void setDescriptor(ClassDescriptor descriptor)
setDescriptor
in interface OptimisticLockingPolicy
public 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 OptimisticLockingPolicy
protected void updateWriteLockValueForWrite(ObjectLevelModifyQuery query, Object lockValue)
public void setWriteLockField(DatabaseField writeLockField)
public void setWriteLockFieldName(String writeLockFieldName)
writeLockFieldName
- the name of the field to lock against.public void storeInCache()
public void storeInObject()
public void updateRowAndObjectForUpdate(ObjectLevelModifyQuery query, Object domainObject)
updateRowAndObjectForUpdate
in interface OptimisticLockingPolicy
public void writeLockValueIntoRow(ObjectLevelModifyQuery query, Object domainObject)
public void validateDelete(int rowCount, Object object, WriteObjectQuery query)
validateDelete
in interface OptimisticLockingPolicy
public void validateUpdate(int rowCount, Object object, WriteObjectQuery owner)
validateUpdate
in interface OptimisticLockingPolicy
public void prepareFetchGroupForReadQuery(FetchGroup fetchGroup, ObjectLevelReadQuery query)
prepareFetchGroupForReadQuery
in interface OptimisticLockingPolicy
Copyright © 2023. All rights reserved.