12.1.2.OpenLink Resource Manager XA Interface Implementation
The OpenLink DataAccess drivers (ODBC, JDBC, ADO.Net) form part of the Resource Manager in the overal DTP model, implementing the XA (eXtended Architecture) interface for the comminication between itself as the upper layer of Resource Manager proess and the Transaction Manager (DTC, Tuxedo, JTS), and also providing the binding to the Database Vendors XA API implementation, which forms the lower layer of the Resoure Manager:
Figure12.2.UDA-XA.gif
Distributed transactions are supported in the OpenLink Multi-Tier and Single-Tier ODBC, JDBC and ADO.Net drivers/providers for Oracle, SQLServer, Sybase, Informix and Ingres II.
ODBC
The OpenLink Multi-Tier and Single-Tier ODBC drivers support distributed transactions using the Microsoft Distributed Transaction Co-ordinator (on Windows only) or Tuxedo as the Transaction Manager of the distributed transaction process.
Distributed Transaction Co-ordinator (DTC)
An OpenLink XA compliant ODBC driver acts as a proxy for an XA capable database (RM) and as such can be thought of as a resource manager. The OpenLink XA compliant ODBC drivers implement and export the function GetXASwitch() which provide the entry points for the DBMS specific XA functions which the DTC can use to communicate directly with the DBMS should an for of distributed transaction recovery need to the performed.
Transaction Enlistment
After initiating a transaction, an application enlists the resource managers it wants to participate in the transaction. Enlistment is done through the ODBC 3.0 connection attribute function call:
SQLSetConnectAttr(SQL_ATTR_ENLIST_IN_DTC)
Tuxedo
An OpenLink XA compliant ODBC driver acts as a proxy for an XA capable database (RM) and as such can be thought of as a resource manager. The driver exports a function opl_xa_switch:
xa_switch_t * opl_xa_switch (void)
which TP monitors can use to retrieve the xa_switch_t structure containing pointers to the XA functions.
Defining the OpenLink Resource Manager in Tuxedo
When integrating a new resource manager into Tuxedo, the file %TUXDIR%/udataobj/RM must be updated to include information about the resource manager. To integrate the OpenLink Lite Driver for Oracle into Tuxedo on Windows, define anrm_alias entry in the RM file by adding a line similar to:
OPL_ORA_XA;(*opl_xa_switch());"c:\program files\openlink\lite32\ntl5o9zz.lib
where, in this example, OPL_ORA_XA is therm_alias.. ntl5o9zz.lib is an import library for the ODBC driver associated with the DSN identified by the xa_info string; in this example the OpenLink Windows Lite Driver for Oracle (ntl5o9zz.dll).
To create anrm_aliasentry in the RM file for the OpenLink Generic Client add a line similar to:
OPL_XA;(*opl_xa_switch());"c:\program files\openlink\olod5032u.lib
On Unix therm_aliasis created in a similar way. A line adding an alias for the OpenLink Generic Client is added to $TUXDIR/udataobj/RM as follows:
OPL_XA:(*opl_xa_switch()):/home/openlink/lib/oplodbcu.so
Where /home/openlink is the openlink installation directory.
xa_info, OPENINFO and CLOSEINFO String Formats
The XA functions xa_open and xa_close open or close a connection to a resource manager for the calling thread. Both functions accept anxa_infoargument.xa_infois a string containing instance-specific information for the resource manager. For OpenLink ODBC drivers, the xa_infostring takes the form of an ODBC Data Source Name. The DSN must be defined in your ODBC.INI file or registry hive using the ODBC Administrator.
In a Tuxedo environment, the xa_info strings required by xa_open and xa_close for a particular RM instance are identified by the OPENINFO and CLOSEINFO entries in the UBBCONFIG configuration file. (An example UBBCONFIG file is given below.) OPENINFO and CLOSEINFO entries must be defined for each server group. These entries must be quoted strings of the form "rm_alias:DSN". (OPENINFO and CLOSEINFO should not contain the usualxa_infostring required by the target database. This string is stored as part of the DSN definition when the ODBC data source is configured. The OpenLink ODBC driver retrieves the storedxa_infostring using the DSN it receives through xa_open or xa_close.)
Using ODBC in an XA Global Transaction
In order for a service to use ODBC functions in the context of a global transaction, the ODBC functions must use the XA connection created when the service connects to the resource manager with which it is linked. (In the sample application, each service connects to a database using tpopen(), when the service is first initialized through tpsvrinit()). OpenLink XA-enabled ODBC drivers provide two functions, SQLGetXaEnv() and SQLGetXaConnect(), which make an XA connection available for use with ODBC. If the XA connection is enlisted in a global transaction, e.g. the client has called tpbegin() before calling the service, then any 'work' done by ODBC functions in the service will be controlled by that global transaction.
SQLGetXaEnv() returns the ODBC environment handle associated with the XA connection. SQLGetXaConnect() returns the ODBC connection handle associated with the XA connection. The prototypes for these functions are:
SQLRETURN SQLGetXaEnv(SQLHENV *phenv); SQLRETURN SQLGetXaConnect(SQLHDBC *phdbc);
When using OpenLink ODBC drivers in a global transaction context, you should not create an environment handle using SQLAllocHandle(), or use SQLSetEnvAttr(). (The SQLHENV associated with the XA connection is created with SQL_ATTR_ODBC_VERSION set to SQL_OV_ODBC3.) If you create an ODBC connection using this SQLHENV, it will not be enlisted in the global transaction.
JDBC
The OpenLink Multi-Tier JDBC drivers support distributed transactions using the Java Transaction API (JTA) as the Transaction Manager of the distributed transaction process.
Java Transaction API (JTA)
The OpenLink UDA Generic JDBC clients (opljdbc3.jar & opljdbc2.jar) support the industry standard XA specification for distributed transaction processing. The XA specification defines an interface between the transaction manager (TM) and resource manager (RM) in a distributed transaction system. This is a generic interface and it does not directly address the use of distributed transactions from Java. The Java mapping of the XA interface is defined in Sun Microsystems Java Transaction API (JTA) and JDBC 2.0/3.0 specifications. The OpenLink UDA Generic JDBC client drivers support the JTA architecture by providing the implementation of JTA resource manager interfaces.
The OpenLink UDA JDBC 3.0 driver provides the openlink.javax.OPLXid, openlink.javax.OPLXADataSource, and openlink.javax.OPLXAConnection classes which implement the interfaces javax.transaction.xa.Xid, javax.transaction.xa.XADataSource, javax.sql.XAConnection, and javax.sql.XAResource respectively. The use if these interfaces is usually transparent for applications and the application developer shouldn't bother with them. They are used only by the JTS transaction manager which normally runs as a part of the J2EE server.
JDBC 3.0 (JDK 1.4 & 1.5)
JTA support is built into the JRE for JDK 1.4 and 1.5, thus the UDA Generic JDBC client (opljdbc3.jar) simply needs to be added to the CLASSPATH and the XA classes will be available for use.
JDBC 2.0 (JDK 1.2 & 1.3)
JTA support was added by Sun Microsystems as an extension to the JDK 1.2 and 1.3 JRE's resulting in the following jar files having to be added to you CLASSPATH in additon to the UDA Generic JDBC client (opljdbc2.jar) :
jdbc2_0-stdext.jar jta-spec1_0_1.jar jndi.jar
JDBC XA Documentaton
Reference documentation for the OpenLink JDBC XA implementation in the UDA JDBC Client.