提交 9339158f authored 作者: Noel Grandin's avatar Noel Grandin

Fix bug in XA management when doing rollback after prepare. Patch by

Stephane Lacoin.
上级 7071b605
......@@ -21,6 +21,7 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>Fix bug in XA management when doing rollback after prepare. Patch by Stephane Lacoin.
<li>MVStore CLOB and BLOB: An exception with the message "Block not found" could be thrown
when using the MVStore storage, when copying LOB objects
(for example due to "alter table" on a table with a LOB object),
......
......@@ -274,8 +274,6 @@ public class JdbcXAConnection extends TraceObject implements XAConnection,
debugCode("rollback("+JdbcXid.toString(xid)+");");
}
try {
physicalConn.rollback();
physicalConn.setAutoCommit(true);
if (prepared) {
Statement stat = null;
try {
......@@ -285,7 +283,10 @@ public class JdbcXAConnection extends TraceObject implements XAConnection,
JdbcUtils.closeSilently(stat);
}
prepared = false;
} else {
physicalConn.rollback();
}
physicalConn.setAutoCommit(true);
} catch (SQLException e) {
throw convertException(e);
}
......
......@@ -38,6 +38,7 @@ public class TestXA extends TestBase {
@Override
public void test() throws Exception {
testRollbackWithoutPrepare();
testRollbackAfterPrepare();
testXAAutoCommit();
deleteDb("xa");
testMixedXaNormal();
......@@ -92,6 +93,45 @@ public class TestXA extends TestBase {
deleteDb("xa");
}
private void testRollbackAfterPrepare() throws Exception {
Xid xid = new Xid() {
@Override
public int getFormatId() {
return 3145;
}
@Override
public byte[] getGlobalTransactionId() {
return new byte[] { 1, 2, 3, 4, 5, 6, 6, 7, 8 };
}
@Override
public byte[] getBranchQualifier() {
return new byte[] { 34, 43, 33, 3, 3, 3, 33, 33, 3 };
}
};
deleteDb("xa");
JdbcDataSource ds = new JdbcDataSource();
ds.setURL(getURL("xa", true));
Connection dm = ds.getConnection();
Statement stat = dm.createStatement();
stat.execute("CREATE TABLE IF NOT EXISTS TEST(ID INT PRIMARY KEY, VAL INT)");
stat.execute("INSERT INTO TEST(ID,VAL) VALUES (1,1)");
dm.close();
XAConnection c = ds.getXAConnection();
XAResource xa = c.getXAResource();
Connection connection = c.getConnection();
xa.start(xid, XAResource.TMJOIN);
PreparedStatement ps = connection.prepareStatement("UPDATE TEST SET VAL=? WHERE ID=?");
ps.setInt(1, new Random().nextInt());
ps.setInt(2, 1);
ps.close();
xa.prepare(xid);
xa.rollback(xid);
connection.close();
c.close();
deleteDb("xa");
}
private void testMixedXaNormal() throws Exception {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论