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 TransactionEntry instances under a given transaction.

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

Field Summary
protected  Map<GlobalTransaction,TransactionEntry> gtx2EntryMap
          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.
 TransactionEntry 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 getNumGlobalTransactions()
          Returns the number of global transactions.
 int getNumLocalTransactions()
          Returns the number of local transactions.
 void initialize(TransactionManager transactionManager, RPCManager rpcManager, Configuration configuration)
           
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 put(GlobalTransaction tx, TransactionEntry entry)
          Associates the global transaction with a transaction entry.
 void put(Transaction tx, GlobalTransaction gtx)
          Associates the global transaction with the local transaction.
 TransactionEntry 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.
 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

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


gtx2EntryMap

protected final Map<GlobalTransaction,TransactionEntry> gtx2EntryMap
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,
                       Configuration configuration)

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)
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 TransactionEntry 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,
                TransactionEntry entry)
Associates the global transaction with a transaction entry.


remove

public TransactionEntry 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


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


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