1. Transaction can be divided into local transaction and global transaction.
A connection commit is called a local transaction.
The commit involving multiple connections is called global transaction.
The author mentioned that global transaction.
2. Global transaction requires support for XA interfaces (including in 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;
The
Javax. SQL. xaconnection;
Javax. transaction. Xa. Xid;
Javax. transaction. Xa. xaresource;
The implementation of these XA interfaces requires the JDBC provision of the database.
The database itself must support Xa. Database JDBC must also provide XA implementation.
Oracle, Sybase, DB2, SQL Server, and other large databases support Xa and global transaction.
My SQL does not support local transaction, let alone Global transation.
3. Xa requires two-phase commit: prepare and commit.
Assume there are two connections, 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 commit
} Else {
Xaresouce1 and 2 rollback
}
As mentioned above, when xaresouce1 and 2 commit,
Maybe xaresouce1 commit () is successful, and xaresouce2 commit () fails.
At this time, a "heuristic exception" will be thrown ". The program can handle this exception. For example, xaresouce. Recover.
However, in general, there is no other way. The data administrator needs to perform all the Undo operations based on the data operation log, or recover the data backup.
Some databases generate a "reverse operation" log when performing data operations. For example, insert to delete.
4.The implementation of transactionmanager can handle multiple xaresouce (one xaresouce list) situations.
For example, tyrex. Or the transaction implementation code of EJB server such as JBoss.