Class TransactionUtil

java.lang.Object
org.apache.ofbiz.entity.transaction.TransactionUtil
All Implemented Interfaces:
javax.transaction.Status

public final class TransactionUtil extends Object implements javax.transaction.Status

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.

  • Field Details

  • Method Details

    • doNewTransaction

      public static <V> V doNewTransaction(Callable<V> callable, String ifErrorMessage, int timeout, boolean printException) throws GenericEntityException
      Throws:
      GenericEntityException
    • doTransaction

      public static <V> V doTransaction(Callable<V> callable, String ifErrorMessage, int timeout, boolean printException) throws GenericEntityException
      Throws:
      GenericEntityException
    • noTransaction

      public static <V> TransactionUtil.NoTransaction<V> noTransaction(Callable<V> callable)
    • inTransaction

      public static <V> TransactionUtil.InTransaction<V> inTransaction(Callable<V> callable, String ifErrorMessage, int timeout, boolean printException)
    • 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
    • internalBegin

      protected static void internalBegin(javax.transaction.UserTransaction ut, int timeout) throws javax.transaction.SystemException, javax.transaction.NotSupportedException
      Throws:
      javax.transaction.SystemException
      javax.transaction.NotSupportedException
    • 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 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, String causeMessage, 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
    • rollback

      public static void rollback(Throwable causeThrowable) throws GenericTransactionException
      Rolls back transaction in the current thread IF transactions are available
      Throws:
      GenericTransactionException
    • setRollbackOnly

      public static void setRollbackOnly(String causeMessage, 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 javax.transaction.Transaction suspend() throws GenericTransactionException
      Throws:
      GenericTransactionException
    • resume

      public static void resume(javax.transaction.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 Connection enlistConnection(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(XAResource resource) throws GenericTransactionException
      Throws:
      GenericTransactionException
    • getTransactionStateString

      public static String getTransactionStateString(int state)
    • debugResources

      public static boolean debugResources()
    • logRunningTx

      public static void logRunningTx()
    • registerSynchronization

      public static void registerSynchronization(javax.transaction.Synchronization sync) throws GenericTransactionException
      Throws:
      GenericTransactionException
    • cleanSuspendedTransactions

      public static int cleanSuspendedTransactions() throws GenericTransactionException
      BE VERY CAREFUL WHERE YOU CALL THIS!!
      Throws:
      GenericTransactionException
    • suspendedTransactionsHeld

      public static boolean suspendedTransactionsHeld()
    • getSuspendedTxStack

      public static List<javax.transaction.Transaction> getSuspendedTxStack()
    • getSuspendedTxLocationsStack

      public static List<Exception> getSuspendedTxLocationsStack()
    • pushSuspendedTransaction

      protected static void pushSuspendedTransaction(javax.transaction.Transaction t)
    • popSuspendedTransaction

      protected static javax.transaction.Transaction popSuspendedTransaction()
    • removeSuspendedTransaction

      protected static void removeSuspendedTransaction(javax.transaction.Transaction t)
    • getTransactionBeginStackSaveSize

      public static int getTransactionBeginStackSaveSize()
    • getTransactionBeginStackSave

      public static List<Exception> getTransactionBeginStackSave()
    • getAllThreadsTransactionBeginStackSave

      public static Map<Long,List<Exception>> getAllThreadsTransactionBeginStackSave()
    • printAllThreadsTransactionBeginStacks

      public static void printAllThreadsTransactionBeginStacks()
    • getTransactionBeginStack

      public static Exception getTransactionBeginStack()
    • getSetRollbackOnlyCause

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

      public static Timestamp getTransactionStartStamp()
    • getTransactionUniqueNowStamp

      public static Timestamp getTransactionUniqueNowStamp()
    • clearTransactionStamps

      protected static void clearTransactionStamps()
    • getCursorConnection

      public static Connection getCursorConnection(GenericHelperInfo helperInfo, Connection con)