Class TransactionUtil

  • All Implemented Interfaces:
    Status

    public final class TransactionUtil
    extends java.lang.Object
    implements 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 Detail

      • module

        public static final java.lang.String module
    • Method Detail

      • doNewTransaction

        public static <V> V doNewTransaction​(java.util.concurrent.Callable<V> callable,
                                             java.lang.String ifErrorMessage,
                                             int timeout,
                                             boolean printException)
                                      throws GenericEntityException
        Throws:
        GenericEntityException
      • doTransaction

        public static <V> V doTransaction​(java.util.concurrent.Callable<V> callable,
                                          java.lang.String ifErrorMessage,
                                          int timeout,
                                          boolean printException)
                                   throws GenericEntityException
        Throws:
        GenericEntityException
      • inTransaction

        public static <V> TransactionUtil.InTransaction<V> inTransaction​(java.util.concurrent.Callable<V> callable,
                                                                         java.lang.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
      • 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
      • 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
      • 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
      • getTransactionStateString

        public static java.lang.String getTransactionStateString​(int state)
      • debugResources

        public static boolean debugResources()
      • logRunningTx

        public static void logRunningTx()
      • suspendedTransactionsHeld

        public static boolean suspendedTransactionsHeld()
      • getSuspendedTxStack

        public static java.util.List<Transaction> getSuspendedTxStack()
      • getSuspendedTxLocationsStack

        public static java.util.List<java.lang.Exception> getSuspendedTxLocationsStack()
      • 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.apache.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()
      • getCursorConnection

        public static java.sql.Connection getCursorConnection​(GenericHelperInfo helperInfo,
                                                              java.sql.Connection con)