org.jboss.cache.transaction
Interface TransactionContext

All Known Implementing Classes:
AbstractTransactionContext, MVCCTransactionContext, OptimisticTransactionContext, PessimisticTransactionContext

public interface TransactionContext

Captures information pertaining to a specific JTA transaction.

This was a concrete class called TransactionEntry prior to 3.0.

Author:
Manik Surtani (manik AT jboss DOT org)
See Also:
InvocationContext

Method Summary
 void addAllLocks(List newLocks)
          Adds a List of locks to the currently maintained collection of locks acquired.
 void addDummyNodeCreatedByCacheLoader(Fqn fqn)
          Adds an Fqn to the list of uninitialized nodes created by the cache loader.
 void addLocalModification(WriteCommand command)
          Adds a modification to the local modification list.
 void addLock(Object lock)
          Adds a lock to the currently maintained collection of locks acquired.
 void addModification(WriteCommand command)
          Adds a modification to the modification list.
 void addRemovedNode(Fqn fqn)
          Adds the node that has been removed in the scope of the current transaction.
 void clearLocks()
          Clears all locks from the currently maintained collection of locks acquired.
 List<Fqn> getDummyNodesCreatedByCacheLoader()
           
 List<WriteCommand> getLocalModifications()
          Returns all modifications that have been invoked with the LOCAL cache mode option.
 List getLocks()
          Returns an immutable, defensive copy of the List of locks currently maintained for the transaction.
 List<WriteCommand> getModifications()
          Returns all modifications.
 Option getOption()
          Retrieves a transaction scope option override
 OrderedSynchronizationHandler getOrderedSynchronizationHandler()
           
 List<Fqn> getRemovedNodes()
          Gets the list of removed nodes.
 Transaction getTransaction()
          Returns a local transaction associated with this context.
 boolean hasAnyModifications()
           
 boolean hasLocalModifications()
           
 boolean hasLock(Object lock)
          Most code could not use this method directly, but use InvocationContext.hasLock(Object) ()} instead, which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
 boolean hasModifications()
           
 boolean isForceAsyncReplication()
          Gets the value of the forceAsyncReplication flag.
 boolean isForceSyncReplication()
          Gets the value of the forceSyncReplication flag.
 void removeLock(Object lock)
          Removes a lock from the currently maintained collection of locks acquired.
 void reset()
          Cleans up internal state, freeing up references.
 void setForceAsyncReplication(boolean forceAsyncReplication)
          Sets the value of the forceAsyncReplication flag.
 void setForceSyncReplication(boolean forceSyncReplication)
          Sets the value of the forceSyncReplication flag.
 void setOption(Option o)
          Sets a transaction-scope option override
 void setOrderedSynchronizationHandler(OrderedSynchronizationHandler orderedSynchronizationHandler)
          Associates an ordered sync handler with this transaction.
 void setTransaction(Transaction tx)
          Sets the local transaction to be associated with this transaction context.
 

Method Detail

addModification

void addModification(WriteCommand command)
Adds a modification to the modification list.

Parameters:
command - modification

getModifications

List<WriteCommand> getModifications()
Returns all modifications. If there are no modifications in this transaction this method will return an empty list.

Returns:
list of modifications.

addLocalModification

void addLocalModification(WriteCommand command)
Adds a modification to the local modification list.

Parameters:
command - command to add to list. Should not be null.
Throws:
NullPointerException - if the command to be added is null.

getLocalModifications

List<WriteCommand> getLocalModifications()
Returns all modifications that have been invoked with the LOCAL cache mode option. These will also be in the standard modification list.

Returns:
list of LOCAL modifications, or an empty list.

addRemovedNode

void addRemovedNode(Fqn fqn)
Adds the node that has been removed in the scope of the current transaction.

Parameters:
fqn - fqn that has been removed.
Throws:
NullPointerException - if the Fqn is null.

getRemovedNodes

List<Fqn> getRemovedNodes()
Gets the list of removed nodes.

Returns:
list of nodes removed in the current transaction scope. Note that this method will return an empty list if nothing has been removed. The list returned is defensively copied.

setTransaction

void setTransaction(Transaction tx)
Sets the local transaction to be associated with this transaction context.

Parameters:
tx - JTA transaction to associate with.

getTransaction

Transaction getTransaction()
Returns a local transaction associated with this context.

Returns:
a JTA transaction

addLock

void addLock(Object lock)
Adds a lock to the currently maintained collection of locks acquired.

Most code could not use this method directly, but use InvocationContext.addLock(Object) instead, which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.

Note that currently (as of 3.0.0) this lock is weakly typed. This is to allow support for both MVCC (which uses Fqns as locks) as well as legacy Optimistic and Pessimistic Locking schemes (which use NodeLock as locks). Once support for legacy node locking schemes are dropped, this method will be more strongly typed to accept Fqn.

Parameters:
lock - lock to add
See Also:
InvocationContext.addLock(Object)

removeLock

void removeLock(Object lock)
Removes a lock from the currently maintained collection of locks acquired.

Most code could not use this method directly, but use InvocationContext.removeLock(Object) instead, which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.

Note that currently (as of 3.0.0) this lock is weakly typed. This is to allow support for both MVCC (which uses Fqns as locks) as well as legacy Optimistic and Pessimistic Locking schemes (which use NodeLock as locks). Once support for legacy node locking schemes are dropped, this method will be more strongly typed to accept Fqn.

