use of nl.topicus.jdbc.xa.CloudSpannerXAConnection in project spanner-jdbc by olavloite.
the class XATester method testXATransaction.
private void testXATransaction(CloudSpannerXAConnection xaConnection, CommitMode mode) throws SQLException, XAException {
log.info("Starting XA simple transaction test");
Connection connection = xaConnection.getConnection();
Xid xid = getRandomXid();
xaConnection.start(xid, XAResource.TMNOFLAGS);
String sql = "insert into test (id, uuid, active, amount, description, created_date, last_updated) values (?, ?, ?, ?, ?, ?, ?)";
PreparedStatement statement = connection.prepareStatement(sql);
setParameterValues(statement, 1000000);
statement.executeUpdate();
xaConnection.end(xid, XAResource.TMSUCCESS);
xaConnection.prepare(xid);
if (mode != CommitMode.None) {
xaConnection.commit(xid, mode == CommitMode.OnePhase);
}
if (mode != CommitMode.None) {
boolean found = false;
try (ResultSet rs = connection.createStatement().executeQuery("select * from test where id=1000000")) {
if (rs.next())
found = true;
}
Assert.assertTrue(found);
}
log.info("Finished XA simple transaction test");
}
use of nl.topicus.jdbc.xa.CloudSpannerXAConnection in project spanner-jdbc by olavloite.
the class XATester method testXA.
public void testXA(String projectId, String instanceId, String database, String pvtKeyPath) throws SQLException {
log.info("Starting XA tests");
int originalLogLevel = CloudSpannerDriver.getLogLevel();
CloudSpannerDriver.setLogLevel(CloudSpannerDriver.DEBUG);
CloudSpannerXADataSource ds = new CloudSpannerXADataSource();
ds.setProjectId(projectId);
ds.setInstanceId(instanceId);
ds.setDatabase(database);
ds.setPvtKeyPath(pvtKeyPath);
ds.setAllowExtendedMode(true);
try (CloudSpannerXAConnection xaConnection = ds.getXAConnection()) {
testXATransaction(xaConnection, CommitMode.TwoPhase);
testXARollback(xaConnection);
deleteTestRow(xaConnection);
testXARecover(xaConnection);
deleteTestRow(xaConnection);
} catch (Exception e) {
throw new CloudSpannerSQLException("Exception occurred during XA tests", Code.INTERNAL, e);
} finally {
CloudSpannerDriver.setLogLevel(originalLogLevel);
}
log.info("Finished XA tests");
}
use of nl.topicus.jdbc.xa.CloudSpannerXAConnection in project spanner-jdbc by olavloite.
the class XATester method prepareDeleteRow.
private Xid prepareDeleteRow(CloudSpannerXAConnection xaConnection) throws SQLException, XAException {
Connection connection = xaConnection.getConnection();
Xid xid = getRandomXid();
xaConnection.start(xid, XAResource.TMNOFLAGS);
String sql = "delete from test where id=1000000";
PreparedStatement statement = connection.prepareStatement(sql);
statement.executeUpdate();
xaConnection.end(xid, XAResource.TMSUCCESS);
xaConnection.prepare(xid);
return xid;
}
Aggregations