提交 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 ...@@ -304,6 +304,7 @@ implements XAConnection, XAResource
} }
try { try {
physicalConn.rollback(); physicalConn.rollback();
physicalConn.setAutoCommit(true);
} catch (SQLException e) { } catch (SQLException e) {
throw convertException(e); throw convertException(e);
} }
...@@ -384,6 +385,7 @@ implements XAConnection, XAResource ...@@ -384,6 +385,7 @@ implements XAConnection, XAResource
stat = physicalConn.createStatement(); stat = physicalConn.createStatement();
stat.execute("COMMIT TRANSACTION TX_" + currentTransactionId); stat.execute("COMMIT TRANSACTION TX_" + currentTransactionId);
} }
physicalConn.setAutoCommit(true);
} catch (SQLException e) { } catch (SQLException e) {
throw convertException(e); throw convertException(e);
} finally { } finally {
......
...@@ -38,6 +38,7 @@ public class TestXA extends TestBase { ...@@ -38,6 +38,7 @@ public class TestXA extends TestBase {
public void test() throws Exception { public void test() throws Exception {
testXAAutoCommit(); testXAAutoCommit();
deleteDb("xa"); deleteDb("xa");
testMixedXaNormal();
testXA(true); testXA(true);
deleteDb(DB_NAME1); deleteDb(DB_NAME1);
deleteDb(DB_NAME2); deleteDb(DB_NAME2);
...@@ -47,6 +48,33 @@ public class TestXA extends TestBase { ...@@ -47,6 +48,33 @@ public class TestXA extends TestBase {
deleteDb(DB_NAME2); 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. * A simple Xid implementation.
*/ */
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论