Re: Question on Manual Transaction Management in J2EE

Hrishikesh Barua <[email protected]> Wed, 7 Apr 2004 05:16:07 -0600
Newsgroups gmane.comp.java.sun.connector
Message-ID <LISTSERV%[email protected]>
Hi,
 <snip>
From my EJB or from my Servlet code, can I access the XADataSource, deployed
by the App Server, directly?
 </snip>
The appserver does not allow access to the XADataSource or it's xa
connections to the application code.
If you want such access you can try instantiating the XADataSource
implementation class yourself - but that'll bypass the application server
and it's management altogether - and it's not recommended nor is it the
correct way to use an XADataSource.
The scenario here cannot be managed through XA semantics because
1. The third party tool does not allow access to xa operations - only UT.
(as you mentioned)
2. The datasource from the jndi lookup does not allow access to XA
operations - it's internally managed. (as mentioned above)
Even if the third party tool allow access to it's TransactionManager it
won't be possible to control the xa phases manually.

Regards
  Hrishikesh

On Wed, 7 Apr 2004 15:43:51 +0530, Ritu Kedia <[email protected]> wrote:

>Thanks for replying Hrishikesh.
>
>In response to your reply:
>> 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.
>
>We are not in synch here. I want to do complete Tx Management Manually
(i.e.
>via my Application). The problem is that the third party tool that I am
>using manages multiple stores and hence has its own JTA implementation to
>manage its distributed transactions. In addition to the operations
performed
>by this third party tool I also want to perform some operations on my local
>DB and club my transaction and the third party actions into a single
>transaction. I have defined my local DB Connection as managed by
>"Servlet/Application". And also defined the DB connections used by the
third
>party tool as "Servlet/Application" (i.e. <res-auth> tag is defined as
>either Servlet or Application).
>
>Given that the third party tool does not support External Tx Manager (i.e.
>allowing JBoss' Tx Manager to control the third party transactions), how do
>I ensure Consistency between the operations performed by the third party
>tool and my DB?
>
>I thought I could do this if the App Container gave acceess to XADataSource
>and in turn XAConnection.
>
>I understand that JCA allows applications to manage transactions by
>UserTransaction. UserTransaction internally manages the TransactionManager,
>which performs the 2 phase commit. But I want control of the 2 phase commit
>inside my application. Basically I want my Application to act as the
>TransactionManager (though I require very rudimentary functionality).
>In other words, the UserTransaction allows me to define the Transaction
>boundaries by begin and commit/rollback, but it does not give me control
>over the individual phases of the 2 phase commit.
>
>
>Just to reiterate my point, I will again explain the pseudo code:
>
>Get ThirdParty's UserTransaction -- javax.transaction.UserTransaction utx =
>thirdparty.getUserTransaction()
>Get MyDB Connection -- Context initCtx = new InitialContext();Context
envCtx
>= (Context) initCtx.lookup("java:comp/env");
>DataSource myDS = (DataSource) envCtx.lookup("jdbc/MyDB");
>Perform ThirdParty Operations -- utx.begin(); thirdparty.performAction();
>Perform MyDB Operations -- java.sql.Connection myCon = myDS.getConnection
();
>Update MyDB
>Commit ThirdParty's UserTransaction -- utx.commit();
>Commit MyDB Connection -- myCon.commit();
>
>In the above e.g. if utx.commit() goes fine but if myCon.commit() fails,
>there is no way I can do utx.rollback(). The reverse order i.e.
>myCon.commit() before utx.commit() also presents similar problem.
>
>From my EJB or from my Servlet code, can I access the XADataSource,
deployed
>by the App Server, directly? If yes, then I can perform a manual 2 phase
>commit on the XAResource obtained from the XAConnection of the
XADataSource.
>
>
>Thanks,
>Ritu
>
>
>
>> -----Original Message-----
>> From: Hrishikesh Barua [mailto:[email protected]]
>> Sent: Wednesday, April 07, 2004 2:46 PM
>> To: [email protected]
>> Subject: Re: Question on Manual Transaction Management in J2EE
>>
>>
>> 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".
>>
>
> ==========================================================================
>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".