--- Dasarath Weeratunge <[EMAIL PROTECTED]>写道:
> Say now, that YOU are providing Bank1 (or Bank2 or both)
> 
> Now when you create a DataSource in JDBC it gives you an XAResource 
> interface. 
> You must register this XAResource interface with the local j2ee tx.
> 
> e.g.
> 
> Bank1.creditImpl(acc, dollars) {
> 
> xaRes = createConnection("JDBC:connection string");
> Transaction tx = tm.getTransaction();
> tx.enlistResource(xaRes);
> 
> // SQL statements
> 
> tx.delistResource(xaRes);
> }
> 
> This usually happens transparently if your TM and DB are properly hooked up 
> to 
> your container-- say Tomcat. (However, I've not seen any docs on how to to do 
> this with Geronimo but certainly it is possible.)

I try to code the web service which will be called in a kandula's transaction.

--------------------------------------
Bank1.creditImpl(acc, dollars) {
  // Get tx
  org.apache.geronimo.transaction.manager.TransactionManagerImpl tmImpl = 
    new org.apache.geronimo.transaction.manager.TransactionManagerImpl();
  javax.transaction.Transaction tx = tmImpl.getTransaction();

  // Get ut and xARes
  Context ctx = new InitialContext();
  UserTransaction ut = 
(UserTransaction)ctx.lookup("java:comp/env/UserTransaction");
  XADataSource xaDs = (XADataSource)ctx.lookup("java:comp/env/jdbc/myXADB");  
<-- Oops, NULL value
!!
  XAConnection xAConn = xaDs.getXAConnection();
  XAResource xARes = xAConn.getXAResource();

  // Enlist xARes
  tx.enlistResource(xARes);

  // Begin ut
  ut.begin();

  // Operate db
  java.sql.Connection conn = xAConn.getConnection();
  Statement stmt = conn.createStatement();
  PreparedStatement pstmt = conn.prepareStatement("update ...");

  // Commit ut
  ut.commit();
 
  // Return
  return "";
}
--------------------------------------

Question 1)
  Is the code right ?

Question 2)
  I use JDK 1.5, Tomcat 5.5, MySQL: 5.0.18-win32, 
mysql-connector-java-5.0.0-beta. I have
configured the XADataSource in tomcat's server.xml, but I only get a null xaDs, 
Oops !! So there
is no xARes yet. I have put this question in mysql mail list. This is the 
XADataSource
configuration in server.xml:

--------------------------------------
  <Resource name="jdbc/myXADB" auth="Container"
    type="javax.sql.XADataSource"
    factory="com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory"
    driverClassName="com.mysql.jdbc.Driver"
    user="root"
    password="password"
    url="jdbc:mysql://localhost/test?useUnicode=true&amp;characterEncoding=gbk"
  />
--------------------------------------

I still tried to test kandula. Please help. Thanks.



Wang Jun


        

        
                
___________________________________________________________ 
雅虎1G免费邮箱百分百防垃圾信 
http://cn.mail.yahoo.com/

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

Reply via email to