Class FieldsLockingPolicy
- java.lang.Object
-
- org.eclipse.persistence.descriptors.FieldsLockingPolicy
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
- Direct Known Subclasses:
AllFieldsLockingPolicy,ChangedFieldsLockingPolicy,SelectedFieldsLockingPolicy
public abstract class FieldsLockingPolicy extends java.lang.Object implements org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicyPurpose: 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.
- See Also:
AllFieldsLockingPolicy,ChangedFieldsLockingPolicy,SelectedFieldsLockingPolicy, Serialized Form- Author:
- Peter Krogh
- Since:
- TopLink 2.1
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<org.eclipse.persistence.internal.helper.DatabaseField>allNonPrimaryKeyFieldsprotected ClassDescriptordescriptor
-
Constructor Summary
Constructors Constructor Description FieldsLockingPolicy()PUBLIC: Create a new field locking policy.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddLockFieldsToUpdateRow(org.eclipse.persistence.internal.sessions.AbstractRecord Record, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Add update fields for template row.abstract voidaddLockValuesToTranslationRow(ObjectLevelModifyQuery query)INTERNAL: Values to be included in the locking mechanism are added to the translation row.protected java.util.ListbuildAllNonPrimaryKeyFields()INTERNAL: Returns the fields that should be compared in the where clause.ExpressionbuildDeleteExpression(org.eclipse.persistence.internal.helper.DatabaseTable table, Expression mainExpression, org.eclipse.persistence.internal.sessions.AbstractRecord row)INTERNAL: When given an expression, this method will return a new expression with the optimistic locking values included.protected ExpressionbuildExpression(org.eclipse.persistence.internal.helper.DatabaseTable table, org.eclipse.persistence.internal.sessions.AbstractRecord transRow, org.eclipse.persistence.internal.sessions.AbstractRecord modifyRow, ExpressionBuilder builder)INTERNAL: returns the expression to be used in both the delete and update where clause.ExpressionbuildUpdateExpression(org.eclipse.persistence.internal.helper.DatabaseTable table, Expression mainExpression, org.eclipse.persistence.internal.sessions.AbstractRecord transRow, org.eclipse.persistence.internal.sessions.AbstractRecord modifyRow)INTERNAL: This method must be included in any locking policy.java.lang.Objectclone()INTERNAL: Clone the policyintcompareWriteLockValues(java.lang.Object value1, java.lang.Object value2)INTERNAL: This method shouldn't be called if supportsWriteLockValuesComparison() returns false.protected java.util.List<org.eclipse.persistence.internal.helper.DatabaseField>getAllNonPrimaryKeyFields()INTERNAL: Returns the fields that should be compared in the where clause.protected java.util.List<org.eclipse.persistence.internal.helper.DatabaseField>getAllNonPrimaryKeyFields(org.eclipse.persistence.internal.helper.DatabaseTable table)INTERNAL: filter the fields based on the passed in table.java.lang.ObjectgetBaseValue()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 java.util.List<org.eclipse.persistence.internal.helper.DatabaseField>getFieldsToCompare(org.eclipse.persistence.internal.helper.DatabaseTable table, org.eclipse.persistence.internal.sessions.AbstractRecord transRow, org.eclipse.persistence.internal.sessions.AbstractRecord modifyRow)INTERNAL: Returns the fields that should be compared in the where clause.org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.LockOnChangegetLockOnChangeMode()ADVANCED: returns the LockOnChange mode for this policy.java.lang.ObjectgetValueToPutInCache(org.eclipse.persistence.internal.sessions.AbstractRecord row, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Return the value that should be stored in the identity map.intgetVersionDifference(java.lang.Object currentValue, java.lang.Object domainObject, java.lang.Object primaryKeys, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Return the number of version difference between the two states of the object.org.eclipse.persistence.internal.helper.DatabaseFieldgetWriteLockField()INTERNAL: Return the write lock field.ExpressiongetWriteLockUpdateExpression(ExpressionBuilder builder, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL:java.lang.ObjectgetWriteLockValue(java.lang.Object domainObject, java.lang.Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: This method will return the optimistic lock value for the objectvoidinitialize(org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: It is responsible for initializing the policy;voidinitializeProperties()INTERNAL: It is responsible for initializing the policy;booleanisCascaded()PUBLIC: Return true if the policy uses cascade locking.booleanisNewerVersion(java.lang.Object currentValue, java.lang.Object domainObject, java.lang.Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Compares the value and the value from the object (or cache).booleanisNewerVersion(org.eclipse.persistence.internal.sessions.AbstractRecord Record, java.lang.Object domainObject, java.lang.Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Compares the value from the row and from the object (or cache).protected booleanisPrimaryKey(org.eclipse.persistence.internal.helper.DatabaseField dbField)INTERNAL: Returns whether or not this field is a primary key.booleanisStoredInCache()PUBLIC: Return true if the lock value is stored in the cache.voidmergeIntoParentCache(org.eclipse.persistence.internal.identitymaps.CacheKey unitOfWorkCacheKey, org.eclipse.persistence.internal.identitymaps.CacheKey parentSessionCacheKey)INTERNAL: This method should merge changes from the parent into the child.voidmergeIntoParentCache(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow, java.lang.Object primaryKey, java.lang.Object object)INTERNAL: Only applicable when the value is stored in the cache.protected voidsetAllNonPrimaryKeyFields(java.util.List allNonPrimaryKeyFields)INTERNAL: Set method for all the primary keysvoidsetDescriptor(ClassDescriptor descriptor)INTERNAL: Set method for the descriptorvoidsetLockOnChangeMode(org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.LockOnChange lockOnChangeMode)ADVANCED: Sets the LockOnChange mode for this policy.voidsetupWriteFieldsForInsert(ObjectLevelModifyQuery query)INTERNAL: Put the initial writelock value into the modifyRow.booleanshouldUpdateVersionOnMappingChange()INTERNAL: Returns true if the policy has been set to set an optimistic read lock when any mapping changes.booleanshouldUpdateVersionOnOwnedMappingChange()INTERNAL: Returns true if the policy has been set to set an optimistic read lock when a owning mapping changes.booleansupportsWriteLockValuesComparison()INTERNAL: Indicates whether compareWriteLockValues method is supported by the policy.voidupdateRowAndObjectForUpdate(ObjectLevelModifyQuery query, java.lang.Object domainObject)INTERNAL: Nothing to do because all updates are handled by the applicationvoidvalidateDelete(int rowCount, java.lang.Object object, DeleteObjectQuery query)INTERNAL: Check the row count for lock failure.voidvalidateUpdate(int rowCount, java.lang.Object object, WriteObjectQuery query)INTERNAL: Check the row count for lock failure.protected voidverifyUsage(org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: throw an exception if not inside a unit of work at this point
-
-
-
Field Detail
-
descriptor
protected ClassDescriptor descriptor
-
allNonPrimaryKeyFields
protected java.util.List<org.eclipse.persistence.internal.helper.DatabaseField> allNonPrimaryKeyFields
-
-
Constructor Detail
-
FieldsLockingPolicy
public 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
-
addLockFieldsToUpdateRow
public void addLockFieldsToUpdateRow(org.eclipse.persistence.internal.sessions.AbstractRecord Record, org.eclipse.persistence.internal.sessions.AbstractSession session)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.- Specified by:
addLockFieldsToUpdateRowin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
addLockValuesToTranslationRow
public abstract void addLockValuesToTranslationRow(ObjectLevelModifyQuery query)
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.- Specified by:
addLockValuesToTranslationRowin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
buildAllNonPrimaryKeyFields
protected java.util.List 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.
-
buildDeleteExpression
public Expression buildDeleteExpression(org.eclipse.persistence.internal.helper.DatabaseTable table, Expression mainExpression, org.eclipse.persistence.internal.sessions.AbstractRecord row)
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.- Specified by:
buildDeleteExpressionin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
buildExpression
protected Expression buildExpression(org.eclipse.persistence.internal.helper.DatabaseTable table, org.eclipse.persistence.internal.sessions.AbstractRecord transRow, org.eclipse.persistence.internal.sessions.AbstractRecord modifyRow, ExpressionBuilder builder)
INTERNAL: returns the expression to be used in both the delete and update where clause.
-
buildUpdateExpression
public Expression buildUpdateExpression(org.eclipse.persistence.internal.helper.DatabaseTable table, Expression mainExpression, org.eclipse.persistence.internal.sessions.AbstractRecord transRow, org.eclipse.persistence.internal.sessions.AbstractRecord modifyRow)
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.- Specified by:
buildUpdateExpressionin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
clone
public java.lang.Object clone()
INTERNAL: Clone the policy- Specified by:
clonein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy- Overrides:
clonein classjava.lang.Object
-
supportsWriteLockValuesComparison
public boolean 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.- Specified by:
supportsWriteLockValuesComparisonin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
compareWriteLockValues
public int compareWriteLockValues(java.lang.Object value1, java.lang.Object value2)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.- Specified by:
compareWriteLockValuesin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
getAllNonPrimaryKeyFields
protected java.util.List<org.eclipse.persistence.internal.helper.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.
-
getAllNonPrimaryKeyFields
protected java.util.List<org.eclipse.persistence.internal.helper.DatabaseField> getAllNonPrimaryKeyFields(org.eclipse.persistence.internal.helper.DatabaseTable table)
INTERNAL: filter the fields based on the passed in table. Only return fields of this table.
-
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.- Specified by:
getBaseValuein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
getFieldsToCompare
protected abstract java.util.List<org.eclipse.persistence.internal.helper.DatabaseField> getFieldsToCompare(org.eclipse.persistence.internal.helper.DatabaseTable table, org.eclipse.persistence.internal.sessions.AbstractRecord transRow, org.eclipse.persistence.internal.sessions.AbstractRecord modifyRow)INTERNAL: Returns the fields that should be compared in the where clause. This method must be implemented by the subclass
-
getWriteLockField
public org.eclipse.persistence.internal.helper.DatabaseField getWriteLockField()
INTERNAL: Return the write lock field.- Specified by:
getWriteLockFieldin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
getWriteLockUpdateExpression
public Expression getWriteLockUpdateExpression(ExpressionBuilder builder, org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL:- Specified by:
getWriteLockUpdateExpressionin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
getLockOnChangeMode
public org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.LockOnChange 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- Specified by:
getLockOnChangeModein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
getValueToPutInCache
public java.lang.Object getValueToPutInCache(org.eclipse.persistence.internal.sessions.AbstractRecord row, org.eclipse.persistence.internal.sessions.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.- Specified by:
getValueToPutInCachein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
getVersionDifference
public int getVersionDifference(java.lang.Object currentValue, java.lang.Object domainObject, java.lang.Object primaryKeys, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Return the number of version difference between the two states of the object.- Specified by:
getVersionDifferencein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
getWriteLockValue
public java.lang.Object getWriteLockValue(java.lang.Object domainObject, java.lang.Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: This method will return the optimistic lock value for the object- Specified by:
getWriteLockValuein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
initialize
public void initialize(org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: It is responsible for initializing the policy;- Specified by:
initializein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
initializeProperties
public void initializeProperties()
INTERNAL: It is responsible for initializing the policy;- Specified by:
initializePropertiesin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
isStoredInCache
public boolean isStoredInCache()
PUBLIC: Return true if the lock value is stored in the cache.- Specified by:
isStoredInCachein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
isCascaded
public boolean isCascaded()
PUBLIC: Return true if the policy uses cascade locking. Currently, not supported on this policy at this time.- Specified by:
isCascadedin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
isNewerVersion
public boolean isNewerVersion(java.lang.Object currentValue, java.lang.Object domainObject, java.lang.Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Compares the value and the value from the object (or cache). Will return true if the object is newer than the row.- Specified by:
isNewerVersionin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
isNewerVersion
public boolean isNewerVersion(org.eclipse.persistence.internal.sessions.AbstractRecord Record, java.lang.Object domainObject, java.lang.Object primaryKey, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Compares the value from the row and from the object (or cache). Will return true if the object is newer than the row.- Specified by:
isNewerVersionin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
isPrimaryKey
protected boolean isPrimaryKey(org.eclipse.persistence.internal.helper.DatabaseField dbField)
INTERNAL: Returns whether or not this field is a primary key. This method will also return true for secondary table primarykeys
-
mergeIntoParentCache
public void mergeIntoParentCache(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow, java.lang.Object primaryKey, java.lang.Object object)INTERNAL: Only applicable when the value is stored in the cache.- Specified by:
mergeIntoParentCachein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
mergeIntoParentCache
public void mergeIntoParentCache(org.eclipse.persistence.internal.identitymaps.CacheKey unitOfWorkCacheKey, org.eclipse.persistence.internal.identitymaps.CacheKey parentSessionCacheKey)INTERNAL: This method should merge changes from the parent into the child. #see this method in VersionLockingPolicy- Specified by:
mergeIntoParentCachein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
setAllNonPrimaryKeyFields
protected void setAllNonPrimaryKeyFields(java.util.List allNonPrimaryKeyFields)
INTERNAL: Set method for all the primary keys
-
setDescriptor
public void setDescriptor(ClassDescriptor descriptor)
INTERNAL: Set method for the descriptor- Specified by:
setDescriptorin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
setLockOnChangeMode
public void setLockOnChangeMode(org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy.LockOnChange lockOnChangeMode)
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- Specified by:
setLockOnChangeModein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
setupWriteFieldsForInsert
public void setupWriteFieldsForInsert(ObjectLevelModifyQuery query)
INTERNAL: Put the initial writelock value into the modifyRow. There is nothing to do because all the lock values are in the mappings.- Specified by:
setupWriteFieldsForInsertin interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
updateRowAndObjectForUpdate
public void updateRowAndObjectForUpdate(ObjectLevelModifyQuery query, java.lang.Object domainObject)
INTERNAL: Nothing to do because all updates are handled by the application- Specified by:
updateRowAndObjectForUpdatein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
shouldUpdateVersionOnOwnedMappingChange
public boolean 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- Specified by:
shouldUpdateVersionOnOwnedMappingChangein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
shouldUpdateVersionOnMappingChange
public boolean 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- Specified by:
shouldUpdateVersionOnMappingChangein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
validateDelete
public void validateDelete(int rowCount, java.lang.Object object, DeleteObjectQuery query)INTERNAL: Check the row count for lock failure.- Specified by:
validateDeletein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
validateUpdate
public void validateUpdate(int rowCount, java.lang.Object object, WriteObjectQuery query)INTERNAL: Check the row count for lock failure.- Specified by:
validateUpdatein interfaceorg.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy
-
verifyUsage
protected void verifyUsage(org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: throw an exception if not inside a unit of work at this point
-
-