Class TransactionUtil
java.lang.Object
org.apache.ofbiz.entity.transaction.TransactionUtil
- All Implemented Interfaces:
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
static final class
static class
-
Field Summary
Fields inherited from interface javax.transaction.Status
STATUS_ACTIVE, STATUS_COMMITTED, STATUS_COMMITTING, STATUS_MARKED_ROLLBACK, STATUS_NO_TRANSACTION, STATUS_PREPARED, STATUS_PREPARING, STATUS_ROLLEDBACK, STATUS_ROLLING_BACK, STATUS_UNKNOWN
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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
BE VERY CAREFUL WHERE YOU CALL THIS!!protected static void
static void
commit()
Commits the transaction in the current thread IF transactions are availablestatic void
commit
(boolean beganTransaction) Commits the transaction in the current thread IF transactions are available AND if beganTransaction is truestatic boolean
static <V> V
doNewTransaction
(Callable<V> callable, String ifErrorMessage, int timeout, boolean printException) static <V> V
doTransaction
(Callable<V> callable, String ifErrorMessage, int timeout, boolean printException) static Connection
enlistConnection
(XAConnection xacon) Enlists the given XAConnection and if a transaction is active in the current thread, returns a plain JDBC Connectionstatic void
enlistResource
(XAResource resource) static Connection
getCursorConnection
(GenericHelperInfo helperInfo, Connection con) static org.apache.ofbiz.entity.transaction.TransactionUtil.RollbackOnlyCause
static int
Gets the status of the transaction in the current thread IF transactions are available, otherwise returns STATUS_NO_TRANSACTIONstatic String
static List<javax.transaction.Transaction>
static Exception
static int
static Timestamp
static String
getTransactionStateString
(int state) static Timestamp
protected static void
internalBegin
(javax.transaction.UserTransaction ut, int timeout) static <V> TransactionUtil.InTransaction<V>
inTransaction
(Callable<V> callable, String ifErrorMessage, int timeout, boolean printException) static boolean
static void
static <V> TransactionUtil.NoTransaction<V>
noTransaction
(Callable<V> callable) protected static javax.transaction.Transaction
static void
protected static void
pushSuspendedTransaction
(javax.transaction.Transaction t) static void
registerSynchronization
(javax.transaction.Synchronization sync) protected static void
removeSuspendedTransaction
(javax.transaction.Transaction t) static void
resume
(javax.transaction.Transaction parentTx) static void
rollback()
Rolls back transaction in the current thread IF transactions are availablestatic void
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 backstatic void
Rolls back transaction in the current thread IF transactions are availablestatic void
setRollbackOnly
(String causeMessage, Throwable causeThrowable) Makes a rollback the only possible outcome of the transaction in the current thread IF transactions are availablestatic void
setTransactionTimeout
(int seconds) Sets the timeout of the transaction in the current thread IF transactions are availablestatic javax.transaction.Transaction
suspend()
static boolean
-
Field Details
-
DEBUG_RES_MAP
-
-
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
-
inTransaction
public static <V> TransactionUtil.InTransaction<V> inTransaction(Callable<V> callable, String ifErrorMessage, int timeout, boolean printException) -
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. 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
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
Gets the status of the transaction in the current thread IF transactions are available, otherwise returns STATUS_NO_TRANSACTION- Throws:
GenericTransactionException
-
getStatusString
- Throws:
GenericTransactionException
-
isTransactionInPlace
- Throws:
GenericTransactionException
-
commit
Commits the transaction in the current thread IF transactions are available AND if beganTransaction is true- Throws:
GenericTransactionException
-
commit
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
Rolls back transaction in the current thread IF transactions are available- Throws:
GenericTransactionException
-
rollback
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
- Throws:
GenericTransactionException
-
resume
public static void resume(javax.transaction.Transaction parentTx) throws GenericTransactionException - Throws:
GenericTransactionException
-
setTransactionTimeout
Sets the timeout of the transaction in the current thread IF transactions are available- Throws:
GenericTransactionException
-
enlistConnection
Enlists the given XAConnection and if a transaction is active in the current thread, returns a plain JDBC Connection- Throws:
GenericTransactionException
-
enlistResource
- Throws:
GenericTransactionException
-
getTransactionStateString
-
debugResources
public static boolean debugResources() -
logRunningTx
public static void logRunningTx() -
registerSynchronization
public static void registerSynchronization(javax.transaction.Synchronization sync) throws GenericTransactionException - Throws:
GenericTransactionException
-
cleanSuspendedTransactions
BE VERY CAREFUL WHERE YOU CALL THIS!!- Throws:
GenericTransactionException
-
suspendedTransactionsHeld
public static boolean suspendedTransactionsHeld() -
getSuspendedTxStack
-
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
-
getAllThreadsTransactionBeginStackSave
-
printAllThreadsTransactionBeginStacks
public static void printAllThreadsTransactionBeginStacks() -
getTransactionBeginStack
-
getSetRollbackOnlyCause
public static org.apache.ofbiz.entity.transaction.TransactionUtil.RollbackOnlyCause getSetRollbackOnlyCause() -
getTransactionStartStamp
-
getTransactionUniqueNowStamp
-
clearTransactionStamps
protected static void clearTransactionStamps() -
getCursorConnection
-