Question on Manual Transaction Management in J2EE
Ritu Kedia <[email protected]> Wed, 7 Apr 2004 14:06:46 +0530
| Newsgroups | gmane.comp.java.sun.connector |
|---|---|
| Message-ID | <641BC301F922D511BA8000B0D07821C8CECF1A@SABAINDMAIL> |
Hello all,
This is my first mail to this list. I am new to JCA. I have a question on
manual transaction management in EJB.
Inside my EJB I want to manually control the 2 phase commit. I am using a
third party product for part of my requirements and in addition performing
some local DB operations as part of the same Tx. The third party product has
its own JTA implementation and currently does not support External Tx
Manager. So I want to do a manual distributed Tx management between the
third party product and my db. In other words, I want to access the
XAResource of my local DB connection and invoke "prepare" on it before
calling commint on the UserTransaction provided by the third party product.
Note that the third party product does not allow me to plug in my own
XAResource in their Tx framework (i.e. their TxMgr)
To sum it up: Is it possible to access the XAResource on a XADataSource
deployed in a J2EE server? OR does JCA restrict the access to the XAResource
to the app server container? If possible, please provide me some sample code
to access the XAResource.
Psuedo Code:
Get ThirdParty's UserTransaction
Get MyDB Connection
Perform ThirdParty Operations
Perform MyDB Operations
Commit ThirdParty's UserTransaction
Commit MyDB Connection
In this scenario, if the commit of the MyDB operations fails, there is
no way to rollback ThirdParty's UserTx (and vice-versa if I were to reverse
the
order of the commits). The problem is that of a 2PC. Till the third party
supports
plugging External TxMgr, is there a workaround to achieve this use case?
I defined a XADataSource in my J2EE server. It deployed fine. Is there a way
to access XAResource on this XADataSource inside the J2EE environment? I am
looking at the following:
Get ThirdParty's UserTransaction
Get MyDB XAResource
MyDB.XAResource.start(xid);
Perform ThirdParty Operations
Perform MyDB Operations
MyDB.XAResource.end(xid);
MyDB.XAResource.prepare()
if (above step returns success)
{
try {
Commit ThirdParty's UserTx
Commit MyDB Connection
}
catch (Exception e)
{
Rollback MyDB Connection
Rollback ThirdParty's UserTx
}
}
else
{
Rollback ThirdParty's UserTx
Rollback MyDB Connection
}
I am running JBoss 3.2.x and have defined oracle-xa-ds.xml in
server/default/deploy directory:
<xa-datasource>
<jndi-name>XAOracleDS</jndi-name>
<track-connection-by-tx>true</track-connection-by-tx>
<isSameRM-override-value>false</isSameRM-override-value>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource
-class>
<xa-datasource-property
name="URL">jdbc:oracle:oci8:@ritu:1521:qadb</xa-datasource-property>
<xa-datasource-property name="User">xyz</xa-datasource-property>
<xa-datasource-property name="Password">xyz</xa-datasource-property>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleEx
ceptionSorter</exception-sorter-class-name>
</xa-datasource>
Java Code that Loads the XADataSource
Context initCtx = new InitialContext();
WrapperDataSource xads = (WrapperDataSource) envCtx.lookup("jdbc/MyXADS");
Connection con = xads.getConnection();
I expected the JNDI lookup for my XAOracleDS to return an XADataSource, but
instead it returns org.jboss.resource.adapter.jdbc.WrapperDataSource. And
WrapperDataSource has no public method to access the XADataSource or the
XAConnection. How do I get the XAConnection?
I have an urgent requirement...your reply would be greatly appreciated.
Regards,
Ritu
===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff CONNECTOR-INTEREST". For general help, send email to
[email protected] and include in the body of the message "help".