Skip to content

Home

Introduction

Development

IDEs

Services

Service manager

API Explorer

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 TORO Integrate and the databaseTransaction.DatabaseMigration.gloop service of 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 onto the second.

Requirement for XA transactions

When performing XA transactions, ensure that participating database connection pools have their xa properties set to true.

Related articles

Please see the following articles for more information:

Try it!

Under the Coder Navigator, expand the examples package entry and navigate to the code folder. Afterwards, look for the databaseTransaction package. This package contains the files and/or directories 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 comments 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
25/04/19 14:53:54.379 INFO  [Integrate] Starting data migration...
25/04/19 14:53:54.732 INFO  [Integrate] Successfully inserted a data to example_xa_db_migrated
25/04/19 14:53:55.040 INFO  [Integrate] Successfully deleted a data from example_db
25/04/19 14:53:55.043 INFO  [Integrate] Successfully inserted a data to example_xa_db_migrated
25/04/19 14:53:55.053 INFO  [Integrate] Successfully deleted a data from example_db
25/04/19 14:53:55.055 INFO  [Integrate] Successfully inserted a data to example_xa_db_migrated
25/04/19 14:53:55.057 INFO  [Integrate] Successfully deleted a data from example_db
25/04/19 14:53:55.060 INFO  [Integrate] Successfully inserted a data to example_xa_db_migrated
25/04/19 14:53:55.062 INFO  [Integrate] Successfully deleted a data from example_db
25/04/19 14:53:55.389 INFO  [Integrate] Successfully migrated data from example_db to example_xa_db_migrated
25/04/19 14:53:55.782 INFO  [Integrate] 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.


  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