org.multiverse.api
Class ThreadLocalTransaction

java.lang.Object
  extended by org.multiverse.api.ThreadLocalTransaction

public final class ThreadLocalTransaction
extends Object

A ThreadLocal that contains the current Transaction. The Stm and the Transaction should not rely on threadlocals, they are only used for convenience to reduce the need to carry around a Transaction.

Author:
Peter Veentjer.

Field Summary
static ThreadLocal<Transaction> threadlocal
           
 
Method Summary
static void clearThreadLocalTransaction()
          Clears the threadlocal transaction.
static Transaction getRequiredThreadLocalTransaction()
          Gets the threadlocal transaction or throws a NoTransactionException if no transaction is found.
static Transaction getThreadLocalTransaction()
          Gets the threadlocal transaction.
static void setThreadLocalTransaction(Transaction tx)
          Sets the threadlocal transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

threadlocal

public static final ThreadLocal<Transaction> threadlocal
Method Detail

getThreadLocalTransaction

public static Transaction getThreadLocalTransaction()
Gets the threadlocal transaction. If no transaction is set, null is returned.

No checks are done on the state of the transaction (so it could be that an aborted or committed transaction is returned).

Returns:
the threadlocal transaction.

getRequiredThreadLocalTransaction

public static Transaction getRequiredThreadLocalTransaction()
Gets the threadlocal transaction or throws a NoTransactionException if no transaction is found.

No checks are done on the state of the transaction (so it could be that an aborted or committed transaction is returned).

Returns:
the threadlocal transaction.
Throws:
NoTransactionFoundException - if no thread local transaction is found.

clearThreadLocalTransaction

public static void clearThreadLocalTransaction()
Clears the threadlocal transaction.

If a transaction is available, it isn't aborted or committed.


setThreadLocalTransaction

public static void setThreadLocalTransaction(Transaction tx)
Sets the threadlocal transaction. The transaction is allowed to be null, effectively clearing the current thread local transaction.

If a transaction is available, it isn't aborted or committed.

Parameters:
tx - the new thread local transaction.


Copyright © 2008-2010 Multiverse. All Rights Reserved.