Re: Question on Manual Transaction Management in J2EE
Hrishikesh Barua <[email protected]> Wed, 7 Apr 2004 03:15:31 -0600
| Newsgroups | gmane.comp.java.sun.connector |
|---|---|
| Message-ID | <LISTSERV%[email protected]> |
Hi,
<snip>
Is it possible to access the XAResource on a XADataSource
deployed in a J2EE server?
</snip>
A J2EE server does not expose the xa datasources deployed on it as XA
datasource objects - that is why in the case of JBoss the object returned
on lookup is a wrapper - the wrapper internally uses the XAdatasource's xa
transaction semantics - or rather, the transaction manager uses it.
<snip>OR does JCA restrict the access to the XAResource
to the app server container</snip>
Where does JCA come into the picture? Or are you using a resource
adapter which has an XADatasource implementation? Am i missing something
here?
As i understand from the situation described you're trying to control
the transaction semantics from within the application and at the same time
let the app server's transaction manager go on with it's transaction
control - this is forbidden by the specification. If the application is
controlling the tx, as through the UserTransaction interface, the
application has to manage everything in that transaction, and not part of
it.
Also the XA interfaces are supposed to be used by the transaction
controller - in this case the transaction manager.
hope this helps.
Regards
Hrishikesh
On Wed, 7 Apr 2004 14:06:46 +0530, Ritu Kedia <[email protected]> wrote:
>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".
===========================================================================
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".