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

public abstract Class FieldsLockingPolicy

extends Object
implements OptimisticLockingPolicy
Class Inheritance
All Implemented Interfaces
org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy, java.io.Serializable, java.lang.Cloneable
Known Direct Subclasses
org.eclipse.persistence.descriptors.AllFieldsLockingPolicy, org.eclipse.persistence.descriptors.ChangedFieldsLockingPolicy, org.eclipse.persistence.descriptors.SelectedFieldsLockingPolicy
Imports
java.util.*, org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy, org.eclipse.persistence.internal.sessions.AbstractRecord, .AbstractSession, .UnitOfWorkImpl, org.eclipse.persistence.internal.helper.*, org.eclipse.persistence.internal.identitymaps.CacheKey, org.eclipse.persistence.queries.*, org.eclipse.persistence.expressions.*, org.eclipse.persistence.exceptions.*

Purpose: An abstract superclass of some implementations of the OptimisticLockingPolicy interface. All of the subclasses of this class implement OptimisticLocking based on mapped fields in the object. These fields are only compared and not modified. Any modification (incrementing etc..) must be handled by the application.

Author
Peter Krogh
Since
TopLink 2.1
See Also
AllFieldsLockingPolicy, ChangedFieldsLockingPolicy, SelectedFieldsLockingPolicy

Field Summary

Modifier and TypeField and Description
protected List<DatabaseField>
protected ClassDescriptor

Constructor Summary

AccessConstructor and Description
protected
FieldsLockingPolicy()

PUBLIC: Create a new field locking policy.

Method Summary

Modifier and TypeMethod and Description
public void
public abstract void
addLockValuesToTranslationRow(ObjectLevelModifyQuery query)

Redeclares org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.addLockValuesToTranslationRow.

INTERNAL: Values to be included in the locking mechanism are added to the translation row.
protected List<DatabaseField>
buildAllNonPrimaryKeyFields()

INTERNAL: Returns the fields that should be compared in the where clause.

public Expression
buildDeleteExpression(DatabaseTable table, Expression mainExpression, AbstractRecord row)

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

INTERNAL: When given an expression, this method will return a new expression with the optimistic locking values included.
protected Expression
buildExpression(DatabaseTable table, AbstractRecord transRow, AbstractRecord modifyRow, ExpressionBuilder builder)

INTERNAL: returns the expression to be used in both the delete and update where clause.

public Expression
buildUpdateExpression(DatabaseTable table, Expression mainExpression, AbstractRecord transRow, AbstractRecord modifyRow)

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

INTERNAL: This method must be included in any locking policy.
public Object
public int
compareWriteLockValues(Object value1, Object value2)

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

INTERNAL: This method shouldn't be called if supportsWriteLockValuesComparison() returns false.
protected List<DatabaseField>
getAllNonPrimaryKeyFields()

INTERNAL: Returns the fields that should be compared in the where clause.

protected List<DatabaseField>
getAllNonPrimaryKeyFields(DatabaseTable table)

INTERNAL: filter the fields based on the passed in table.

public <T> T
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 abstract List<DatabaseField>
getFieldsToCompare(DatabaseTable table, AbstractRecord transRow, AbstractRecord modifyRow)

INTERNAL: Returns the fields that should be compared in the where clause.

public OptimisticLockingPolicy.LockOnChange
getLockOnChangeMode()

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

ADVANCED: returns the LockOnChange mode for this policy.
public <T> T
getValueToPutInCache(AbstractRecord row, AbstractSession session)

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

INTERNAL: Return the value that should be stored in the identity map.
public int
getVersionDifference(Object currentValue, Object domainObject, Object primaryKeys, AbstractSession session)

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

INTERNAL: Return the number of version difference between the two states of the object.
public DatabaseField
public Expression
public <T> T
getWriteLockValue(Object domainObject, Object primaryKey, AbstractSession session)

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

INTERNAL: This method will return the optimistic lock value for the object
public void
initialize(AbstractSession session)

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

INTERNAL: It is responsible for initializing the policy;
public void
public boolean
isCascaded()

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

PUBLIC: Return true if the policy uses cascade locking.
public boolean
isNewerVersion(Object currentValue, Object domainObject, Object primaryKey, AbstractSession session)

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

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

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

INTERNAL: Compares the value from the row and from the object (or cache).
protected boolean
isPrimaryKey(DatabaseField dbField)

INTERNAL: Returns whether or not this field is a primary key.

public boolean
isStoredInCache()

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

PUBLIC: Return true if the lock value is stored in the cache.
public void
mergeIntoParentCache(UnitOfWorkImpl uow, Object primaryKey, Object object)

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

INTERNAL: Only applicable when the value is stored in the cache.
public void
mergeIntoParentCache(CacheKey unitOfWorkCacheKey, CacheKey parentSessionCacheKey)

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

INTERNAL: This method should merge changes from the parent into the child.
protected void
setAllNonPrimaryKeyFields(List<DatabaseField> allNonPrimaryKeyFields)

INTERNAL: Set method for all the primary keys

