1. Transaction is divided into two types, Local Transaction and Global Transaction.
involves a connection commit, called the local Transaction.
involves multiple connection commits, called Global Transaction.
The landlord mentioned is, Global transaction.
2. The Global Transaction requires support for the XA interface (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;
javax.sql.xaconnection;
javax.transaction.xa.xid;
javax.transaction.xa.xaresource;
The implementation of these XA interfaces requires the JDBC supply of the database.
The database itself is to support XA. The JDBC of the database also provides an implementation of XA.
Large databases such as Oracle, Sybase, DB2, SQL Server support XA and support global Transaction.
My SQL even local transaction support is not good, let alone global transation.
3. XA requires two phase commit--prepare and commit.
Suppose there are two connection, Con1, Con2, the general process is as follows,
con1 = Xaresouce1.getconnection...con2 = do Some thing.con2 some thing.after they Finish.pre1 = Xaresouce1.prepare ();p Re2 = Xaresouce2.prepare (); if (both Pre1 and Pre2 are OK) {XAResouce1 and 2 commit} else {XAResouce1 and 2 rollback}
Someone said before, in XAResouce1 and 2 commit,
Perhaps XAResouce1 commit () succeeded, XAResouce2 commit () failed.
At this point, a "heuristic exception" is thrown. The program can handle this exception. For example, Xaresouce.recover () or something like that.
But in general, there is no other way, it is necessary for the data administrator to undo all operations according to the data operation log, or to restore the data backup.
Some databases generate an "Anti-action" 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 transaction implementation code for EJB server such as JBoss
Note: The XA:XA protocol was first proposed by Tuxedo and presented to the X/open organization as the interface standard for the Resource Manager (database) and transaction manager. Currently, major database manufacturers such as Oracle, Informix, DB2, and Sybase provide support for XA. The XA protocol uses a two-phase commit method to manage distributed transactions. The XA interface provides a standard interface for communication between the resource manager and the transaction manager. The XA protocol consists of two sets of functions, beginning with Xa_ and beginning with Ax_.
The following functions enable the transaction manager to perform operations on the resource manager:
1) Xa_open,xa_close: Establish and close the connection to the resource manager.
2) Xa_start,xa_end: Start and end a local transaction.
3) Xa_prepare,xa_commit,xa_rollback: Pre-commit, commit, and rollback a local transaction.
4) Xa_recover: Rolls back a transaction that has been pre-committed.
5) Ax_ begins with a function that allows the resource manager to dynamically register in the transaction manager and can operate on XID (TRANSACTION IDS).
6) Ax_reg,ax_unreg; Allows an explorer to dynamically register or unregister in a single TMS (TRANSACTION MANAGER SERVER).
Introduction to JPA and distributed transactions