提交 822498a8 authored 作者: Thomas Mueller's avatar Thomas Mueller

XA connection: after transaction commit or rollback, the physical connection is…

XA connection: after transaction commit or rollback, the physical connection is set into autocommit mode.
上级 edd6df0d
......@@ -304,6 +304,7 @@ implements XAConnection, XAResource
}
try {
physicalConn.rollback();
physicalConn.setAutoCommit(true);
} catch (SQLException e) {
throw convertException(e);
}
......@@ -384,6 +385,7 @@ implements XAConnection, XAResource
stat = physicalConn.createStatement();
stat.execute("COMMIT TRANSACTION TX_" + currentTransactionId);
}
physicalConn.setAutoCommit(true);
} catch (SQLException e) {
throw convertException(e);
} finally {
......
......@@ -38,6 +38,7 @@ public class TestXA extends TestBase {
public void test() throws Exception {
testXAAutoCommit();
deleteDb("xa");
testMixedXaNormal();
testXA(true);
deleteDb(DB_NAME1);
deleteDb(DB_NAME2);
......@@ -47,6 +48,33 @@ public class TestXA extends TestBase {
deleteDb(DB_NAME2);
}
private void testMixedXaNormal() throws Exception {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test");
ds.setUser("sa");
ds.setPassword("");
XAConnection xa = ds.getXAConnection();
Connection c = xa.getConnection();
assertTrue(c.getAutoCommit());
MyXid xid = new MyXid();
XAResource res = xa.getXAResource();
res.start(xid, XAResource.TMNOFLAGS);
assertTrue(!c.getAutoCommit());
res.end(xid, XAResource.TMSUCCESS);
res.commit(xid, true);
assertTrue(c.getAutoCommit());
res.start(xid, XAResource.TMNOFLAGS);
assertTrue(!c.getAutoCommit());
res.end(xid, XAResource.TMFAIL);
res.rollback(xid);
assertTrue(c.getAutoCommit());
c.close();
xa.close();
}
/**
* A simple Xid implementation.
*/
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论