Transaction Events
Transactional Events
BoxLang emits events during the lifecycle of a JDBC transaction which can be used to react to various transaction points in your app:
Note that all these events (with the exception of onTransactionAcquire
and onTransactionRelease
) have the potential to be acting upon a no-op transaction, with a null connection
parameter since no connection was ever obtained. ( Read more in Transaction Behavior for a description of how transactions work. )
With this in mind, you'll want to do null checks against the connection
parameter in case no connection has yet been acquired:
The two exceptions, as mentioned above, are onTransactionAcquire
and onTransactionRelease
, which only emit once a connection has been acquired, and is being released, respectively. Most of the time you'll want to listen for these events instead of their onTransactionBegin
/onTransactionEnd
counterparts.
onTransactionBegin
This event fires when the transaction block is first opened and before the body begins processing.
Note that in BoxLang transactions, no connection is acquired until the first JDBC query is executed. This means that the onTransactionBegin
will not have any connection to operate on. Most of the time, you will want to use onTransactionAcquire
in place of onTransactionBegin
.
transaction
Java class
Instance of the Transaction object
Example
onTransactionEnd
This event fires when the transaction block is closed after the body has finished processing.
Consider using onTransactionRelease
as an alternative to onTransactionEnd
if you only want to listen for transactions that have done work.
transaction
Java class
Instance of the Transaction object
connection
Java class
Instance of the java.sql.Connection object this transaction is operating upon. May be null
if no JDBC queries have executed inside this transaction.
Example
onTransactionAcquire
This event fires when the transaction first acquires a connection due to a JDBC query being executed within the body. You should prefer this over onTransactionBegin
.
transaction
Java class
Instance of the Transaction object
connection
Java class
Instance of the java.sql.Connection object this transaction is operating upon
Example
onTransactionRelease
This event fires when the transaction releases its connection. You should prefer this over onTransactionEnd
.
transaction
Java class
Instance of the Transaction object
connection
Java class
Instance of the java.sql.Connection object this transaction is operating upon
Example
onTransactionCommit
This event fires when a transaction commit action occurs. Can occur multiple times (or never) within a single transaction.
transaction
Java class
Instance of the Transaction object
connection
Java class
Instance of the java.sql.Connection object this transaction is operating upon
Example
onTransactionRollback
This event fires when a transaction rollback action occurs. Can occur multiple times (or never) within a single transaction.
transaction
Java class
Instance of the Transaction object
connection
Java class
Instance of the java.sql.Connection object this transaction is operating upon
savepoint
String
Savepoint name to roll back to. May be null
.
Example
onTransactionSetSavepoint
This event fires when a transaction savepoint is set.
transaction
Java class
Instance of the Transaction object
connection
Java class
Instance of the java.sql.Connection object this transaction is operating upon
savepoint
String
Savepoint name to set.
Example
Last updated
Was this helpful?