org.infinispan.transaction
Class TransactionTable

java.lang.Object
  extended by org.infinispan.transaction.TransactionTable

public class TransactionTable
extends Object

Maintains the mapping between a local Transaction and a GlobalTransaction. Also stores TransactionContext instances under a given transaction.

Since:
4.0
Author:
Bela Ban Apr 14, 2003

Field Summary
protected  Map<GlobalTransaction,TransactionContext> gtxMapping
          Mappong between GlobalTransaction and a TransactionContext
protected  Map<Transaction,TransactionContext> txMapping
          Mapping between local (javax.transaction.Transaction) and a TransactionContext
 
Constructor Summary
TransactionTable()
           
 
Method Summary
static void assertTransactionValid(InvocationContext ctx)
          Tests whether the caller is in a valid transaction.
 void associateTransaction(Transaction tx, GlobalTransaction gtx, TransactionContext ctx)
          Associates 3 elements of a transaction - a local Transaction, a GlobalTransaction and a TransactionContext - with each other.
 void cleanup(GlobalTransaction gtx)
           
 GlobalTransaction get(Transaction tx)
          Returns the global transaction associated with the local transaction.
 GlobalTransaction getCurrentTransaction()
          Returns the transaction associated with the current thread.
 GlobalTransaction getCurrentTransaction(boolean createIfNotExists)
          Returns the transaction associated with the thread; optionally creating it if is does not exist.
 GlobalTransaction getCurrentTransaction(Transaction tx)
          Returns the global transaction for this local transaction.
 GlobalTransaction getCurrentTransaction(Transaction tx, boolean createIfNotExists)
          Returns the global transaction for this local transaction.
protected  Transaction getLocalTransaction()
          Returns the transaction associated with the current thread.
 Transaction getLocalTransaction(GlobalTransaction gtx)
           
 Transaction getLocalTransaction(GlobalTransaction gtx, boolean assertExists)
          If assers exists is true and the coresponding local transaction is null an IllegalStateExcetpion is being thrown.
 int getNumGlobalTransactions()
          Returns the number of global transactions.
 int getNumLocalTransactions()
          Returns the number of local transactions.
 TransactionContext getTransactionContext(GlobalTransaction gtx)
           
 void initialize(TransactionManager transactionManager, RpcManager rpcManager, ContextFactory contextFactory)
           
static boolean isActive(Transaction tx)
          Returns true if transaction is ACTIVE, false otherwise
static boolean isPreparing(Transaction tx)
          Returns true if transaction is PREPARING, false otherwise
static boolean isValid(Transaction tx)
          Return s true of tx's status is ACTIVE or PREPARING
 void start()
           
 String toString()
          Returns summary debug information.
 String toString(boolean printDetails)
          Returns detailed debug information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

txMapping

protected final Map<Transaction,TransactionContext> txMapping
Mapping between local (javax.transaction.Transaction) and a TransactionContext


gtxMapping

protected final Map<GlobalTransaction,TransactionContext> gtxMapping
Mappong between GlobalTransaction and a TransactionContext

Constructor Detail

TransactionTable

public TransactionTable()
Method Detail

initialize

public void initialize(TransactionManager transactionManager,
                       RpcManager rpcManager,
                       ContextFactory contextFactory)

start

public void start()

getNumLocalTransactions

public int getNumLocalTransactions()
Returns the number of local transactions.


getNumGlobalTransactions

public int getNumGlobalTransactions()
Returns the number of global transactions.


get

public GlobalTransaction get(Transaction tx)
Returns the global transaction associated with the local transaction. Returns null if tx is null or it was not found.


getLocalTransaction

public Transaction getLocalTransaction(GlobalTransaction gtx,
                                       boolean assertExists)
If assers exists is true and the coresponding local transaction is null an IllegalStateExcetpion is being thrown.


associateTransaction

public void associateTransaction(Transaction tx,
                                 GlobalTransaction gtx,
                                 TransactionContext ctx)
Associates 3 elements of a transaction - a local Transaction, a GlobalTransaction and a TransactionContext - with each other.

Parameters:
tx - transaction to associate
gtx - global transaction to associate
ctx - transaction context to associate

getLocalTransaction

public Transaction getLocalTransaction(GlobalTransaction gtx)

toString

public String toString()
Returns summary debug information.

Overrides:
toString in class Object

toString

public String toString(boolean printDetails)
Returns detailed debug information.


getCurrentTransaction

public GlobalTransaction getCurrentTransaction()
Returns the transaction associated with the current thread. If a local transaction exists, but doesn't yet have a mapping to a GlobalTransaction, a new GlobalTransaction will be created and mapped to the local transaction. Note that if a local transaction exists, but is not ACTIVE or PREPARING, null is returned.

Returns:
A GlobalTransaction, or null if no (local) transaction was associated with the current thread

getCurrentTransaction

public GlobalTransaction getCurrentTransaction(boolean createIfNotExists)
Returns the transaction associated with the thread; optionally creating it if is does not exist.


getLocalTransaction

protected Transaction getLocalTransaction()
Returns the transaction associated with the current thread. We get the initial context and a reference to the TransactionManager to get the transaction. This method is used by getCurrentTransaction()


isActive

public static boolean isActive(Transaction tx)
Returns true if transaction is ACTIVE, false otherwise


isPreparing

public static boolean isPreparing(Transaction tx)
Returns true if transaction is PREPARING, false otherwise


isValid

public static boolean isValid(Transaction tx)
Return s true of tx's status is ACTIVE or PREPARING

Parameters:
tx -
Returns:
true if the tx is active or preparing

assertTransactionValid

public static void assertTransactionValid(InvocationContext ctx)
Tests whether the caller is in a valid transaction. If not, will throw a CacheException.


getCurrentTransaction

public GlobalTransaction getCurrentTransaction(Transaction tx)
Returns the global transaction for this local transaction.


getCurrentTransaction

public GlobalTransaction getCurrentTransaction(Transaction tx,
                                               boolean createIfNotExists)
Returns the global transaction for this local transaction.

Parameters:
createIfNotExists - if true, if a global transaction is not found; one is created

getTransactionContext

public TransactionContext getTransactionContext(GlobalTransaction gtx)

cleanup

public void cleanup(GlobalTransaction gtx)


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