use of javax.sql.XAConnection in project derby by apache.
the class cdsXid method testCloseActiveConnection_XA_local.
/**
* Test that connections retrieved from {@code XADataSource} that are not
* part of a global XA transaction, behave as expected when {@code close()}
* is called and the transaction is active.
*/
public void testCloseActiveConnection_XA_local() throws SQLException {
XADataSource ds = J2EEDataSource.getXADataSource();
XAConnection xa = ds.getXAConnection();
testCloseActiveConnection(xa.getConnection(), true, false);
Connection c = xa.getConnection();
c.setAutoCommit(false);
testCloseActiveConnection(c, false, false);
xa.close();
}
use of javax.sql.XAConnection in project derby by apache.
the class cdsXid method testCloseActiveConnection_XA_global.
/**
* Test that connections retrieved from {@code XADataSource} that are part
* of a global XA transaction, behave as expected when {@code close()} is
* called and the transaction is active.
*/
public void testCloseActiveConnection_XA_global() throws SQLException, XAException {
XADataSource ds = J2EEDataSource.getXADataSource();
XAConnection xa = ds.getXAConnection();
XAResource xar = xa.getXAResource();
Xid xid = new cdsXid(1, (byte) 2, (byte) 3);
xar.start(xid, XAResource.TMNOFLAGS);
// auto-commit is always off in XA transactions, so we expect
// getAutoCommit() to return false without having set it explicitly
testCloseActiveConnection(xa.getConnection(), false, true);
Connection c = xa.getConnection();
c.setAutoCommit(false);
testCloseActiveConnection(c, false, true);
xar.end(xid, XAResource.TMSUCCESS);
xa.close();
}
use of javax.sql.XAConnection in project derby by apache.
the class cdsXid method testConnectionFlowCommit.
/**
* check whether commit without statement will flow by checking its transaction id
* on client. This test is run only for client where commits without an
* active transactions will not flow to the server.
* DERBY-4653
*
* @throws SQLException
*/
public void testConnectionFlowCommit() throws SQLException {
ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();
PooledConnection pc = ds.getPooledConnection();
Connection conn = pc.getConnection();
testConnectionFlowCommitWork(conn);
conn.close();
// Test for XADataSource
XADataSource xs = J2EEDataSource.getXADataSource();
XAConnection xc = xs.getXAConnection();
conn = xc.getConnection();
testConnectionFlowCommitWork(conn);
conn.close();
// Test for DataSource
DataSource jds = JDBCDataSource.getDataSource();
conn = jds.getConnection();
testConnectionFlowCommitWork(conn);
conn.close();
}
use of javax.sql.XAConnection in project derby by apache.
the class cdsXid method testAutoCommitOnXAResourceStart.
// test that an xastart in auto commit mode commits the existing work.
// test fix of a bug ('beetle 5178') wherein XAresource.start() when
// auto-commit is true did not implictly commit any transaction
// Also tests DERBY-1025, same description, but for client.
public void testAutoCommitOnXAResourceStart() throws SQLException, XAException {
XADataSource dsx = J2EEDataSource.getXADataSource();
XAConnection xac4 = dsx.getXAConnection();
Xid xid4a = null;
// this wasn't needed, so just create a different id for client
if (usingEmbedded())
xid4a = new cdsXid(4, (byte) 23, (byte) 76);
else if (usingDerbyNetClient())
xid4a = new cdsXid(5, (byte) 23, (byte) 76);
Connection conn4 = xac4.getConnection();
assertTrue(conn4.getAutoCommit());
Statement s4 = conn4.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);
ResultSet rs4 = s4.executeQuery("select i from autocommitxastart");
rs4.next();
assertEquals(1, rs4.getInt(1));
rs4.next();
assertEquals(2, rs4.getInt(1));
// XAResource().start should commit the transaction
xac4.getXAResource().start(xid4a, XAResource.TMNOFLAGS);
xac4.getXAResource().end(xid4a, XAResource.TMSUCCESS);
try {
rs4.next();
fail("expected an exception indicating resultset is closed.");
} catch (SQLException sqle) {
// Embedded gets 08003. No current connection (DERBY-2620)
if (usingDerbyNetClient())
assertSQLState("XCL16", sqle);
}
conn4.setAutoCommit(false);
assertFalse(conn4.getAutoCommit());
rs4 = s4.executeQuery("select i from autocommitxastart");
rs4.next();
assertEquals(1, rs4.getInt(1));
rs4.next();
assertEquals(2, rs4.getInt(1));
// Get a new xid to begin another transaction.
if (usingEmbedded())
xid4a = new cdsXid(4, (byte) 93, (byte) 103);
else if (usingDerbyNetClient())
xid4a = new cdsXid(5, (byte) 93, (byte) 103);
try {
xac4.getXAResource().start(xid4a, XAResource.TMNOFLAGS);
} catch (XAException xae) {
if (usingEmbedded())
assertNull(xae.getMessage());
else if (usingDerbyNetClient()) {
// This should give XAER_OUTSIDE exception because
// the resource manager is busy in the local transaction
assertTrue(xae.getMessage().indexOf("XAER_OUTSIDE") >= 0);
}
assertEquals(-9, xae.errorCode);
}
rs4.next();
assertEquals(3, rs4.getInt(1));
rs4.close();
conn4.rollback();
conn4.close();
xac4.close();
}
use of javax.sql.XAConnection in project derby by apache.
the class DataSourcePropertiesTest method embeddedTestAttributesAsPasswordWithoutPassword_xa.
/**
* Tests that the default password is not sent as an attribute string when
* <code>attributesAsPassword</code> is <code>true</code>. The test is run
* with an <code>XADataSource</code>.
*/
public void embeddedTestAttributesAsPasswordWithoutPassword_xa() throws Exception {
XADataSource ds = J2EEDataSource.getXADataSource();
JDBCDataSource.setBeanProperty(ds, "password", "mypassword");
JDBCDataSource.setBeanProperty(ds, "attributesAsPassword", Boolean.TRUE);
XAConnection xa = ds.getXAConnection();
Connection c = xa.getConnection();
c.close();
}
Aggregations