In the JDBC2.0 Optional Package, distributed transactions in cooperation with the transaction manager (TM) based on the XA standard of X/Open are defined as an extension of the connection pooling function. The following provides an overview of distributed transactions:
- Connection pooling has almost no effect on existing applications. However, there are certain restrictions, such as that direct commit is not allowed. Also, as with connection pooling, it is a precondition that database connection is not performed by using DriverManager, but rather by using DataSource and JNDI introduced by the JDBC2.0 Optional Package.
- As with connection pooling, the transaction linkage function for linking with a TM is outside the functional scope of the JDBC specifications.
- Normally, a transaction linkage function is installed as an extension of a connection pooling function, and uses TM-provided JTA and JTS as the interface with the TM. Note that operations complying with JTA standard 1.0 are not guaranteed.
- In the transaction linkage facility, as with connection pooling, the DataSource class can be used as the interface with applications. This DataSource class is different from the one provided by the JDBC driver.
- The JDBC driver can use the XADataSource class and XAConnection class as an interface with the transaction linkage facility. Also, the JDBC driver can use XAResource class as an interface with TM.
- As with the DataSource class provided by the JDBC driver, the XADataSource class provided by the JDBC driver can use the connection information setting/acquisition methods.
As with connection pooling, Connection objects used by applications are generated by the XAConnection class. However, there are certain differences compared with the Connection objects generated by the DataSource class provided by the PooledConnection class or JDBC driver.
- The method of invoking a commit method or rollback method for the Connection class is based on an SQLException. That is, an application cannot directly complete a transaction.
- The default mode for AutoCommit is OFF.
- Issuance of a Connection class's setAutoCommit (true) method that turns on the AutoCommit mode results in an SQLException.
The following table lists and describes the classes related to distributed transactions.
Table 17-12 Classes related to distributed transactions
Class |
Overview |
javax.sql.DataSource |
- Provided by a transaction linkage function.
- Used as the interface to applications during database connection.
- Normally, linkage to a TM and connection pools are controlled in this class.
- Normally, registered in JNDI for use.
- Different from the DataSource class provided by the JDBC driver.
|
javax.sql.XADataSource |
- Provided by the JDBC driver.
- Can use a method for setting/acquiring connection information necessary for database connection.
- Normally not used directly from an application, and is used by a transaction linkage function.
- Normally, registered in JNDI for use.
- A transaction linkage function acquires an XAConnection object from this class of objects.
|
javax.sql.XAConnection |
- Provided by the JDBC driver.
- This is a subclass of the PooledConnection class. That is, it inherits all methods related to connection pooling.
- Normally not used directly from an application, and is used by a transaction linkage function.
- A transaction linkage function targets this class of objects for pooling.
- A transaction linkage function acquires a Connection object to be used by an application from this class of objects.
|
javax.sql.ConnectionEventListener |
- Provided by a transaction linkage function.
- A transaction linkage function senses a connection pooling trigger by detecting a disconnection or SQL error through this class of objects.
|
javax.transaction.xa.XAResource |
- Provided by the JDBC driver.
- Can use the XA-related methods used by a TM.
|
javax.transaction.xa.Xid |
- Provided by the JDBC driver and TM.
- Used as the argument/return value of an XAResource class method.
|
Because the interface definition of the classes listed in Table 17-12 is not included in JDK as a standard feature, you must acquire them from the JavaSoft website when you develop a transaction linkage facility.
The following are the package names and class names of the classes provided by the JDBC driver and shown in Table 17-12.
- Package name: JP.co.Hitachi.soft.HiRDB.JDBC
- XADataSource class name: JdbhXADataSource
- XAConnection class name: JdbhXAConnection
- XAResource class name: JdbhXAResource
- Xid class name: JdbhXid
Note that the setting of the connection information of the XADataSource class provided by the JDBC driver is the same as the setting of the connection information of the DataSource class provided by the JDBC driver.
All Rights Reserved. Copyright (C) 2011, Hitachi, Ltd.