You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by Jack Wang <pi...@yahoo.com> on 2006/02/09 05:47:29 UTC

Web service in Kandula and XAResource in MySQL 5.0

--- Dasarath Weeratunge <dw...@purdue.edu>写道:
> 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: kandula-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: kandula-dev-help@ws.apache.org


Re: Web service in Kandula and XAResource in MySQL 5.0

Posted by Jack Wang <pi...@yahoo.com>.
Thanks Dasarath.

    XAResource with MySQL has not resolved yet, I will back later.


--- Dasarath Weeratunge <dw...@purdue.edu>写道:

> Quoting Jack Wang <pi...@yahoo.com>:
> 
> > Bank1.creditImpl(acc, dollars) {
> >   // Get tx
> >   org.apache.geronimo.transaction.manager.TransactionManagerImpl tmImpl = 
> >     new org.apache.geronimo.transaction.manager.TransactionManagerImpl();
> 
> don't create another instance of the transaction manager. This will not work. 
> Use the instance created by Kandula.




	

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

---------------------------------------------------------------------
To unsubscribe, e-mail: kandula-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: kandula-dev-help@ws.apache.org


Re: Web service in Kandula and XAResource in MySQL 5.0

Posted by Jack Wang <pi...@yahoo.com>.
Thanks Dasarath.

    XAResource with MySQL has not resolved yet, I will back later.


--- Dasarath Weeratunge <dw...@purdue.edu>写道:

> Quoting Jack Wang <pi...@yahoo.com>:
> 
> > Bank1.creditImpl(acc, dollars) {
> >   // Get tx
> >   org.apache.geronimo.transaction.manager.TransactionManagerImpl tmImpl = 
> >     new org.apache.geronimo.transaction.manager.TransactionManagerImpl();
> 
> don't create another instance of the transaction manager. This will not work. 
> Use the instance created by Kandula.




	

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

---------------------------------------------------------------------
To unsubscribe, e-mail: kandula-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: kandula-dev-help@ws.apache.org


Re: Web service in Kandula and XAResource in MySQL 5.0

Posted by Dasarath Weeratunge <dw...@purdue.edu>.
Quoting Jack Wang <pi...@yahoo.com>:

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

don't create another instance of the transaction manager. This will not work. 
Use the instance created by Kandula.

>   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();

As I've told you BEFORE, you should neither begin nor commit the tx. Tx will
be created automatically by the runtime when the method is called. You just have
to obtain a reference to it by some means and then enlist your resources. (Even 
this should be done by the container). You don't seem to understand the concept 
of distributed transaction. I suggest that you read a little bit about how 
ejb's handle transactions. Especially the section on Bean managed tx and 
container managed tx in the EJB spec.


>   // Return
>   return "";
> }
> --------------------------------------
> 
> Question 1)
>   Is the code right ?
> 
> Question 2)
>   I use JDK 1.5, Tomcat 5.5, MySQL: 5.0.18-win32,

if u are using jdk 1.5, please keep in mind that Kandula has ONLY been tested 
on jdk 1.4.2

--dasarath


> 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: kandula-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: kandula-dev-help@ws.apache.org
> 
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: kandula-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: kandula-dev-help@ws.apache.org


Re: Web service in Kandula and XAResource in MySQL 5.0

Posted by Dasarath Weeratunge <dw...@purdue.edu>.
Quoting Jack Wang <pi...@yahoo.com>:

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

don't create another instance of the transaction manager. This will not work. 
Use the instance created by Kandula.

>   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();

As I've told you BEFORE, you should neither begin nor commit the tx. Tx will
be created automatically by the runtime when the method is called. You just have
to obtain a reference to it by some means and then enlist your resources. (Even 
this should be done by the container). You don't seem to understand the concept 
of distributed transaction. I suggest that you read a little bit about how 
ejb's handle transactions. Especially the section on Bean managed tx and 
container managed tx in the EJB spec.


>   // Return
>   return "";
> }
> --------------------------------------
> 
> Question 1)
>   Is the code right ?
> 
> Question 2)
>   I use JDK 1.5, Tomcat 5.5, MySQL: 5.0.18-win32,

if u are using jdk 1.5, please keep in mind that Kandula has ONLY been tested 
on jdk 1.4.2

--dasarath


> 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: kandula-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: kandula-dev-help@ws.apache.org
> 
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: kandula-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: kandula-dev-help@ws.apache.org