Parameters:
lock - lock to remove
See Also:
InvocationContext.removeLock(Object)

clearLocks

void clearLocks()
Clears all locks from the currently maintained collection of locks acquired.

Most code could not use this method directly, but use InvocationContext.clearLocks() instead, which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.

Note that currently (as of 3.0.0) this lock is weakly typed. This is to allow support for both MVCC (which uses Fqns as locks) as well as legacy Optimistic and Pessimistic Locking schemes (which use NodeLock as locks). Once support for legacy node locking schemes are dropped, this method will be more strongly typed to accept Fqn.

See Also:
InvocationContext.clearLocks()

addAllLocks

void addAllLocks(List newLocks)
Adds a List of locks to the currently maintained collection of locks acquired.

Most code could not use this method directly, but use InvocationContext.addAllLocks(java.util.List) instead, which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.

Note that currently (as of 3.0.0) this list is unchecked. This is to allow support for both MVCC (which uses Fqns as locks) as well as legacy Optimistic and Pessimistic Locking schemes (which use NodeLock as locks). Once support for legacy node locking schemes are dropped, this method will be more strongly typed to accept List.

Parameters:
newLocks - locks to add
See Also:
InvocationContext.addAllLocks(java.util.List)

getLocks

List getLocks()
Returns an immutable, defensive copy of the List of locks currently maintained for the transaction.

Most code could not use this method directly, but use InvocationContext.getLocks() instead, which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.

Note that currently (as of 3.0.0) this list is unchecked. This is to allow support for both MVCC (which uses Fqns as locks) as well as legacy Optimistic and Pessimistic Locking schemes (which use NodeLock as locks). Once support for legacy node locking schemes are dropped, this method will be more strongly typed to return List.

Returns:
locks held in current scope.
See Also:
InvocationContext.getLocks()

hasLock

boolean hasLock(Object lock)
Most code could not use this method directly, but use InvocationContext.hasLock(Object) ()} instead, which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.

Parameters:
lock - lock to test
Returns:
true if the lock being tested is already held in the current scope, false otherwise.

isForceAsyncReplication

boolean isForceAsyncReplication()
Gets the value of the forceAsyncReplication flag. Used by ReplicationInterceptor and OptimisticReplicationInterceptor when dealing with Cache.putForExternalRead(org.jboss.cache.Fqn,Object,Object) within a transactional context.

Returns:
true if the forceAsyncReplication flag is set to true.

setForceAsyncReplication

void setForceAsyncReplication(boolean forceAsyncReplication)
Sets the value of the forceAsyncReplication flag. Used by ReplicationInterceptor and OptimisticReplicationInterceptor when dealing with Cache.putForExternalRead(org.jboss.cache.Fqn,Object,Object) within a transactional context. Also used by OptimisticReplicationInterceptor when dealing with Option.setForceAsynchronous(boolean) in a non-transactional context (i.e. with an implicit transaction).

Parameters:
forceAsyncReplication - value of forceAsyncReplication

isForceSyncReplication

boolean isForceSyncReplication()
Gets the value of the forceSyncReplication flag. Used by ReplicationInterceptor and OptimisticReplicationInterceptor when dealing with Cache.putForExternalRead(org.jboss.cache.Fqn,Object,Object) within a transactional context.

Returns:
true if the forceAsyncReplication flag is set to true.

setForceSyncReplication

void setForceSyncReplication(boolean forceSyncReplication)
Sets the value of the forceSyncReplication flag. Used by ReplicationInterceptor and OptimisticReplicationInterceptor when dealing with Cache.putForExternalRead(org.jboss.cache.Fqn,Object,Object) within a transactional context.

Parameters:
forceSyncReplication - value of forceSyncReplication

addDummyNodeCreatedByCacheLoader

void addDummyNodeCreatedByCacheLoader(Fqn fqn)
Adds an Fqn to the list of uninitialized nodes created by the cache loader.

Parameters:
fqn - fqn to add. Must not be null.

getDummyNodesCreatedByCacheLoader

List<Fqn> getDummyNodesCreatedByCacheLoader()
Returns:
a list of uninitialized nodes created by the cache loader, or an empty list.

setOption

void setOption(Option o)
Sets a transaction-scope option override

Parameters:
o - option to set

getOption

Option getOption()
Retrieves a transaction scope option override

Returns:
option

getOrderedSynchronizationHandler

OrderedSynchronizationHandler getOrderedSynchronizationHandler()
Returns:
the ordered sync handler associated with this transaction

setOrderedSynchronizationHandler

void setOrderedSynchronizationHandler(OrderedSynchronizationHandler orderedSynchronizationHandler)
Associates an ordered sync handler with this transaction.

Parameters:
orderedSynchronizationHandler - to set

hasModifications

boolean hasModifications()
Returns:
true if modifications were registered.

hasLocalModifications

boolean hasLocalModifications()
Returns:
true if any modifications have been invoked with cache mode being LOCAL.

hasAnyModifications

boolean hasAnyModifications()
Returns:
true if either there are modifications or local modifications that are not for replicating.

reset

void reset()
Cleans up internal state, freeing up references.



Copyright © 2009 JBoss, a division of Red Hat. All Rights Reserved.