Quoting Jack Wang <[EMAIL PROTECTED]>:

> 
> I try to follow it and here is my web application code in H3 running Kandula.
> 
> 
> /* -- wstm begin in H3 ------- */                                     
> ActivationStub stub = new ActivationStub(new
> EndpointReference("http://H3:port/axis/services/activationCoordinator";));
> CoordinationContext ctx =
> stub.createCoordinationContext(ATCoordinator.COORDINATION_TYPE_ID);
> EndpointReference cps = ctx.register(ATCoordinator.PROTOCOL_ID_COMPLETION,
>       new EndpointReference
("http://H3:port/axis/services/completionInitiator";));
> SetCoordCtxHandler.setCtx(ctx);
> /* --------------------------- */                                     


This code though gets the job done is ABSOLUTELY unnecessary. Use the 
o.a.k.coordinator.at.TransactionManager.begin/commit for this. The reason why 
it is not used in the InteropIBM sample is because that sample is a standalone 
application. Look at how things are done in test-suite1 implementation.

> Question 1:
> I wonder if I do not configure "UserTransaction" in H1 and H2's tomcats now
> when I operate the
> database in the web services of H1 and H2, which will be called by H3's
> transaction. And Also
> wonder if I do not configure "UserTransaction" in H3's tomcat , where there
> is a local db
> operation which will also be placed in the H3's same transaction.
> 

The *correct* way to do this is to create objects "UserTransaction" 
and "TransactionManager" and register them with JNDI at Tomcat startup. JOTM 
provides a good document on how to do this with JOTM. Look at that and try to 
do the same with Geronimo TM. Once thing to be careful here is not to create 
two instances of the TM. Kandula Bridge (o.a.k.geronimo.Bridge) presently 
instantiates the TM when the class is loaded. This instance can be obtained by 
calling Bridge.getTM(). If this interface is not enough let us know and I will 
change the code promptly.

In future Kandula will be integrated with Geronimo and all this work will be 
unnecessary.

> In the normal application, I use UserTransaction configured in tomcat's
> sever.xml to operate
> database. The code is as follow:
> 
> /* -- normal db application ----------------- */                              
> Context ctx = new InitialContext();
> UserTransaction ut =
> (UserTransaction)ctx.lookup("java:comp/env/UserTransaction");
> DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/myDB");
> java.sql.Connection conn = ds.getConnection();
> ut.begin();
> Statement stmt = conn.createStatement();
> PreparedStatement pstmt = conn.prepareStatement("update ...");
> ...

This is correct. But to run this code you MUST do what I said before. Also note 
that you are not directly using the ws-at protocol here. This is the most 
likely way in which Kandula will be used by participants.

In fact in the earlier code we even supported exporting J2EE transactions 
automatically when ws calls were made from a thread with an active J2EE tx 
context.

> 
> My application will be a ws container application, so not consider standalone
> application. 

so then you will have no trouble using o.a.k.coordinator.at.TM

> 
> I try to follow it and here is my code in H1 or H2 to do the db transaction.
> The database server
> is mySQL 5.0 and I will use Connector/J 5.0 jdbc driver, so I can use
> Distributed Transactions.
> 
> /* -----db transaction in H1 and H2 --------- */   
> MysqlXADataSource xaDs = new MysqlXADataSource();
> XAConnection xaConn = xaDs.getXAConnection();
> javax.transaction.xa.XAResource xaRes = xaConn.getXAResource();
> /* ------------------------------------------ */   
> 
> > Transaction tx = tm.getTransaction();
> > tx.enlistResource(xaRes);
> > 

this is correct. But this should be done some where else. See the JOTM/Tomcat 
integration example.

> application container. I can
> get a UserTransaction. Can I get a Transaction instance directly by
> "Transaction tx =
> javax.transaction.TransactionManager.getTransaction();" ? If not, how can I
> get the local j2ee tx?

you can do this. Looking at the code of the TM will help resolve this type of 
questions. Get the source of the Geronimo TM and have a look or ask on geronimo-
user and David Jenks him self will answer:-)

> /* ----- SQL statements in H1 and H2 --------- */   
> Connection conn = xaConn.getConnection();
> Xid xid = createXid();
> xaRes.start(xid, XAResource.TMNOFLAGS);
> conn.createStatement().executeUpdate("INSERT INTO testCoordination VALUES
> (1)");
> xaRes.end(xid, XAResource.TMSUCCESS);
> int ret = xaRes.prepare(xid);
> if (ret == XAResource.XA_OK) { 
>       xaRes.commit(xid, false); 
> } else{
>       xaRes.rollback(xid); 
> }

this is NOT correct. User applications should never deal with XAResource 
interface directly. Use the commit/rollback methods in TM or Tx interface.

> /* ------------------------------------------ */   
> 
> Question 3:
> If H3's transaction also contains a local database operation, I should let
> the H3's local j2ee tx
> enlist the xaRes in H3's bean, which will be called by a jsp's request. Is it
> right?

your Q is not clear. Isn't H3 where Kandula is running?

> 
> Question 4:
> The key problem is that I don't know how to get the local JTA(j2ee) tx, and
> how kandula ties the
> local tx with the corresponding (global) ws-at tx, please ask in which class
> kandula ties them ?

this is very simple. Look at the o.a.k.geronimo.* package. However, the current 
code only supports importing ws tx s into j2ee. It is also possible to export 
j2ee tx s as ws tx s but it not implemented yet.

thanks,
--dasarath

> 
> Thanks again
> 
> 
> 
> Wang Jun
> 
> 
>       
> 
>       
>               
> ___________________________________________________________ 
> ÑÅ»¢1GÃâ·ÑÓÊÏä°Ù·Ö°Ù·ÀÀ¬»øÐÅ 
> http://cn.mail.yahoo.com/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to