org.ofbiz.entity.transaction
Class TransactionUtil

java.lang.Object
  extended by org.ofbiz.entity.transaction.TransactionUtil

public class TransactionUtil
extends java.lang.Object

Transaction Utility to help with some common transaction tasks

Provides a wrapper around the transaction objects to allow for changes in underlying implementations in the future.


Nested Class Summary
static class TransactionUtil.StampClearSync
           
 
Field Summary
static java.util.Map<javax.transaction.xa.Xid,DebugXaResource> debugResMap
           
static boolean debugResources
           
static java.lang.String module
           
 
Constructor Summary
TransactionUtil()
           
 
Method Summary
static boolean begin()
          Begins a transaction in the current thread IF transactions are available; only tries if the current transaction status is ACTIVE, if not active it returns false.
static boolean begin(int timeout)
          Begins a transaction in the current thread IF transactions are available; only tries if the current transaction status is ACTIVE, if not active it returns false.
static int cleanSuspendedTransactions()
          BE VERY CARFUL WHERE YOU CALL THIS!!
protected static void clearTransactionStamps()
           
static void commit()
          Commits the transaction in the current thread IF transactions are available
static void commit(boolean beganTransaction)
          Commits the transaction in the current thread IF transactions are available AND if beganTransaction is true
static java.sql.Connection enlistConnection(javax.sql.XAConnection xacon)
          Enlists the given XAConnection and if a transaction is active in the current thread, returns a plain JDBC Connection
static void enlistResource(javax.transaction.xa.XAResource resource)
           
static java.util.Map<java.lang.Long,java.util.List<java.lang.Exception>> getAllThreadsTransactionBeginStackSave()
           
static org.ofbiz.entity.transaction.TransactionUtil.RollbackOnlyCause getSetRollbackOnlyCause()
           
static int getStatus()
          Gets the status of the transaction in the current thread IF transactions are available, otherwise returns STATUS_NO_TRANSACTION
static java.lang.String getStatusString()
           
static java.lang.Exception getTransactionBeginStack()
           
static java.util.List<java.lang.Exception> getTransactionBeginStackSave()
           
static int getTransactionBeginStackSaveSize()
           
static java.sql.Timestamp getTransactionStartStamp()
           
static java.lang.String getTransactionStateString(int state)
           
static java.sql.Timestamp getTransactionUniqueNowStamp()
           
static boolean isTransactionInPlace()
           
static void logRunningTx()
           
protected static Transaction popSuspendedTransaction()
           
static void printAllThreadsTransactionBeginStacks()
           
protected static void pushSuspendedTransaction(Transaction t)
           
static void registerSynchronization(Synchronization sync)
           
protected static void removeSuspendedTransaction(Transaction t)
           
static void resume(Transaction parentTx)
           
static void rollback()
          Rolls back transaction in the current thread IF transactions are available
static void rollback(boolean beganTransaction)
          Deprecated.  
static void rollback(boolean beganTransaction, java.lang.String causeMessage, java.lang.Throwable causeThrowable)
          Rolls back transaction in the current thread IF transactions are available AND if beganTransaction is true; if beganTransaction is not true, setRollbackOnly is called to insure that the transaction will be rolled back
static void setRollbackOnly(java.lang.String causeMessage, java.lang.Throwable causeThrowable)
          Makes a rollback the only possible outcome of the transaction in the current thread IF transactions are available
static void setTransactionTimeout(int seconds)
          Sets the timeout of the transaction in the current thread IF transactions are available
static Transaction suspend()
           
static boolean suspendedTransactionsHeld()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

module

public static final java.lang.String module

debugResMap

public static java.util.Map<javax.transaction.xa.Xid,DebugXaResource> debugResMap

debugResources

public static boolean debugResources
Constructor Detail

TransactionUtil

public TransactionUtil()
Method Detail

begin

public static boolean begin()
                     throws GenericTransactionException
Begins a transaction in the current thread IF transactions are available; only tries if the current transaction status is ACTIVE, if not active it returns false. If and on only if it begins a transaction it will return true. In other words, if a transaction is already in place it will return false and do nothing.

Throws:
GenericTransactionException

begin

public static boolean begin(int timeout)
                     throws GenericTransactionException
Begins a transaction in the current thread IF transactions are available; only tries if the current transaction status is ACTIVE, if not active it returns false. If and on only if it begins a transaction it will return true. In other words, if a transaction is already in place it will return false and do nothing.

