use of org.h2.jdbcx.JdbcXAConnection in project h2database by h2database.
the class TestDataSource method testXAConnection.
private void testXAConnection(boolean userInDataSource) throws Exception {
deleteDb("dataSource");
JdbcDataSource ds = new JdbcDataSource();
String url = getURL("dataSource", true);
String user = getUser();
ds.setURL(url);
if (userInDataSource) {
ds.setUser(user);
ds.setPassword(getPassword());
}
if (userInDataSource) {
assertEquals("ds" + ds.getTraceId() + ": url=" + url + " user=" + user, ds.toString());
} else {
assertEquals("ds" + ds.getTraceId() + ": url=" + url + " user=", ds.toString());
}
XAConnection xaConn;
if (userInDataSource) {
xaConn = ds.getXAConnection();
} else {
xaConn = ds.getXAConnection(user, getPassword());
}
int traceId = ((JdbcXAConnection) xaConn).getTraceId();
assertTrue(xaConn.toString().startsWith("xads" + traceId + ": conn"));
xaConn.addConnectionEventListener(new ConnectionEventListener() {
@Override
public void connectionClosed(ConnectionEvent event) {
// nothing to do
}
@Override
public void connectionErrorOccurred(ConnectionEvent event) {
// nothing to do
}
});
XAResource res = xaConn.getXAResource();
assertFalse(res.setTransactionTimeout(1));
assertEquals(0, res.getTransactionTimeout());
assertTrue(res.isSameRM(res));
assertFalse(res.isSameRM(null));
Connection conn = xaConn.getConnection();
assertEquals(user.toUpperCase(), conn.getMetaData().getUserName());
Xid[] list = res.recover(XAResource.TMSTARTRSCAN);
assertEquals(0, list.length);
Statement stat = conn.createStatement();
stat.execute("SELECT * FROM DUAL");
conn.close();
xaConn.close();
}
Aggregations