--- Dasarath Weeratunge <[EMAIL PROTECTED]>写道:
> Quoting Jack Wang <[EMAIL PROTECTED]>:
>
> Hello Jack,
>
> Have you had a look at the following stuff in Tomcat docs?
>
> http://tomcat.apache.org/tomcat-4.1-doc/jndi-datasource-examples-howto.html
>
> What is missing in your work is you when you create the connection in you
> DataSource object's getConnection method, you need to also create an
> XAConnection and then enlist the XAResource in the local tx associated with
> the
> thread. This you can get from the TM and must be done BEFORE you return the
> connection object to your application.
>
Hi, Dasarath,
The key problem I met these days is that I can not get the local tx in the
service side, so I have
not reached enlisting resource step yet. This problem should not post to
kandula-dev, maybe it is
a MySQL's bug.
As the previous mail's illustration, I first do a test without Kandula's
participation. In this
test, I use Jotm and MySQL to suport XA, and Tomcat 5.5 is the container, and
there is no ws yet.
I can get XAResource whth the JNDI's configuratioin in tomcat, and can also get
the tm with
several methods:
1)
TMService jotm = new Jotm(true, false);
TransactionManager tm = jotm.getTransactionManager();
javax.transaction.Transaction tx = tm.getTransaction(); <== NULL !!
or
2)
TransactionManager tm = o.a.k.g.Bridge.getInstance().getTM();
javax.transaction.Transaction tx = tm.getTransaction(); <== NULL !!
But both methods can not produce the correct tx, only null value. I have a test
to add these code
in a web service, especially method 2, and called by the kandula's client, but
I can not get the
tx also.
> When you invoke a ws with a coordination ctx, Kandula will create a local tx
> and attach that to the thread that runs your service implementation. This is
> why you do not and SHOULD NOT call begin() in your code. Then when the global
> ws-at tx is terminated, the Kandula will terminate that local tx as
> appropriate. This why you SHOULD not commit the tx. You can however rollback
> the local tx. Then Kandula will rollback the global tx. If you mark your
> local
> tx is RollbackOnly this will happen when the global ws-at tx is terminated.
> If
> rollback the local tx, the global ws-at tx will also be rollbacked
> immediately.
> If you try to commit the local tx, then AGAIN the global ws-at tx will be
> immediately rollbacked by Kandula since what you are tring to do is illegal.
>
> --dasarath
Yes. This test has no kandula and ws yet. I only use it to test MySQL's XA
operation. If MySQL'XA
is avalable, I will use it with Kandula.
Thanks Dasarath.
And these is the previous mail which has no concern with kandula yet. I paste
here for reference.
---------- previous mail begin ---------------
I hava done a test to use the MySQL XADataSource. For MySQL has no
MYSQLXADataSourceFactory
class, so I coded one to produce MysqlXADataSource. MysqlXADataSource is
configured in tomcat 5.5
server.xml. I can get the MysqlXADataSource instance xaDs by which I can get
XAConnection and
XAResource. I also configured a UserTransaction which was produced by
org.objectweb.jotm.UserTransactionFactory. The following is the action's code
in a test web
application. This action runs correctly the first time, but in the second time,
it runs very slow,
then reports "Lock wait timeout exceeded; try restarting transaction" error.
The first question is that it seems the action did not update the table
testdata's data. Did the
UserTransaction ut have some error not participate in the database transaction?
The second question is that I have searched this error, but don't know how to
solve it. Please
give me some tips. Must I not use MySQL's XA in Kandula ? Thanks.
The java code (JOTM example):
========================================================
UserTransaction ut = null;
try{
Context ctx = new InitialContext();
MysqlXADataSource xaDs =
(MysqlXADataSource)ctx.lookup("java:comp/env/jdbc/myXADB");
ut = (UserTransaction)ctx.lookup("java:comp/env/UserTransaction");
XAConnection xCon = xaDs.getXAConnection();
java.sql.Connection conn = xCon.getConnection();
System.out.println("<<< beginning the transaction >>> xa con = " + conn);
ut.begin();
// JDBC statements
Statement stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery("select id, foo from testdata");
if(rst.next()) {
foo=rst.getInt(2);
}
System.out.println("foo = "+ foo +" (before completion)");
String sql = "update testdata set foo=" + (++foo) + " where id=1";
stmt.executeUpdate(sql);// <=== The program will wait here, and then report
the error message
!
ut.commit();
System.out.println("<<< committing the transaction >>>");
conn.close();
System.out.println("<<< done >>>");
}catch(Exception e) {
System.out.print("DBTest >> ");
e.printStackTrace();
System.out.println("<<< rolling back the transaction >>>");
try {
ut.rollback();
System.out.println("rollback ok.");
}catch(Exception e1){
System.out.println("rollback Error " + e1);
}
System.out.println("rollback end");
}
}
========================================================
The error message:
========================================================
==> xaDataSource = [EMAIL PROTECTED] <==
<<< beginning the transaction >>> xa con = [EMAIL PROTECTED]
foo = 29 (before completion)
<<< committing the transaction >>>
<<< done >>>
<<< beginning the transaction >>> xa con = [EMAIL PROTECTED]
foo = 29 (before completion)
- set rollback only (tx=bb14:38:0:01777d30dfc9556034...986c02:)
DBTest >> java.sql.SQLException: Lock wait timeout exceeded; try restarting
transaction
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2822)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1536)
at
com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1159)
at
com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:684)
at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1184)
at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1101)
at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1086)
at
com.mysql.jdbc.jdbc2.optional.PreparedStatementWrapper.executeUpdate(PreparedStatementWrapper.java:840)
at foo.XADBTest.init(XADBTest.java:92)
at
org.apache.jsp.testJotm_jsp._jspService(org.apache.jsp.testJotm_jsp:55)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
<<< rolling back the transaction >>>
rollback ok.
rollback end
---------- previous mail end ---------------
Wang Jun
__________________________________________________
赶快注册雅虎超大容量免费邮箱?
http://cn.mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]