org.jboss.cache.transaction
Class TransactionTable

java.lang.Object
  extended by org.jboss.cache.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.

Version:
$Revision: 7604 $
Author:
Bela Ban Apr 14, 2003

Field Summary
protected  Map<GlobalTransaction,TransactionContext> gtx2ContextMap
          Mappings between GlobalTransactions and modifications.
protected  Map<GlobalTransaction,Transaction> gtx2TxMap
           
protected  Map<Transaction,GlobalTransaction> tx2gtxMap
          Mapping between local (javax.transaction.Transaction) and GlobalTransactions.
 
Constructor Summary
TransactionTable()
           
 
Method Summary
static void assertTransactionValid(InvocationContext ctx)
          Tests whether the caller is in a valid transaction.
 TransactionContext get(GlobalTransaction gtx)
          Returns the local transaction entry for the global transaction.
 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)
          Returns the local transaction associated with a GlobalTransaction.
 Transaction getLocalTransaction(GlobalTransaction gtx, boolean assertExists)
          If assers exists is true and the coresponding local transaction is null an IllegalStateExcetpion is being thrown.
 int getNumberOfRegisteredTransactions()
           
 int getNumGlobalTransactions()
          Returns the number of global transactions.
 int getNumLocalTransactions()
          Returns the number of local transactions.
 String getTransactionMap()
           
 void initialize(TransactionManager transactionManager, RPCManager rpcManager, ContextFactory contextFactory)
           
static boolean isActive(Transaction tx)
          Returns true if transaction is ACTIVE, false otherwise
static boolean isMarkedAsRollback(Transaction tx)
          Returns true if transaction is STATUS_MARKED_ROLLBACK, false otherwise
static boolean isPreparing(Transaction tx)
          Returns true if transaction is PREPARING, false otherwise
static boolean isValid(Transaction tx)
          Returns true of tx's status is ACTIVE or PREPARING or MARKED_ROLLBACK
 void put(GlobalTransaction tx, TransactionContext transactionContext)
          Associates the global transaction with a transaction context.
 void put(Transaction tx, GlobalTransaction gtx)
          Associates the global transaction with the local transaction.
 TransactionContext remove(GlobalTransaction tx)
          Removes a global transation, returns the old transaction entry.
 void remove(GlobalTransaction gtx, Transaction tx)
           
 GlobalTransaction remove(Transaction tx)
          Removes a local transation, returns the global transaction entry.
 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

tx2gtxMap

protected final Map<Transaction,GlobalTransaction> tx2gtxMap
Mapping between local (javax.transaction.Transaction) and GlobalTransactions. New: a local TX can have a number of GTXs


gtx2ContextMap

protected final Map<GlobalTransaction,TransactionContext> gtx2ContextMap
Mappings between GlobalTransactions and modifications.


gtx2TxMap

protected final Map<GlobalTransaction,Transaction> gtx2TxMap
Constructor Detail

TransactionTable

public TransactionTable()
Method Detail

initialize

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

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)
Returns the local transaction associated with a GlobalTransaction.

Parameters:
gtx - The GlobalTransaction
Returns:
Transaction. The local transaction associated with a given GlobalTransaction). This will be null if no local transaction is associated with a given GTX

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.


put

public void put(Transaction tx,
                GlobalTransaction gtx)
Associates the global transaction with the local transaction.


get

public TransactionContext get(GlobalTransaction gtx)
Returns the local transaction entry for the global transaction. Returns null if tx is null or it was not found.


put

public void put(GlobalTransaction tx,
                TransactionContext transactionContext)
Associates the global transaction with a transaction context.


remove

public TransactionContext remove(GlobalTransaction tx)
Removes a global transation, returns the old transaction entry.


remove

public GlobalTransaction remove(Transaction tx)
Removes a local transation, returns the global transaction entry.


remove

public void remove(GlobalTransaction gtx,
                   Transaction tx)

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


isMarkedAsRollback

public static boolean isMarkedAsRollback(Transaction tx)
Returns true if transaction is STATUS_MARKED_ROLLBACK, false otherwise


isValid

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

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

getNumberOfRegisteredTransactions

public int getNumberOfRegisteredTransactions()

getTransactionMap

public String getTransactionMap()


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