XA transactions
XA is a two-phase commit protocol that is natively supported by many databases and transaction monitors. XA transactions allow multiple resources (such as other databases or JMS systems) to coordinate in a single global transaction. This ensures data credibility as updates are committed or rolled-back across all resources.
Some drivers don't natively support XA
For the drivers that don't support XA natively, Martini emulates XA via implementing last resource commit optimization; but such a strategy has limitations – it is not possible to have more than one emulation of an XA datasource in a single XA transaction.
Managing XA transactions
Before handling XA transactions, ensure that your database connection has the "Use XA" property enabled.
Starting XA transactions
To mark the start of the transaction,
call SqlMethods.startTransaction(boolean, int)
.
GloopExecutionContext parameters
Although the method requires a GloopExecutionContext
parameter, it's not shown in the UI as it's
automatically mapped and generally used internally.
Parameter | Default | Description |
---|---|---|
autoCommit |
false |
Whether to automtically commit after the service has finished or not, even if an exception was thrown. |
timeout |
60 |
Amount of time to wait before timing out the transaction (in seconds). |
First you must create a TransactionFacade
object first and then invoke its start()
method.
To create said object, you may use the Transactions
class's
create
* methods.
1 2 |
|
Committing XA transactions
To manually commit a transaction, call
SqlMethods.commitTransaction()
. This will commit the current
transaction.
As for committing an XA Transaction in Groovy, simply call on the TransactionFacade
object's commit()
method.
1 |
|
Rolling back XA transactions
As for rolling back, simply call
SqlMethods.rollbackTransaction()
.
This will rollback the current transaction.
To rollback an XA transaction in Groovy, simply call the rollback()
method of the TransactionFacade
object.
1 |
|
Database transactions in Gloop
The examples package includes Gloop Services that perform transactions in the
code/databaseTransaction
directory.