このコンテンツは選択した言語では利用できません。

6.9. Global Transactions


Global or client XA transactions allow the JBoss Data Virtualization JDBC API to participate in transactions that are beyond the scope of a single client resource. For this, use the org.teiid.jdbc.TeiidDataSource class for establishing connections.
When the data source class is used in the context of a user transaction in an application server, such as JBoss, WebSphere, or Weblogic, the resulting connection will already be associated with the current XA transaction. No additional client JDBC code is necessary to interact with the XA transaction.
The following code demonstrates usage of UserTransactions.
UserTransaction ut = context.getUserTransaction();
try {
	ut.begin();
	Datasource oracle = lookup(...)
	Datasource teiid = lookup(...)
	Connection c1 = oracle.getConnection();
	Connection c2 = teiid.getConnection();
	// do something with Oracle connection
	// do something with Teiid connection
	c1.close();
	c2.close();
	ut.commit();
} catch (Exception ex) {
	ut.rollback();
}
Copy to Clipboard Toggle word wrap
The following code demonstrates manual usage of XA transactions.
XAConnection xaConn = null;
XAResource xaRes = null;
Connection conn = null;
Statement stmt = null;

try 
{
   xaConn = <XADataSource instance>.getXAConnection();
   xaRes = xaConn.getXAResource();
   Xid xid = <new Xid instance>;
   conn = xaConn.getConnection();
   stmt = conn.createStatement();

   xaRes.start(xid, XAResource.TMNOFLAGS);
   stmt.executeUpdate("insert into …");
   // other statements on this connection or other resources enlisted in this transaction
   // ...
   xaRes.end(xid, XAResource.TMSUCCESS);
        
   if (xaRes.prepare(xid) == XAResource.XA_OK) 
   {
      xaRes.commit(xid, false);
   }
}
catch (XAException e) 
{
   xaRes.rollback(xid);
} 
finally 
{
  // clean up code
  // ...
}
Copy to Clipboard Toggle word wrap
With the use of global transactions, multiple XAConnections may participate in the same transaction. It is important to note that the JDBC XAResource isSameRM() method only returns true if connections are made to the same server instance in a cluster. If the JBoss Data Virtualization connections are to different server instances then transactional behavior may not be the same as if they were to the same cluster member. For example, if the client transaction manager uses the same XID for each connection, duplicate XID exceptions may arise from the same physical source accessed through different cluster members. If the client transaction manager uses a different branch identifier for each connection, issues may arise with sources that lock or isolate changes based upon branch identifiers.
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat