Package org.compiere.util
Class Trx
java.lang.Object
org.compiere.util.Trx
Transaction Management. - Create new Transaction by Trx.get(name); - ..transactions.. - commit(); ---- start(); ---- commit(); - close();
- Author:
- Jorg Janke, Low Heng Sin
- added rollback(boolean) and commit(boolean) [20070105]
- remove unnecessary use of savepoint
- use UUID for safer transaction name generation, Teo Sarca, http://www.arhipac.ro
- FR [ 2080217 ] Implement TrxRunnable
- BF [ 2876927 ] Oracle JDBC driver problem https://sourceforge.net/p/adempiere/bugs/2173/, Teo Sarca, teo.sarca@gmail.com
- BF [ 2849122 ] PO.AfterSave is not rollback on error - add releaseSavepoint method https://sourceforge.net/p/adempiere/bugs/2073/
-
Nested Class Summary
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addTrxEventListener
(TrxEventListener listener) Add transaction event listenerboolean
close()
End Transaction and Close Connectionboolean
commit()
Commitboolean
commit
(boolean throwException) Commitstatic String
Create unique Transaction Namestatic String
createTrxName
(String prefix) Create unique Transaction Nameprotected void
finalize()
static Trx
Get Transactionstatic Trx
get
(String trxName, boolean createNew, Connection con) Deprecated.static Trx[]
Deprecated.- wrong method name fixed with IDEMPIERE-5355 - please use getOpenTransactionsGet connectiongetConnection
(boolean createNew) Get ConnectionGet transaction display name.Get last set workflow save point.static Trx[]
Get register transactionsGet stack trace saveint
Get transaction timout valueGet Nameboolean
Is there additional changes make by transaction event listenerboolean
isActive()
Transaction is Activestatic String
Register a null trxvoid
releaseSavepoint
(Savepoint savepoint) Release Savepointboolean
removeTrxEventListener
(TrxEventListener listener) Remove transaction event listenerboolean
rollback()
Rollbackboolean
rollback
(boolean throwException) Rollbackboolean
Rollback to save pointboolean
Rollback and close transaction.
This is means to be called by the timeout monitor and developer usually shouldn't call this directly.static void
run
(String trxName, TrxRunnable r) Execute runnable object using provided transaction.
If execution fails, database operations will be rolled back.static void
run
(TrxRunnable r) void
setChangesMadeByEventListener
(boolean changesMade) Indicate additional DB changes have been made by a transaction event listenervoid
setDisplayName
(String displayName) Set transaction display namevoid
setLastWFSavepoint
(Savepoint savepoint) Set last workflow save point.
For workflow engine use, developer usually shouldn't call this method directly.setSavepoint
(String name) Set transaction save pointvoid
setTimeout
(int timeout) set transaction timeout value ( in seconds )boolean
start()
Start Trxstatic void
Start transaction timeout monitor (run every 5 minutes)toString()
String Representationstatic void
unregisterNullTrx
(String nullTrxName) Unregister a null trx
-
Field Details
-
trace
-
-
Method Details
-
get
Get Transaction- Parameters:
trxName
- trx namecreateNew
- if false, null is returned if not found- Returns:
- Transaction or null
-
get
Deprecated.Get Transaction in a Connection- Parameters:
trxName
- trx namecreateNew
- if false, null is returned if not foundcon
- Connection- Returns:
- Transaction or null
-
startTrxMonitor
public static void startTrxMonitor()Start transaction timeout monitor (run every 5 minutes) -
createTrxName
Create unique Transaction Name- Parameters:
prefix
- optional prefix- Returns:
- unique transaction name
-
createTrxName
Create unique Transaction Name- Returns:
- unique name
-
getConnection
Get connection- Returns:
- connection
-
getConnection
Get Connection- Parameters:
createNew
- if true, create new connection if the trx does not have one created yet- Returns:
- connection
-
getTrxName
Get Name- Returns:
- transaction name
-
start
public boolean start()Start Trx- Returns:
- true if trx started
-
getStartTime
- Returns:
- The start time of this transaction
-
isActive
public boolean isActive()Transaction is Active- Returns:
- true if transaction is active
-
rollback
Rollback- Parameters:
throwException
- if true, re-throws exception- Returns:
- true if success, false if failed or transaction already rollback
- Throws:
SQLException
-
rollback
public boolean rollback()Rollback- Returns:
- true if success, false if failed or transaction already rollback
-
rollback
Rollback to save point- Parameters:
savepoint
-- Returns:
- true if success, false if failed or transaction already rollback
- Throws:
SQLException
-
commit
Commit- Parameters:
throwException
- if true, re-throws exception- Returns:
- true if success
- Throws:
SQLException
-
commit
public boolean commit()Commit- Returns:
- true if success
-
rollbackAndCloseOnTimeout
public boolean rollbackAndCloseOnTimeout()Rollback and close transaction.
This is means to be called by the timeout monitor and developer usually shouldn't call this directly.- Returns:
- true if success
-
close
public boolean close()End Transaction and Close Connection- Returns:
- true if success
-
setSavepoint
Set transaction save point- Parameters:
name
- optional savepoint name- Returns:
- Savepoint
- Throws:
SQLException
-
setLastWFSavepoint
Set last workflow save point.
For workflow engine use, developer usually shouldn't call this method directly.- Parameters:
savepoint
-
-
getLastWFSavepoint
Get last set workflow save point. For workflow engine use, developer usually shouldn't call this method directly.- Returns:
- last set workflow save point or null
-
releaseSavepoint
Release Savepoint- Parameters:
savepoint
-- Throws:
SQLException
-
toString
String Representation -
getOpenTransactions
Get register transactions- Returns:
- array of register transactions
-
getActiveTransactions
Deprecated.- wrong method name fixed with IDEMPIERE-5355 - please use getOpenTransactions- Returns:
- Trx[]
-
run
- See Also:
-
run
Execute runnable object using provided transaction.
If execution fails, database operations will be rolled back.Example:
Trx.run(null, new
TrxRunnable
() { public void run(String trxName) { // do something using trxName } )};- Parameters:
trxName
- transaction name (if null, a new transaction will be created)r
- runnable object- Throws:
RuntimeException
- orAdempiereException
-
getTimeout
public int getTimeout()Get transaction timout value- Returns:
- trx timoue value in second
-
setTimeout
public void setTimeout(int timeout) set transaction timeout value ( in seconds )- Parameters:
timeout
-
-
addTrxEventListener
Add transaction event listener- Parameters:
listener
-
-
removeTrxEventListener
Remove transaction event listener- Parameters:
listener
-- Returns:
- true if listener is found and remove
-
getStrackTrace
Get stack trace save- Returns:
- stack trace save or empty string
-
getDisplayName
Get transaction display name. Fall back to transaction name if display name is not set.- Returns:
- display name or name
-
setDisplayName
Set transaction display name- Parameters:
displayName
-
-
setChangesMadeByEventListener
public void setChangesMadeByEventListener(boolean changesMade) Indicate additional DB changes have been made by a transaction event listener- Parameters:
changesMade
-
-
hasChangesMadeByEventListener
public boolean hasChangesMadeByEventListener()Is there additional changes make by transaction event listener- Returns:
- true if event listener(s) has flag that additional db changes have been made
-
finalize
-
registerNullTrx
Register a null trx- Returns:
-
unregisterNullTrx
Unregister a null trx- Parameters:
nullTrxName
-
-