public void
public void
public void
public boolean
shouldUpdateVersionOnMappingChange()

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

INTERNAL: Returns true if the policy has been set to set an optimistic read lock when any mapping changes.
public boolean
shouldUpdateVersionOnOwnedMappingChange()

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

INTERNAL: Returns true if the policy has been set to set an optimistic read lock when a owning mapping changes.
public boolean
supportsWriteLockValuesComparison()

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

INTERNAL: Indicates whether compareWriteLockValues method is supported by the policy.
public void
updateRowAndObjectForUpdate(ObjectLevelModifyQuery query, Object domainObject)

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

INTERNAL: Nothing to do because all updates are handled by the application
public void
validateDelete(int rowCount, Object object, DeleteObjectQuery query)

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

INTERNAL: Check the row count for lock failure.
public void
validateUpdate(int rowCount, Object object, WriteObjectQuery query)

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

INTERNAL: Check the row count for lock failure.
protected void
verifyUsage(AbstractSession session)

INTERNAL: throw an exception if not inside a unit of work at this point

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allNonPrimaryKeyFieldsback to summary
protected List<DatabaseField> allNonPrimaryKeyFields
descriptorback to summary
protected ClassDescriptor descriptor

Constructor Detail

FieldsLockingPolicyback to summary
protected FieldsLockingPolicy()

PUBLIC: Create a new field locking policy. A field locking policy is based on locking on a subset of fields by comparing with their previous values to detect field-level collisions.

Note

the unit of work must be used for all updates when using field locking.

Method Detail

addLockFieldsToUpdateRowback to summary
public void addLockFieldsToUpdateRow(AbstractRecord Record, AbstractSession session)

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

INTERNAL: Add update fields for template row. These are any unmapped fields required to write in an update. Since all fields are mapped, there is nothing required.

Annotations
@Override
addLockValuesToTranslationRowback to summary
public abstract void addLockValuesToTranslationRow(ObjectLevelModifyQuery query)

Redeclares org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.addLockValuesToTranslationRow.

INTERNAL: Values to be included in the locking mechanism are added to the translation row. Set the translation row to all the original field values.

Annotations
@Override
buildAllNonPrimaryKeyFieldsback to summary
protected List<DatabaseField> buildAllNonPrimaryKeyFields()

INTERNAL: Returns the fields that should be compared in the where clause. In this case, it is all the fields, except for the primary key and class indicator fields. This is called during lazy initialization.

buildDeleteExpressionback to summary
public Expression buildDeleteExpression(DatabaseTable table, Expression mainExpression, AbstractRecord row)

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

INTERNAL: When given an expression, this method will return a new expression with the optimistic locking values included. The values are taken from the passed in database row. This expression will be used in a delete call.

Annotations
@Override
buildExpressionback to summary
protected Expression buildExpression(DatabaseTable table, AbstractRecord transRow, AbstractRecord modifyRow, ExpressionBuilder builder)

INTERNAL: returns the expression to be used in both the delete and update where clause.

buildUpdateExpressionback to summary
public Expression buildUpdateExpression(DatabaseTable table, Expression mainExpression, AbstractRecord transRow, AbstractRecord modifyRow)

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

INTERNAL: This method must be included in any locking policy. When given an expression, this method will return a new expression with the optimistic locking values included. The values are taken from the passed in database row. This expression will be used in a delete call.

Annotations
@Override
cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

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

INTERNAL: Clone the policy

Returns:Object

Doc from java.lang.Object.clone.

a clone of this instance.

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

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

INTERNAL: This method shouldn't be called if supportsWriteLockValuesComparison() returns false. This method compares two writeLockValues. The writeLockValues should be non-null and of the correct type. 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
getAllNonPrimaryKeyFieldsback to summary
protected List<DatabaseField> getAllNonPrimaryKeyFields()

INTERNAL: Returns the fields that should be compared in the where clause. In this case, it is all the fields, except for the primary key and class indicator field.

getAllNonPrimaryKeyFieldsback to summary
protected List<DatabaseField> getAllNonPrimaryKeyFields(DatabaseTable table)

INTERNAL: filter the fields based on the passed in table. Only return fields of this table.

getBaseValueback to summary
public <T> T 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
getFieldsToCompareback to summary
protected abstract List<DatabaseField> getFieldsToCompare(DatabaseTable table, AbstractRecord transRow, AbstractRecord modifyRow)

INTERNAL: Returns the fields that should be compared in the where clause. This method must be implemented by the subclass

getLockOnChangeModeback to summary
public OptimisticLockingPolicy.LockOnChange getLockOnChangeMode()

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

ADVANCED: returns the LockOnChange mode for this policy. This mode specifies if a Optimistic Write lock should be enforced on this entity when a set of mappings are changed. Unfortunately this locking policy can not enforce an optimistic write lock unless a FK or DTF field has changed so this type returns LockOnChange.NONE

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

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
getVersionDifferenceback to summary
public int getVersionDifference(Object currentValue, Object domainObject, Object primaryKeys, AbstractSession session)

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

INTERNAL: Return the number of version difference between the two states of the object.