Throws:
GenericTransactionException

getStatus

public static int getStatus()
                     throws GenericTransactionException
Gets the status of the transaction in the current thread IF transactions are available, otherwise returns STATUS_NO_TRANSACTION

Throws:
GenericTransactionException

getStatusString

public static java.lang.String getStatusString()
                                        throws GenericTransactionException
Throws:
GenericTransactionException

isTransactionInPlace

public static boolean isTransactionInPlace()
                                    throws GenericTransactionException
Throws:
GenericTransactionException

commit

public static void commit(boolean beganTransaction)
                   throws GenericTransactionException
Commits the transaction in the current thread IF transactions are available AND if beganTransaction is true

Throws:
GenericTransactionException

commit

public static void commit()
                   throws GenericTransactionException
Commits the transaction in the current thread IF transactions are available

Throws:
GenericTransactionException

rollback

public static void rollback(boolean beganTransaction)
                     throws GenericTransactionException
Deprecated. 

Throws:
GenericTransactionException

rollback

public static void rollback(boolean beganTransaction,
                            java.lang.String causeMessage,
                            java.lang.Throwable causeThrowable)
                     throws GenericTransactionException
Rolls back transaction in the current thread IF transactions are available AND if beganTransaction is true; if beganTransaction is not true, setRollbackOnly is called to insure that the transaction will be rolled back

Throws:
GenericTransactionException

rollback

public static void rollback()
                     throws GenericTransactionException
Rolls back transaction in the current thread IF transactions are available

Throws:
GenericTransactionException

setRollbackOnly

public static void setRollbackOnly(java.lang.String causeMessage,
                                   java.lang.Throwable causeThrowable)
                            throws GenericTransactionException
Makes a rollback the only possible outcome of the transaction in the current thread IF transactions are available

Throws:
GenericTransactionException

suspend

public static Transaction suspend()
                           throws GenericTransactionException
Throws:
GenericTransactionException

resume

public static void resume(Transaction parentTx)
                   throws GenericTransactionException
Throws:
GenericTransactionException

setTransactionTimeout

public static void setTransactionTimeout(int seconds)
                                  throws GenericTransactionException
Sets the timeout of the transaction in the current thread IF transactions are available

Throws:
GenericTransactionException

enlistConnection

public static java.sql.Connection enlistConnection(javax.sql.XAConnection xacon)
                                            throws GenericTransactionException
Enlists the given XAConnection and if a transaction is active in the current thread, returns a plain JDBC Connection

Throws:
GenericTransactionException

enlistResource

public static void enlistResource(javax.transaction.xa.XAResource resource)
                           throws GenericTransactionException
Throws:
GenericTransactionException

getTransactionStateString

public static java.lang.String getTransactionStateString(int state)

logRunningTx

public static void logRunningTx()

registerSynchronization

public static void registerSynchronization(Synchronization sync)
                                    throws GenericTransactionException
Throws:
GenericTransactionException

cleanSuspendedTransactions

public static int cleanSuspendedTransactions()
                                      throws GenericTransactionException
BE VERY CARFUL WHERE YOU CALL THIS!!

Throws:
GenericTransactionException

suspendedTransactionsHeld

public static boolean suspendedTransactionsHeld()

pushSuspendedTransaction

protected static void pushSuspendedTransaction(Transaction t)

popSuspendedTransaction

protected static Transaction popSuspendedTransaction()

removeSuspendedTransaction

protected static void removeSuspendedTransaction(Transaction t)

getTransactionBeginStackSaveSize

public static int getTransactionBeginStackSaveSize()

getTransactionBeginStackSave

public static java.util.List<java.lang.Exception> getTransactionBeginStackSave()

getAllThreadsTransactionBeginStackSave

public static java.util.Map<java.lang.Long,java.util.List<java.lang.Exception>> getAllThreadsTransactionBeginStackSave()

printAllThreadsTransactionBeginStacks

public static void printAllThreadsTransactionBeginStacks()

getTransactionBeginStack

public static java.lang.Exception getTransactionBeginStack()

getSetRollbackOnlyCause

public static org.ofbiz.entity.transaction.TransactionUtil.RollbackOnlyCause getSetRollbackOnlyCause()

getTransactionStartStamp

public static java.sql.Timestamp getTransactionStartStamp()

getTransactionUniqueNowStamp

public static java.sql.Timestamp getTransactionUniqueNowStamp()

clearTransactionStamps

protected static void clearTransactionStamps()