testTwoPhase("xaSimple2b", true, false);
}
private void testTwoPhase(String db, boolean shutdown, boolean commit) throws Exception {
deleteDb(db);
JdbcDataSource ds = new JdbcDataSource();
ds.setPassword(getPassword());
ds.setUser("sa");
// ds.setURL(getURL("xaSimple", true) + ";trace_level_system_out=3");
ds.setURL(getURL(db, true));
XAConnection xa;
xa = ds.getXAConnection();
Connection conn;
conn = xa.getConnection();
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar(255))");
Xid xid = SimpleXid.createRandom();
xa.getXAResource().start(xid, XAResource.TMNOFLAGS);
conn.setAutoCommit(false);
stat.execute("insert into test values(1, 'Hello')");
xa.getXAResource().end(xid, XAResource.TMSUCCESS);
xa.getXAResource().prepare(xid);
if (shutdown) {
shutdown(ds);
}
xa = ds.getXAConnection();
Xid[] list = xa.getXAResource().recover(XAResource.TMSTARTRSCAN);
assertEquals(1, list.length);
assertTrue(xid.equals(list[0]));
if (commit) {
xa.getXAResource().commit(list[0], false);
} else {
xa.getXAResource().rollback(list[0]);
}
if (shutdown) {
shutdown(ds);
}
xa = ds.getXAConnection();
list = xa.getXAResource().recover(XAResource.TMSTARTRSCAN);
assertEquals(0, list.length);
conn = xa.getConnection();
ResultSet rs;
rs = conn.createStatement().executeQuery("select * from test");