examples
package: Executing database XA transactions
According to Oracle:
"XA is a two-phase commit protocol that is natively supported by many databases and transaction monitors. It ensures data integrity by coordinating single transactions accessing multiple relational databases. XA guarantees that transactional updates are committed in all of the participating databases, or are fully rolled back out of all of the databases, reverting to the state prior to the start of the transaction."1
XA transactions are supported by Martini and the
databaseTransaction.DatabaseMigration.gloop
service in the examples
package demonstrates how
XA transactions can be used in Gloop. In this example, there are two data sources and the goal of the
service is to migrate the data from the first data source to the second.
Requirement for XA transactions
When performing XA transactions, ensure that participating database connections have
their xa
properties set to true
.
Related articles
Please see the following articles for more information:
Try it!
In the Navigator, expand the examples
package and navigate to the
code
folder, then expand the databaseTransaction
package. This package contains the
files and/or directories as shown below:
1 2 3 4 5 6 7 8 9 10 |
|
Inspect and run the DatabaseMigration.gloop
service to see XA database transactions in
action. This service has its steps decorated with comments2 to help
explain the goal or purpose of each of its components.
Output of DatabaseMigration.gloop
1 2 3 4 5 6 7 8 9 10 11 |
|
Explanation
Simply put, all this service does is migrate data from dataSource1
to dataSource2
and delete the copied row(s) from
dataSource1
if successful. However all of the database operations that the service executes across the multiple
databases will be committed in a single call, even though there are multiple transactions at play (since more than
one database is involved).
-
Oracle Corporation. (n.d.). XA Transactions. Retrieved October 23, 2018, from https://docs.oracle.com/cd/E19509-01/820-5892/ref_xatrans/index.html ↩
-
Open the service file to see comments. Make sure comments are also not hidden. ↩