ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahh_5.4.0.1/jdbcxa.htm

97 lines
6.0 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="JDBC XA Distributed Transaction Management" />
<meta name="abstract" content="The JDBC XA distributed transaction management classes enable you to use the IBM Toolbox for Java JDBC driver within a distributed transaction. Using the XA classes to enable the IBM Toolbox for Java JDBC driver allows it to participate in transactions that span multiple data sources." />
<meta name="description" content="The JDBC XA distributed transaction management classes enable you to use the IBM Toolbox for Java JDBC driver within a distributed transaction. Using the XA classes to enable the IBM Toolbox for Java JDBC driver allows it to participate in transactions that span multiple data sources." />
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="jdbcxa" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>JDBC XA Distributed Transaction Management</title>
</head>
<body id="jdbcxa"><a name="jdbcxa"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">JDBC XA Distributed Transaction Management</h1>
<div><p>The JDBC XA distributed transaction management classes enable you
to use the IBM<sup>®</sup> Toolbox
for Java™ JDBC
driver within a distributed transaction. Using the XA classes to enable the IBM Toolbox
for Java JDBC
driver allows it to participate in transactions that span multiple data sources.</p>
<div class="section"><p>Typically, XA distributed transaction management classes are used
and controlled directly by a transaction manager, which is separate from
the JDBC driver. The distributed transaction management interfaces are defined
as part of the JDBC 2.0 Optional Package and the Java Transaction API (JTA). Both are available
from Sun as jar files. The distributed transaction management interfaces
are also supported in the JDBC 3.0 API, which is bundled with the Java 2
Platform, Standard Edition, version 1.4.</p>
<p>For more information, see
the Sun Web sites for <a href="http://java.sun.com/products/jdbc/index.html" target="_blank">JDBC</a> <img src="www.gif" alt="Link outside Information Center" /> and the <a href="http://java.sun.com/products/jta/index.html" target="_blank">JTA</a> <img src="www.gif" alt="Link outside Information Center" />.</p>
<p>Use the following objects to enable the IBM Toolbox for Java JDBC
driver to participate in XA distributed transactions:</p>
<ul><li><a href="javadoc/com/ibm/as400/access/AS400JDBCXADataSource.html#NAVBAR_TOP"> AS400JDBCXADataSource</a> - A factory for AS400JDBCXAConnection
objects. This is a subclass of <a href="javadoc/com/ibm/as400/access/AS400JDBCDataSource.html#NAVBAR_TOP"> AS400JDBCDataSource</a>.</li>
<li><a href="javadoc/com/ibm/as400/access/AS400JDBCXAConnection.html#NAVBAR_TOP"> AS400JDBCXACConnection</a> - A pooled connection object
that provides hooks for connection pool management and XA resource management.</li>
<li><a href="javadoc/com/ibm/as400/access/AS400JDBCXAResource.html#NAVBAR_TOP"> AS400JDBCXAResource</a> - A resource manager for use in
XA transaction management.</li>
</ul>
<div class="note"><span class="notetitle">Note:</span> Prior to V5R3, the database host server used <a href="../apis/unix12a.htm">XA APIs for Job Scoped Locks</a> (XA model).
In V5R3 and subsequent releases, the database host server uses <a href="../apis/unix12b.htm">XA APIs for Transaction Scoped Locks</a> (NTS
model) for all MTS functions. For more information about how these APIs differ,
see <a href="../apis/unix12.htm">XA APIs</a>.</div>
</div>
<div class="section"><h4 class="sectiontitle">Example: Using XA classes</h4><p>The following example
shows simple usage of the XA classes. Keep in mind that the details would
be filled in with work using other data sources. This type of code usually
appears within a transaction manager.</p>
<pre> // Create an XA data source for making the XA connection.
AS400JDBCXADataSource xaDataSource = new AS400JDBCXADataSource("myAS400");
xaDataSource.setUser("myUser");
xaDataSource.setPassword("myPasswd");
// Get an XAConnection and get the associated XAResource.
// This provides access to the resource manager.
XAConnection xaConnection = xaDataSource.getXAConnection();
XAResource xaResource = xaConnection.getXAResource();
// Generate a new Xid (this is up to the transaction manager).
Xid xid = ...;
// Start the transaction.
xaResource.start(xid, XAResource.TMNOFLAGS);
// ...Do some work with the database...
// End the transaction.
xaResource.end(xid, XAResource.TMSUCCESS);
// Prepare for a commit.
xaResource.prepare(xid);
// Commit the transaction.
xaResource.commit(xid, false);
// Close the XA connection when done. This implicitly
// closes the XA resource.
xaConnection.close();</pre>
</div>
</div>
</body>
</html>