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

public Class SelectedFieldsLockingPolicy

extends FieldsLockingPolicy
Class Inheritance
Imports
java.util.ArrayList, .Collections, .HashMap, .Iterator, .List, .Map, org.eclipse.persistence.exceptions.DatabaseException, org.eclipse.persistence.internal.helper.DatabaseField, .DatabaseTable, org.eclipse.persistence.internal.sessions.AbstractRecord, .AbstractSession, org.eclipse.persistence.mappings.DatabaseMapping, .DatabaseMapping.WriteType, org.eclipse.persistence.queries.ObjectLevelModifyQuery

Purpose: An implementation of the OptimisticLockingPolicy interface. This policy compares selected fields in the WHERE clause when doing an update or a delete. If any field has been changed, an optimistic locking exception will be thrown. Note that the fields specified must be mapped and not be primary keys.

Note

This policy can only be used inside a unit of work.

Since
TopLink 2.5

Field Summary

Modifier and TypeField and Description
protected List<DatabaseField>
protected Map<DatabaseTable, List<DatabaseField>>
Inherited from org.eclipse.persistence.descriptors.FieldsLockingPolicy:
allNonPrimaryKeyFieldsdescriptor

Constructor Summary

AccessConstructor and Description
public
SelectedFieldsLockingPolicy()

PUBLIC: Create a new selected fields locking policy.

Method Summary

Modifier and TypeMethod and Description
public void
addLockFieldName(String fieldName)

PUBLIC: Add a field name to lock on.

public void
protected List<DatabaseField>
getFieldsToCompare(DatabaseTable table, AbstractRecord transRow, AbstractRecord modifyRow)

Implements abstract org.eclipse.persistence.descriptors.FieldsLockingPolicy.getFieldsToCompare.

INTERNAL: returns the lock fields to compare based on the passed in table.
public List<DatabaseField>
getLockFields()

INTERNAL: Returns the lock fields

protected List<DatabaseField>
getLockFields(DatabaseTable table)

INTERNAL: returns the lock fields based on the passed in table

protected Map<DatabaseTable, List<DatabaseField>>
getLockFieldsByTable()

INTERNAL: returns the lock fields

public void
public void
setLockFieldNames(List<String> lockFieldNames)

PUBLIC: Set the field names to lock on.

protected void
setLockFields(List<DatabaseField> lockFields)

INTERNAL: Sets the lock fields

protected void
setLockFieldsByTable(Map<DatabaseTable, List<DatabaseField>> lockFieldsByTable)

INTERNAL: Used to set the field names to be used in this policy.

Inherited from org.eclipse.persistence.descriptors.FieldsLockingPolicy:
addLockFieldsToUpdateRowbuildAllNonPrimaryKeyFieldsbuildDeleteExpressionbuildExpressionbuildUpdateExpressionclonecompareWriteLockValuesgetAllNonPrimaryKeyFieldsgetAllNonPrimaryKeyFieldsgetBaseValuegetLockOnChangeModegetValueToPutInCachegetVersionDifferencegetWriteLockFieldgetWriteLockUpdateExpressiongetWriteLockValueinitializePropertiesisCascadedisNewerVersionisNewerVersionisPrimaryKeyisStoredInCachemergeIntoParentCachemergeIntoParentCachesetAllNonPrimaryKeyFieldssetDescriptorsetLockOnChangeModesetupWriteFieldsForInsertshouldUpdateVersionOnMappingChangeshouldUpdateVersionOnOwnedMappingChangesupportsWriteLockValuesComparisonupdateRowAndObjectForUpdatevalidateDeletevalidateUpdateverifyUsage

Field Detail

lockFieldsback to summary
protected List<DatabaseField> lockFields
lockFieldsByTableback to summary
protected Map<DatabaseTable, List<DatabaseField>> lockFieldsByTable

Constructor Detail

SelectedFieldsLockingPolicyback to summary
public SelectedFieldsLockingPolicy()

PUBLIC: Create a new selected fields locking policy. A field locking policy is based on locking on the specified 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

addLockFieldNameback to summary
public void addLockFieldName(String fieldName)

PUBLIC: Add a field name to lock on. All fields in this list will be compared when updating if the value of any of the fields does not match the value in memory, an OptimisticLockException will be thrown.

Note

An Automatic update will not be done on this field, only a comparison occurs.

addLockValuesToTranslationRowback to summary
public void addLockValuesToTranslationRow(ObjectLevelModifyQuery query) throws DatabaseException

Implements abstract org.eclipse.persistence.descriptors.FieldsLockingPolicy.addLockValuesToTranslationRow.

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

INTERNAL: Values to be included in the locking mechanism are added to the translation row. For changed fields the normal build row is ok as only changed fields matter.

Annotations
@Override
getFieldsToCompareback to summary
protected List<DatabaseField> getFieldsToCompare(DatabaseTable table, AbstractRecord transRow, AbstractRecord modifyRow)

Implements abstract org.eclipse.persistence.descriptors.FieldsLockingPolicy.getFieldsToCompare.

INTERNAL: returns the lock fields to compare based on the passed in table.

Annotations
@Override
getLockFieldsback to summary
public List<DatabaseField> getLockFields()

INTERNAL: Returns the lock fields

getLockFieldsback to summary
protected List<DatabaseField> getLockFields(DatabaseTable table)

INTERNAL: returns the lock fields based on the passed in table

getLockFieldsByTableback to summary
protected Map<DatabaseTable, List<DatabaseField>> getLockFieldsByTable()

INTERNAL: returns the lock fields

initializeback to summary
public void initialize(AbstractSession session)

Overrides org.eclipse.persistence.descriptors.FieldsLockingPolicy.initialize.

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

INTERNAL: It is responsible for initializing the policy;

Annotations
@Override
setLockFieldNamesback to summary
public void setLockFieldNames(List<String> lockFieldNames)

PUBLIC: Set the field names to lock on. All fields in this list will be compared when Updating. If the value of any of the fields does not match the value in memory, an OptimisticLockException will be thrown.

Note

An Automatic update will not be done on this field, only a comparison occurs.

setLockFieldsback to summary
protected void setLockFields(List<DatabaseField> lockFields)

INTERNAL: Sets the lock fields

setLockFieldsByTableback to summary
protected void setLockFieldsByTable(Map<DatabaseTable, List<DatabaseField>> lockFieldsByTable)

INTERNAL: Used to set the field names to be used in this policy.