use of javax.sql.XAConnection in project jaybird by FirebirdSQL.
the class TestFBXADataSource method testConnection.
/**
* Tests if the connection obtained from the PooledConnection can be used
* and has expected defaults.
*/
@Test
public void testConnection() throws SQLException {
XAConnection pc = getXAConnection();
Connection con = pc.getConnection();
assertTrue("Autocommit should be true", con.getAutoCommit());
assertTrue("Read-only should be false", !con.isReadOnly());
assertEquals("Tx isolation level should be read committed.", Connection.TRANSACTION_READ_COMMITTED, con.getTransactionIsolation());
try (Statement stmt = con.createStatement()) {
ResultSet rs = stmt.executeQuery("SELECT cast(1 AS INTEGER) FROM rdb$database");
assertTrue("Should select one row", rs.next());
assertEquals("Selected value should be 1.", 1, rs.getInt(1));
}
con.close();
assertTrue("Connection should report as being closed.", con.isClosed());
}
use of javax.sql.XAConnection in project jaybird by FirebirdSQL.
the class TestFBXADataSource method testInDistributed_setAutoCommit_true_notInAutoCommit.
/**
* Tests if setting autoCommit(true) when autoCommit is false throws an exception when participating in a distributed transaction (JDBC 4.0 section 12.4).
*/
@Test
public void testInDistributed_setAutoCommit_true_notInAutoCommit() throws Exception {
XAConnection pc = getXAConnection();
XAResource xa = pc.getXAResource();
Xid xid = new XidImpl();
try (Connection con = pc.getConnection()) {
con.setAutoCommit(false);
xa.start(xid, XAResource.TMNOFLAGS);
expectedException.expect(SQLException.class);
expectedException.expect(sqlStateEquals(SQLStateConstants.SQL_STATE_INVALID_TX_STATE));
con.setAutoCommit(true);
} finally {
xa.end(xid, XAResource.TMSUCCESS);
xa.rollback(xid);
}
}
use of javax.sql.XAConnection in project jaybird by FirebirdSQL.
the class TestFBXADataSource method getXAConnection.
protected XAConnection getXAConnection() throws SQLException {
XAConnection pc = ds.getXAConnection();
connections.add(pc);
return pc;
}
use of javax.sql.XAConnection in project jaybird by FirebirdSQL.
the class TestFBXADataSource method testInDistributed_rollback.
/**
* Test if calling rollback throws an exception when participating in a distributed transaction (JDBC 4.0 section 12.4).
*/
@Test
public void testInDistributed_rollback() throws Exception {
XAConnection pc = getXAConnection();
XAResource xa = pc.getXAResource();
Xid xid = new XidImpl();
try (Connection con = pc.getConnection()) {
con.setAutoCommit(false);
xa.start(xid, XAResource.TMNOFLAGS);
expectedException.expect(SQLException.class);
expectedException.expect(sqlStateEquals(SQLStateConstants.SQL_STATE_INVALID_TX_STATE));
con.rollback();
} finally {
xa.end(xid, XAResource.TMSUCCESS);
xa.rollback(xid);
}
}
use of javax.sql.XAConnection in project jaybird by FirebirdSQL.
the class TestFBXADataSource method testInDistributed_setSavepoint_named.
/**
* Test if calling setSavePoint (named) throws an exception when participating in a distributed transaction (JDBC 4.0 section 12.4).
*/
@Test
public void testInDistributed_setSavepoint_named() throws Exception {
XAConnection pc = getXAConnection();
XAResource xa = pc.getXAResource();
Xid xid = new XidImpl();
try (Connection con = pc.getConnection()) {
con.setAutoCommit(false);
xa.start(xid, XAResource.TMNOFLAGS);
expectedException.expect(SQLException.class);
expectedException.expect(sqlStateEquals(SQLStateConstants.SQL_STATE_INVALID_TX_STATE));
con.setSavepoint("test_sp");
} finally {
xa.end(xid, XAResource.TMSUCCESS);
xa.rollback(xid);
}
}
Aggregations