Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


com.tangosol.run.jca
Class SimpleValidator

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.run.jca.SimpleValidator

All Implemented Interfaces:
TransactionMap.Validator

public class SimpleValidator
extends Base
implements TransactionMap.Validator

Simple generic Validator implementation that uses hashCode values for the enlisted resources to resolve optimistic transaction conflicts.

Since:
Coherence 2.3
Author:
gg 2003.12.19

Field Summary
protected  java.util.Map m_mapVersion
          The map that holds version objects for enlisted resources.

 

Constructor Summary
SimpleValidator()
          Default constructor.

 

Method Summary
protected  java.lang.Comparable calculateVersion(java.lang.Object oValue)
          Generate the Comparable version indicator for a given resource value.
 void enlist(TransactionMap mapTx, java.lang.Object oKey)
          Enlist the resource with the specified transaction.
 TransactionMap.Validator getNextValidator()
          Retrive the next Validator.
 java.util.Map getVersionMap()
          Obtain a map that holds the version objects for resources enlisted into a transaction.
 void setNextValidator(TransactionMap.Validator validator)
          Set the next Validator.
 void validate(TransactionMap mapTx, java.util.Set setInsert, java.util.Set setUpdate, java.util.Set setDelete, java.util.Set setRead, java.util.Set setPhantom)
          Validate that the content of the TransactionMap is "fit" to be committed into the base map.
protected  void validateInsert(TransactionMap mapTx, java.util.Set setKey)
          Validate the set of the inserts.
protected  void validateValue(TransactionMap mapTx, java.util.Set setKey)
          Validate the set of the read values.
protected  void validateVersion(TransactionMap mapTx, java.util.Set setKey)
          Validate the set of the updates or deletes.

 

Field Detail

m_mapVersion

protected java.util.Map m_mapVersion
The map that holds version objects for enlisted resources.

Constructor Detail

SimpleValidator

public SimpleValidator()
Default constructor.

Method Detail

getVersionMap

public java.util.Map getVersionMap()
Obtain a map that holds the version objects for resources enlisted into a transaction.
Returns:
the versions map

enlist

public void enlist(TransactionMap mapTx,
                   java.lang.Object oKey)
Enlist the resource with the specified transaction.

This method is invoked for all resources that are "used" by the transaction immediately before the resource value is copied into the local map. If the resource value implements the Versionable interface, the corresponding version indicator will be placed into the version map; otherwise the value's hashCode will be used.

It is this method's responsibility to call a next Validator in the validation chain.

Specified by:
enlist in interface TransactionMap.Validator
Parameters:
mapTx - the TransactionMap to enlist the resource with
oKey - the resource key to be enlisted with the transaction

validate

public void validate(TransactionMap mapTx,
                     java.util.Set setInsert,
                     java.util.Set setUpdate,
                     java.util.Set setDelete,
                     java.util.Set setRead,
                     java.util.Set setPhantom)
              throws java.util.ConcurrentModificationException
Validate that the content of the TransactionMap is "fit" to be committed into the base map.

This method is invoked during "prepare" phase after all the resources involved in this transaction are successfully locked at the base map. The Validator is expected to retrieve the "old" and "new" values (using map.get(oKey), map.getBaseMap().get(oKey)) and use the information gathered during "enlist" calls to make the determination whether or not commit should be allowed to proceed.

To force a roll back it should throw an exception indicating the reason this transaction cannot be committed. When that happens, the sets are expected to hold just the keys of the "offending" resources.

It is this method's responsibility to call a next Validator in the validation chain (i.e. getNextValidator().validate(map, setI, setU, setD, setR, setF);)

Specified by:
validate in interface TransactionMap.Validator
Parameters:
mapTx - the TransactionMap that is being prepared
setInsert - the set of inserted resources
setUpdate - the set of updated resources
setDelete - the set of deleted resources
setRead - the set of read resources. It is always empty for TRANSACTION_GET_COMMITTED isolation level.
setPhantom - the set of phantom resources, that is resources that were added to the base map, but were not known to the transaction. This set can be not empty only for TRANSACTION_GET_SERIALIZED isolation level.
Throws:
java.util.ConcurrentModificationException - if the validator detects an unresolveable conflict between the resources

getNextValidator

public TransactionMap.Validator getNextValidator()
Retrive the next Validator.
Specified by:
getNextValidator in interface TransactionMap.Validator
Returns:
the next Validator

setNextValidator

public void setNextValidator(TransactionMap.Validator validator)
Set the next Validator.
Specified by:
setNextValidator in interface TransactionMap.Validator
Parameters:
validator - the Validator to be added

validateInsert

protected void validateInsert(TransactionMap mapTx,
                              java.util.Set setKey)
Validate the set of the inserts.

If the inserts do not exist in the base map (as they should not), remove them from the specified key set, so only keys corresponding to the conflicting inserts are left in the key set.

Parameters:
mapTx - the TransactionMap
setKey - the key set of inserted resources
Throws:
java.util.ConcurrentModificationException - if conflicts are detected

validateVersion

protected void validateVersion(TransactionMap mapTx,
                               java.util.Set setKey)
Validate the set of the updates or deletes.

If the version of an updated or removed resource matches to the version stored off in the version map at the time when the resource was enlisted, remove it from the specified key set, so only keys corresponding to the conflicting updates, removes or reads are left in the key set.

Parameters:
mapTx - the TransactionMap
setKey - the key set of updated or removed resources
Throws:
java.util.ConcurrentModificationException - if conflicts are detected

validateValue

protected void validateValue(TransactionMap mapTx,
                             java.util.Set setKey)
Validate the set of the read values.

If the values that were read during transaction are equal to the values as they exist in the base map, remove them from the specified key set, so only keys corresponding to the conflicting reads are left in the set.

Note: this can occur only for repeatable or serializable isolation level.

Parameters:
mapTx - the TransactionMap
setKey - the key set of read resources
Throws:
java.util.ConcurrentModificationException - if conflicts are detected

calculateVersion

protected java.lang.Comparable calculateVersion(java.lang.Object oValue)
Generate the Comparable version indicator for a given resource value.

If the value implements the Versionable interface, the corresponding version indicator is returned; otherwise the value's hashCode is used.

Returns:
a Comparable version indicator

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.