Annotations
@Override
getWriteLockFieldback to summary
public DatabaseField getWriteLockField()

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

INTERNAL: Return the write lock field.

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

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

INTERNAL:

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

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

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

Annotations
@Override
initializeback to summary
public void initialize(AbstractSession session)

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

INTERNAL: It is responsible for initializing the policy;

Annotations
@Override
initializePropertiesback to summary
public void initializeProperties()

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

INTERNAL: It is responsible for initializing the policy;

Annotations
@Override
isCascadedback to summary
public boolean isCascaded()

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

PUBLIC: Return true if the policy uses cascade locking. Currently, not supported on this policy at this time.

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

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

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

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

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 object is newer than the row.

Annotations
@Override
isPrimaryKeyback to summary
protected boolean isPrimaryKey(DatabaseField dbField)

INTERNAL: Returns whether or not this field is a primary key. This method will also return true for secondary table primarykeys

isStoredInCacheback to summary
public boolean isStoredInCache()

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

PUBLIC: Return true if the lock value is stored in the cache.

Annotations
@Override
mergeIntoParentCacheback to summary
public void mergeIntoParentCache(UnitOfWorkImpl uow, Object primaryKey, Object object)

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

INTERNAL: Only applicable when the value is stored in the cache.

Annotations
@Override
mergeIntoParentCacheback to summary
public void mergeIntoParentCache(CacheKey unitOfWorkCacheKey, CacheKey parentSessionCacheKey)

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

INTERNAL: This method should merge changes from the parent into the child. #see this method in VersionLockingPolicy

Annotations
@Override
setAllNonPrimaryKeyFieldsback to summary
protected void setAllNonPrimaryKeyFields(List<DatabaseField> allNonPrimaryKeyFields)

INTERNAL: Set method for all the primary keys

setDescriptorback to summary
public void setDescriptor(ClassDescriptor descriptor)

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

INTERNAL: Set method for the descriptor

Annotations
@Override
setLockOnChangeModeback to summary
public void setLockOnChangeMode(OptimisticLockingPolicy.LockOnChange lockOnChangeMode)

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

ADVANCED: Sets the LockOnChange mode for this policy. This mode specifies if a Optimistic Write lock should be enforced on this entity when set of mappings are changed. Unfortunately this locking policy can not always force an optimistic lock unless the core fields have changed

Annotations
@Override
setupWriteFieldsForInsertback to summary
public void setupWriteFieldsForInsert(ObjectLevelModifyQuery query)

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

INTERNAL: Put the initial writelock value into the modifyRow. There is nothing to do because all the lock values are in the mappings.

Annotations
@Override
shouldUpdateVersionOnMappingChangeback to summary
public boolean shouldUpdateVersionOnMappingChange()

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

INTERNAL: Returns true if the policy has been set to set an optimistic read lock when any mapping changes. Unfortunately this locking policy can not always force an optimistic lock unless the core fields have changed

Annotations
@Override
shouldUpdateVersionOnOwnedMappingChangeback to summary
public boolean shouldUpdateVersionOnOwnedMappingChange()

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

INTERNAL: Returns true if the policy has been set to set an optimistic read lock when a owning mapping changes. Unfortunately this locking policy can not always force an optimistic lock unless the core fields have changed

Annotations
@Override
supportsWriteLockValuesComparisonback to summary
public boolean supportsWriteLockValuesComparison()

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

INTERNAL: Indicates whether compareWriteLockValues method is supported by the policy. Numeric or timestamp lock values could be compared: for every pair of values v1 and v2 - either v1<v2; or v1==v2; or v1>v2. However it's impossible to compare values for FieldsLockingPolicy for two reasons: 1. there is no "linear order": v1<v2 and v>v2 is not defined: either v1==v2 or v1!=v2; 2. locking value is not a single field which is not part of mapped object value but rather a set of object's mapped fields. That means any object's mapped attribute change is potentially a change of the locking value. For ChangedFieldsLockingPolicy every mapped attribute's change is a change of locking value. The pattern used by versioning: "if the original locking value is unchanged then the object hasn't been changed outside of the application", which allows to distinguish between the change made inside and outside the application, doesn't work for fields locking. It degenerates into useless pattern: "if the original locking value is unchanged then the object hasn't been changed". Use compareWriteLockValues method only if this method returns true.

Annotations
@Override
updateRowAndObjectForUpdateback to summary
public void updateRowAndObjectForUpdate(ObjectLevelModifyQuery query, Object domainObject)

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

INTERNAL: Nothing to do because all updates are handled by the application

Annotations
@Override
validateDeleteback to summary
public void validateDelete(int rowCount, Object object, DeleteObjectQuery query)

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

INTERNAL: Check the row count for lock failure.

Annotations
@Override
validateUpdateback to summary
public void validateUpdate(int rowCount, Object object, WriteObjectQuery query)

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

INTERNAL: Check the row count for lock failure.

Annotations
@Override
verifyUsageback to summary
protected void verifyUsage(AbstractSession session)

INTERNAL: throw an exception if not inside a unit of work at this point