Skip to content

Home

Development

IDEs

API Explorer

Releases

Release notes

Martini Runtime

Martini Desktop

Martini Online

Feature requests

Bug reports

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
examples
├── ...
└── code
    └── databaseTransaction
        ├── util
           ├── DatabaseXAHelper.gloop
           ├── DisableDatabaseXA.gloop
           ├── EnableDatabaseXA.gloop
           └── PopulateDatasource.gloop
        └── DatabaseMigration.gloop

Inspect and run the DatabaseMigration.gloop service to see XA database transactions in action. This Gloop 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
INFO  [Martini] Starting data migration...
INFO  [Martini] Successfully inserted a data to example_xa_db_migrated
INFO  [Martini] Successfully deleted a data from example_db
INFO  [Martini] Successfully inserted a data to example_xa_db_migrated
INFO  [Martini] Successfully deleted a data from example_db
INFO  [Martini] Successfully inserted a data to example_xa_db_migrated
INFO  [Martini] Successfully deleted a data from example_db
INFO  [Martini] Successfully inserted a data to example_xa_db_migrated
INFO  [Martini] Successfully deleted a data from example_db
INFO  [Martini] Successfully migrated data from example_db to example_xa_db_migrated
INFO  [Martini] Disabling xa for data sources [example_db, example_xa_db_migrated]

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).


  1. Oracle Corporation. (n.d.). XA Transactions. Retrieved October 23, 2018, from https://docs.oracle.com/cd/E19509-01/820-5892/ref_xatrans/index.html 

  2. Open the Gloop service file to see comments. Make sure comments are also not hidden.