Search in sources :

Example 81 with XAConnection

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();
}
Also used : XADataSource(javax.sql.XADataSource) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PooledConnection(javax.sql.PooledConnection) XAConnection(javax.sql.XAConnection)

Example 82 with XAConnection

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();
}
Also used : XADataSource(javax.sql.XADataSource) XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PooledConnection(javax.sql.PooledConnection) XAConnection(javax.sql.XAConnection)

Example 83 with XAConnection

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();
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) PooledConnection(javax.sql.PooledConnection) XADataSource(javax.sql.XADataSource) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PooledConnection(javax.sql.PooledConnection) XAConnection(javax.sql.XAConnection) XADataSource(javax.sql.XADataSource) J2EEDataSource(org.apache.derbyTesting.junit.J2EEDataSource) DataSource(javax.sql.DataSource) ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) JDBCDataSource(org.apache.derbyTesting.junit.JDBCDataSource)

Example 84 with XAConnection

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();
}
Also used : XADataSource(javax.sql.XADataSource) Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PooledConnection(javax.sql.PooledConnection) ResultSet(java.sql.ResultSet) XAConnection(javax.sql.XAConnection)

Example 85 with XAConnection

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();
}
Also used : XADataSource(javax.sql.XADataSource) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PooledConnection(javax.sql.PooledConnection) XAConnection(javax.sql.XAConnection)

Aggregations

XAConnection (javax.sql.XAConnection)115 Connection (java.sql.Connection)78 XAResource (javax.transaction.xa.XAResource)56 XADataSource (javax.sql.XADataSource)52 Xid (javax.transaction.xa.Xid)44 Statement (java.sql.Statement)34 SQLException (java.sql.SQLException)30 PreparedStatement (java.sql.PreparedStatement)23 PooledConnection (javax.sql.PooledConnection)23 ResultSet (java.sql.ResultSet)22 CallableStatement (java.sql.CallableStatement)18 Test (org.junit.Test)18 XAException (javax.transaction.xa.XAException)16 Transaction (javax.transaction.Transaction)8 DataSource (javax.sql.DataSource)7 XidImpl (org.firebirdsql.jca.TestXABase.XidImpl)7 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)7 NotSupportedException (javax.transaction.NotSupportedException)5 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)4 J2EEDataSource (org.apache.derbyTesting.junit.J2EEDataSource)4