Class TransactionUtil
- java.lang.Object
-
- org.apache.ofbiz.entity.transaction.TransactionUtil
-
- All Implemented Interfaces:
javax.transaction.Status
public final class TransactionUtil extends java.lang.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TransactionUtil.InTransaction<V>
static class
TransactionUtil.NoTransaction<V>
static class
TransactionUtil.StampClearSync
-
Field Summary
Fields Modifier and Type Field Description static java.util.Map<javax.transaction.xa.Xid,DebugXaResource>
debugResMap
static java.lang.String
module
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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 CAREFUL WHERE YOU CALL THIS!!protected static void
clearTransactionStamps()
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
debugResources()
static <V> V
doNewTransaction(java.util.concurrent.Callable<V> callable, java.lang.String ifErrorMessage, int timeout, boolean printException)
static <V> V
doTransaction(java.util.concurrent.Callable<V> callable, java.lang.String ifErrorMessage, int timeout, boolean printException)
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 Connectionstatic void
enlistResource(javax.transaction.xa.XAResource resource)
static java.util.Map<java.lang.Long,java.util.List<java.lang.Exception>>
getAllThreadsTransactionBeginStackSave()
static java.sql.Connection
getCursorConnection(GenericHelperInfo helperInfo, java.sql.Connection con)
static org.apache.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_TRANSACTIONstatic java.lang.String
getStatusString()
static java.util.List<java.lang.Exception>
getSuspendedTxLocationsStack()
static java.util.List<javax.transaction.Transaction>
getSuspendedTxStack()
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()
protected static void
internalBegin(javax.transaction.UserTransaction ut, int timeout)
static <V> TransactionUtil.InTransaction<V>
inTransaction(java.util.concurrent.Callable<V> callable, java.lang.String ifErrorMessage, int timeout, boolean printException)
static boolean
isTransactionInPlace()
static void
logRunningTx()
static <V> TransactionUtil.NoTransaction<V>
noTransaction(java.util.concurrent.Callable<V> callable)
protected static javax.transaction.Transaction
popSuspendedTransaction()
static void
printAllThreadsTransactionBeginStacks()
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
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 backstatic void
rollback(java.lang.Throwable causeThrowable)
Rolls back transaction in the current thread IF transactions are availablestatic 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 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
suspendedTransactionsHeld()
-
-
-
Field Detail
-
module
public static final java.lang.String module
-
debugResMap
public static final java.util.Map<javax.transaction.xa.Xid,DebugXaResource> debugResMap
-
-
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
-
noTransaction
public static <V> TransactionUtil.NoTransaction<V> noTransaction(java.util.concurrent.Callable<V> callable)
-
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
-
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 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, 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
-
rollback
public static void rollback(java.lang.Throwable causeThrowable) 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 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 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)
-
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 java.util.List<javax.transaction.Transaction> getSuspendedTxStack()
-
getSuspendedTxLocationsStack
public static java.util.List<java.lang.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 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)
-
-