JTA and two phase commits, handling global transactions

Source: Internet
Author: User
Tags prepare
1. Transaction is divided into two types, local Transaction and Global Transaction.
Involves a connection commit, called the local Transaction.
A commit that involves multiple connection, called the global Transaction.
The landlord mentioned is that Global Transaction.

2. Global Transaction requires the support of the XA interface, including inside the JTA.

Import javax.sql.XAConnection;
Import Javax.transaction.xa.Xid;
Import Javax.transaction.xa.XAResource;
Import javax.transaction.xa.XAException;
Import javax.transaction.Transaction;
Import Javax.transaction.TransactionManager;

of which
Javax.sql.XAConnection;
Javax.transaction.xa.Xid;
Javax.transaction.xa.XAResource;

Implementations of these XA interfaces require JDBC provision of the database.
The database itself will support XA. Database JDBC also provides the implementation of XA.

Large databases such as Oracle, Sybase, DB2, SQL Server support XA and support global Transaction.
My SQL does not support the local transaction, let alone the global transation.

3. XA requires two stages of submission-prepare and commit.
Suppose there are two connection, Con1, Con2, the general process is as follows,

Con1 = Xaresouce1.getconnection ...
Con2 = Xaresouce2.getconnection ...

Con1 do some thing.
Con2 do some thing.
After they finish.

Pre1 = Xaresouce1.prepare ();
Pre2 = Xaresouce2.prepare ();

if (both Pre1 and Pre2 are OK) {
XAResouce1 and 2 commits
}else {
XAResouce1 and 2 rollback
}

It was said earlier that, in the XAResouce1 and 2 commit,
Possibly XAResouce1 commit () succeeded, XAResouce2 commit () failed.
At this point, a "heuristic exception" is thrown. The program can handle this exception. For example, Xaresouce.recover ().
But in general, there is no other way, the data administrator needs to undo all operations based on the data operation log, or restore the data backup.
Some databases generate a "reverse operation" log when they perform data operations. For example, insert to delete, and so on.

4. The implementation of TransactionManager can handle multiple xaresouce (a xaresouce list).
Like Tyrex. or the transaction implementation code of an EJB server such as JBoss.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.