Package org.apache.derbyTesting.functionTests.tests.jdbcapi

Examples of org.apache.derbyTesting.functionTests.tests.jdbcapi.AssertEventCatcher


        // handled correctly
        // Some more isolation testing using SQL and JDBC api
        XADataSource dsx = J2EEDataSource.getXADataSource();
        JDBCDataSource.setBeanProperty(dsx, "DatabaseName", dbName);
        XAConnection xac = dsx.getXAConnection();
        AssertEventCatcher aes6 = new AssertEventCatcher(6);
        xac.addConnectionEventListener(aes6);
        XAResource xar = xac.getXAResource();
        Connection conn = xac.getConnection();
        Statement s = conn.createStatement();
        // initial local
        assertConnectionState(
            ResultSet.HOLD_CURSORS_OVER_COMMIT,
            Connection.TRANSACTION_READ_COMMITTED,
            true, false, conn);

        // Issue setTransactionIsolation in local transaction
        conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
        // setTransactionIsolation in local
        assertConnectionState(
            ResultSet.HOLD_CURSORS_OVER_COMMIT,
            Connection.TRANSACTION_READ_UNCOMMITTED,
            true, false, conn);

        Xid xid;
        //Issue SQL to change isolation in local transaction
        s.executeUpdate("set current isolation = RR");
        assertConnectionState(ResultSet.HOLD_CURSORS_OVER_COMMIT,
            Connection.TRANSACTION_SERIALIZABLE,
            true, false, conn);

        xid = new cdsXid(1, (byte) 35, (byte) 47);
        xar.start(xid, XAResource.TMNOFLAGS);
        // 1st global (new)
        assertConnectionState(ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_SERIALIZABLE,
            false, false, conn);
        xar.end(xid, XAResource.TMSUCCESS);

        // local
        assertConnectionState(ResultSet.HOLD_CURSORS_OVER_COMMIT,
            Connection.TRANSACTION_SERIALIZABLE,
            true, false, conn);
        //Issue SQL to change isolation in local transaction
        s.executeUpdate("set current isolation = RS");
        assertConnectionState(ResultSet.HOLD_CURSORS_OVER_COMMIT,
            Connection.TRANSACTION_REPEATABLE_READ,
            true, false, conn);

        // DERBY-1325 - Isolation level of local connection does not get reset after ending
        // a global transaction that was joined/resumed if the isolation level was changed
        // using SQL
        xar.start(xid, XAResource.TMJOIN);
        // 1st global(existing)
        assertConnectionState(ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_SERIALIZABLE,
            false, false, conn);
        xar.end(xid, XAResource.TMSUCCESS);
        // local
        assertConnectionState(ResultSet.HOLD_CURSORS_OVER_COMMIT,
            Connection.TRANSACTION_REPEATABLE_READ,
            true, false, conn);
        // DERBY-1325 end test

        Xid xid2 = new cdsXid(1, (byte) 93, (byte) 103);
        xar.start(xid2, XAResource.TMNOFLAGS);
        // 2nd global (new)
        assertConnectionState(ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_REPEATABLE_READ,
            false, false, conn);
        xar.end(xid2, XAResource.TMSUCCESS);

        xar.start(xid, XAResource.TMJOIN);
        // 1st global (existing)
        assertConnectionState(ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_SERIALIZABLE,
            false, false, conn);
        xar.end(xid, XAResource.TMSUCCESS);

        //local
        assertConnectionState(ResultSet.HOLD_CURSORS_OVER_COMMIT,
            Connection.TRANSACTION_REPEATABLE_READ,
            true, false, conn);

        xar.start(xid, XAResource.TMJOIN);
       
        // 1st global (existing)
        assertConnectionState(ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_SERIALIZABLE,
            false, false, conn);
        // Issue SQL to change isolation in 1st global transaction
        s.executeUpdate("set current isolation = UR");
        assertConnectionState(ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_READ_UNCOMMITTED,
            false, false, conn);
        xar.end(xid, XAResource.TMSUCCESS);

        // local
        assertConnectionState(ResultSet.HOLD_CURSORS_OVER_COMMIT,
            Connection.TRANSACTION_READ_UNCOMMITTED,
            true, false, conn);

        xar.start(xid2, XAResource.TMJOIN);
        // 2nd global (existing)
        assertConnectionState(ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_REPEATABLE_READ,
            false, false, conn);
        xar.end(xid2, XAResource.TMSUCCESS);
        xar.rollback(xid2);
        // (After 2nd global rollback ) local
        assertConnectionState(ResultSet.HOLD_CURSORS_OVER_COMMIT,
            Connection.TRANSACTION_READ_UNCOMMITTED,
            true, false, conn);

        xar.rollback(xid);
        // (After 1st global rollback) local
        assertConnectionState(ResultSet.HOLD_CURSORS_OVER_COMMIT,
            Connection.TRANSACTION_READ_UNCOMMITTED,
            true, false, conn);
        //Confirm - no connection closed event & connection error event
        assertFalse(aes6.didConnectionClosedEventHappen());
        assertFalse(aes6.didConnectionErrorEventHappen());
        aes6.resetState();
    }
View Full Code Here


            ResultSet.HOLD_CURSORS_OVER_COMMIT};

        XADataSource dsx = J2EEDataSource.getXADataSource();
        JDBCDataSource.setBeanProperty(dsx, "DatabaseName", dbName);
        XAConnection xac = dsx.getXAConnection();
        AssertEventCatcher aes6 = new AssertEventCatcher(6);
        xac.addConnectionEventListener(aes6);
        XAResource xar = xac.getXAResource();
        Xid xid = new cdsXid(1, (byte) 103, (byte) 119);

        // now check re-use of *Statement objects across local/global
        // connections.
        Connection cs1 = xac.getConnection();

        // ensure read locks stay around until end-of transaction
        cs1.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
        cs1.setAutoCommit(false);
        assertLocks(null, cs1);

        Statement sru1 = cs1.createStatement();
        sru1.setCursorName("SN1");
        sru1.executeUpdate("insert into intTable values 1,2,3");
        Statement sruBatch = cs1.createStatement();
        sruBatch.setCursorName("sruBatch");
        Statement sruState = createFloatStatementForStateChecking(
            StatementExpectedValues, cs1);
        PreparedStatement psruState = createFloatStatementForStateChecking(
            new int[] {1, 4}, PreparedStatementExpectedValues, cs1,
            "select i from intTable where i = ?");
        CallableStatement csruState = createFloatCallForStateChecking(
            new int[] {2, 12, 12}, CallableStatementExpectedValues, cs1,
            "CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?,?)");
        PreparedStatement psParams =
            cs1.prepareStatement("select * from intTable where i > ?");
        psParams.setCursorName("params");
        psParams.setInt(1, 2);
        // Params-local-1
        resultSetQuery("params", three, psParams.executeQuery());

        sruBatch.addBatch("insert into intTable values 4");
        // sru1-local-1
        queryOnStatement("SN1", onetwothree, cs1, sru1);
        cs1.commit(); // need to commit to switch to an global connection;

        // simple case - underlying connection is re-used for global.
        xar.start(xid, XAResource.TMNOFLAGS);
        // Expecting downgrade because global transaction sru1-global-2 is
        // using a statement with holdability true
        // sru1-global-2
        queryOnStatement("SN1", onetwothree, cs1, sru1);
        sruBatch.addBatch("insert into intTable values 5");
        Statement sru2 = cs1.createStatement();
        sru2.setCursorName("OAK2");
        //sru2-global-3
        queryOnStatement("OAK2", onetwothree, cs1, sru2);
        // Expecting downgrade because global transaction sru1-global-4 is
        // using a statement with holdability true
        // sru1-global-4
        queryOnStatement("SN1", onetwothree, cs1, sru1);
        // Global statement
        StatementExpectedValues[6] = ResultSet.CLOSE_CURSORS_AT_COMMIT;
        PreparedStatementExpectedValues[6] = ResultSet.CLOSE_CURSORS_AT_COMMIT;
        CallableStatementExpectedValues[6] = ResultSet.CLOSE_CURSORS_AT_COMMIT;
        assertStatementState(null, StatementExpectedValues ,sruState);
        // Global PreparedStatement
        assertStatementState(pspc, PreparedStatementExpectedValues, psruState);
        // Global CallableStatement
        assertStatementState(cspc, CallableStatementExpectedValues, csruState);
        // Params-global-1
        resultSetQuery("params", three, psParams.executeQuery());

        xar.end(xid, XAResource.TMSUCCESS);
        // now a new underlying connection is created
        // sru1-local-5
        queryOnStatement("SN1", onetwothree, cs1, sru1);
        // sru2-local-6
        queryOnStatement("OAK2", onetwothree, cs1, sru2);
        sruBatch.addBatch("insert into intTable values 6,7");
        Statement sru3 = cs1.createStatement();
        sru3.setCursorName("SF3");
        // sru3-local-7
        queryOnStatement("SF3", onetwothree, cs1, sru3);
        // Two transactions should hold locks (global and the current XA);
        // LOCAL
        StatementExpectedValues[6] = ResultSet.HOLD_CURSORS_OVER_COMMIT;
        PreparedStatementExpectedValues[6] = ResultSet.HOLD_CURSORS_OVER_COMMIT;
        CallableStatementExpectedValues[6] = ResultSet.HOLD_CURSORS_OVER_COMMIT;
        assertStatementState(null, StatementExpectedValues, sruState);
        assertStatementState(pspc, PreparedStatementExpectedValues, psruState);
        assertStatementState(cspc, CallableStatementExpectedValues, csruState);
        // Params-local-2
        resultSetQuery("params", three, psParams.executeQuery());
        assertLocks(new int[] {14,14}, cs1);
        cs1.commit();
        //Confirm - no connection closed event & connection error event
        assertFalse(aes6.didConnectionClosedEventHappen());
        assertFalse(aes6.didConnectionErrorEventHappen());
        aes6.resetState();

        // attach the XA transaction to another connection and see what happens
        XAConnection xac2 = dsx.getXAConnection();
        AssertEventCatcher aes5 = new AssertEventCatcher(5);
        xac2.addConnectionEventListener(aes5);
        XAResource xar2 = xac2.getXAResource();

        xar2.start(xid, XAResource.TMJOIN);
        Connection cs2 = xac2.getConnection();

        // these statements were generated by cs1 and thus are still
        // in a local connection.
        // sru1-local-8
        queryOnStatement("SN1", onetwothree, cs1, sru1);
        // sru2-local-9
        queryOnStatement("OAK2", onetwothree, cs1, sru2);
        // sru3-local-10
        queryOnStatement("SF3", onetwothree, cs1, sru3);
        sruBatch.addBatch("insert into intTable values 8");
        // LOCAL 2
        assertStatementState(null, StatementExpectedValues, sruState);
        assertStatementState(pspc, PreparedStatementExpectedValues, psruState);
        assertStatementState(cspc, CallableStatementExpectedValues, csruState);

        assertLocks(new int[] {14, 12}, cs1);

        int[] updateCounts = sruBatch.executeBatch();
        int[] expectedUpdateCounts = {1, 1, 2, 1};
        // sruBatch update counts:
        for (int i = 0; i < updateCounts.length; i++) {
            assertEquals(expectedUpdateCounts[i], updateCounts[i]);
        }
        // sruBatch
        queryOnStatement(
            "sruBatch", new int[] {1,2,3,4,5,6,7,8}, cs1, sruBatch);

        xar2.end(xid, XAResource.TMSUCCESS);
        //Confirm - no connection closed event & connection error event
        assertFalse(aes5.didConnectionClosedEventHappen());
        assertFalse(aes5.didConnectionErrorEventHappen());
        aes5.resetState();
        xac2.close();

        // allow close on already closed XAConnection
        xac2.close();
        xac2.addConnectionEventListener(null);
View Full Code Here

        if (usingEmbedded())
        {
            SecurityCheck.assertSourceSecurity(
                pc, "javax.sql.PooledConnection");
        }
        AssertEventCatcher aes1 = new AssertEventCatcher(1);
        pc.addConnectionEventListener(aes1);

        // DERBY-2531
        // with Network Server / DerbyNetClient, the assertConnectionOK check
        // returns a different connection object...
        assertConnectionOK(
            expectedValues, "ConnectionPoolDataSource", pc.getConnection());
        //Check if got connection closed event but not connection error event
        assertTrue(aes1.didConnectionClosedEventHappen());
        assertFalse(aes1.didConnectionErrorEventHappen());
        aes1.resetState();
        assertConnectionOK(
            expectedValues, "ConnectionPoolDataSource", pc.getConnection());
        //Check if got connection closed event but not connection error event
        assertTrue(aes1.didConnectionClosedEventHappen());
        assertFalse(aes1.didConnectionErrorEventHappen());
        aes1.resetState();

        XADataSource dsx = J2EEDataSource.getXADataSource();
        JDBCDataSource.setBeanProperty(dsx, "DatabaseName", dbName);
        if (usingEmbedded())
            assertToString(dsx);

        // shutdown db and check all's still ok thereafter
        TestConfiguration.getCurrent().shutdownDatabase();

        dmc = getConnection();
        cs = dmc.prepareCall("call checkConn2(?)");
        // checks currently only implemented for embedded
        if (usingEmbedded())
        {
            SecurityCheck.assertSourceSecurity(
                cs, "java.sql.CallableStatement");
        }
        cs.setString(1,"Nested");
        try {
            cs.execute();
        } catch (SQLException sqle) {
            assertSQLState("40XC0", sqle);
        }
        cs.setString(1, "Nested2");
        cs.execute();

        XAConnection xac = dsx.getXAConnection();
        // checks currently only implemented for embedded
        if (usingEmbedded())
        {
            SecurityCheck.assertSourceSecurity(xac, "javax.sql.XAConnection");
        }
        AssertEventCatcher aes3 = new AssertEventCatcher(3);
        xac.addConnectionEventListener(aes3);
        assertConnectionOK(
            expectedValues, "XADataSource", xac.getConnection());
        //Check if got connection closed event but not connection error event
        assertTrue(aes3.didConnectionClosedEventHappen());
        assertFalse(aes3.didConnectionErrorEventHappen());
        aes3.resetState();
                      
        pc = dsp.getPooledConnection();
        AssertEventCatcher aes2 = new AssertEventCatcher(2);
        pc.addConnectionEventListener(aes2);
        assertConnectionOK(
            expectedValues, "ConnectionPoolDataSource", pc.getConnection());
        //Check if got connection closed event but not connection error event
        assertTrue(aes2.didConnectionClosedEventHappen());
        assertFalse(aes2.didConnectionErrorEventHappen());
        aes2.resetState();

        // test "local" XAConnections
        xac = dsx.getXAConnection();
        AssertEventCatcher aes4 = new AssertEventCatcher(4);
        xac.addConnectionEventListener(aes4);
        assertConnectionOK(
            expectedValues, "XADataSource", xac.getConnection());
        //Check if got connection closed event but not connection error event
        assertTrue(aes4.didConnectionClosedEventHappen());
        assertFalse(aes4.didConnectionErrorEventHappen());
        aes4.resetState();
        assertConnectionOK(
            expectedValues, "XADataSource", xac.getConnection());
        //Check if got connection closed event but not connection error event
        assertTrue(aes4.didConnectionClosedEventHappen());
        assertFalse(aes4.didConnectionErrorEventHappen());
        aes4.resetState();
        xac.close();

        // test "global" XAConnections
        xac = dsx.getXAConnection();
        AssertEventCatcher aes5 = new AssertEventCatcher(5);
        xac.addConnectionEventListener(aes5);
        XAResource xar = xac.getXAResource();
        // checks currently only implemented for embedded
        if (usingEmbedded())
        {
           SecurityCheck.assertSourceSecurity(
                xar, "javax.transaction.xa.XAResource");
        }
        Xid xid = new cdsXid(1, (byte) 35, (byte) 47);
        xar.start(xid, XAResource.TMNOFLAGS);
        Connection xacc = xac.getConnection();
        xacc.close();
        expectedValues[0] = new Integer(ResultSet.CLOSE_CURSORS_AT_COMMIT);
        if (usingEmbedded())
            expectedValues[1] = "XJ058";
        expectedValues[3] = new Boolean(false);
        assertConnectionOK(
            expectedValues, "Global XADataSource", xac.getConnection());
        //Check if got connection closed event but not connection error event
        assertTrue(aes5.didConnectionClosedEventHappen());
        assertFalse(aes5.didConnectionErrorEventHappen());
        aes5.resetState();
        assertConnectionOK(
            expectedValues, "Global XADataSource", xac.getConnection());
        //Check if got connection closed event but not connection error event
        assertTrue(aes5.didConnectionClosedEventHappen());
        assertFalse(aes5.didConnectionErrorEventHappen());
        aes5.resetState();

        xar.end(xid, XAResource.TMSUCCESS);

        expectedValues[0] = new Integer(ResultSet.HOLD_CURSORS_OVER_COMMIT);
        expectedValues[3] = new Boolean(true);
        assertConnectionOK(expectedValues,
            "Switch to local XADataSource", xac.getConnection());
        //Check if got connection closed event but not connection error event
        assertTrue(aes5.didConnectionClosedEventHappen());
        assertFalse(aes5.didConnectionErrorEventHappen());
        aes5.resetState();
        assertConnectionOK(expectedValues,
            "Switch to local XADataSource", xac.getConnection());
        //Check if got connection closed event but not connection error event
        assertTrue(aes5.didConnectionClosedEventHappen());
        assertFalse(aes5.didConnectionErrorEventHappen());
        aes5.resetState();

        Connection backtoGlobal = xac.getConnection();

        xar.start(xid, XAResource.TMJOIN);
        expectedValues[0] = new Integer(ResultSet.CLOSE_CURSORS_AT_COMMIT);
        expectedValues[3] = new Boolean(false);
        assertConnectionOK(expectedValues,
            "Switch to global XADataSource", backtoGlobal);
        //Check if got connection closed event but not connection error event
        assertTrue(aes5.didConnectionClosedEventHappen());
        assertFalse(aes5.didConnectionErrorEventHappen());
        aes5.resetState();
        assertConnectionOK(expectedValues,
            "Switch to global XADataSource", xac.getConnection());
        //Check if got connection closed event but not connection error event
        assertTrue(aes5.didConnectionClosedEventHappen());
        assertFalse(aes5.didConnectionErrorEventHappen());
        aes5.resetState();
        xar.end(xid, XAResource.TMSUCCESS);
        xar.commit(xid, true);

        xac.close();
    }
View Full Code Here

        // some of this may be tested elsewhere too.

        XADataSource dsx = J2EEDataSource.getXADataSource();
        JDBCDataSource.setBeanProperty(dsx, "DatabaseName", dbName);
        XAConnection xac = dsx.getXAConnection();
        AssertEventCatcher aes6 = new AssertEventCatcher(6);
        xac.addConnectionEventListener(aes6);
        XAResource xar = xac.getXAResource();
        Xid xid = new cdsXid(1, (byte) 93, (byte) 103);

        // series 1 - Single connection object
        Connection cs1 = xac.getConnection();
        // initial local
        assertConnectionState(
            ResultSet.HOLD_CURSORS_OVER_COMMIT,
            Connection.TRANSACTION_READ_COMMITTED,
            true, false, cs1);
        xar.start(xid, XAResource.TMNOFLAGS);
        // initial X1
        assertConnectionState(
            ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_READ_COMMITTED,
            false, false, cs1);
        cs1.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
        cs1.setReadOnly(true);
        setHoldability(cs1, false); // close cursors
        // modified X1
        boolean ReadOnly = false;
        // see DERBY-911, ReadOnly state different for Embedded/DerbyNetClient
        if (usingEmbedded())
            ReadOnly = true;
        assertConnectionState(
            ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_READ_UNCOMMITTED,
            false, ReadOnly, cs1);
        xar.end(xid, XAResource.TMSUCCESS);
        // the underlying local transaction/connection must pick up the
        // state of the Connection handle cs1
        // modified local:
        assertConnectionState(
            ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_READ_UNCOMMITTED,
            true, ReadOnly, cs1);
       
        cs1.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
        cs1.setReadOnly(false);
        setHoldability(cs1, false); // close cursors

        // reset local
        assertConnectionState(
            ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_READ_COMMITTED,
            true, false, cs1);

        // now re-join the transaction, should pick up the read-only
        // and isolation level from the transaction,
        // holdability remains that of this handle.
        xar.start(xid, XAResource.TMJOIN);
        // re-join X1
        assertConnectionState(
            ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_READ_UNCOMMITTED,
            false, ReadOnly, cs1);
        xar.end(xid, XAResource.TMSUCCESS);

        // back to local - should be the same as the reset local
        assertConnectionState(
            ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_READ_COMMITTED,
            true, false, cs1);
       
        // test suspend/resume
        // now re-join the transaction (X1) for the second time, should pick
        // up the read-only and isolation level from the transaction,
        // holdability remains that of this handle.
        xar.start(xid, XAResource.TMJOIN);
        assertConnectionState(
            ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_READ_UNCOMMITTED,
            false, ReadOnly, cs1);
       
        xar.end(xid, XAResource.TMSUSPEND);
        // local after suspend
        assertConnectionState(
            ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_READ_COMMITTED,
            true, false, cs1);
       
        xar.start(xid, XAResource.TMRESUME);
        // resume X1
        assertConnectionState(
            ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_READ_UNCOMMITTED,
            false, ReadOnly, cs1);
       
        xar.end(xid, XAResource.TMSUCCESS);
        // back to local (second time)
        assertConnectionState(
            ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_READ_COMMITTED,
            true, false, cs1);
       
        cs1.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
        cs1.setReadOnly(true);
        setHoldability(cs1, true); // hold
        //Confirm - no connection closed event & connection error event
        assertFalse(aes6.didConnectionClosedEventHappen());
        assertFalse(aes6.didConnectionErrorEventHappen());
        aes6.resetState();
        cs1.close();
        //Check if got connection closed event but not connection error event
        assertTrue(aes6.didConnectionClosedEventHappen());
        assertFalse(aes6.didConnectionErrorEventHappen());
        aes6.resetState();
       
        cs1 = xac.getConnection();
        // new handle - local
        assertConnectionState(
            ResultSet.HOLD_CURSORS_OVER_COMMIT,
            Connection.TRANSACTION_READ_COMMITTED,
            true, false, cs1);
        cs1.close();
        //Check if got connection closed event but not connection error event
        assertTrue(aes6.didConnectionClosedEventHappen());
        assertFalse(aes6.didConnectionErrorEventHappen());
        aes6.resetState();
       
        xar.start(xid, XAResource.TMJOIN);
        cs1 = xac.getConnection();
        // re-join with new handle X1
        assertConnectionState(
            ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_READ_UNCOMMITTED,
            false, ReadOnly, cs1);
        cs1.close();
        xar.end(xid, XAResource.TMSUCCESS);
        //Check if got connection closed event but not connection error event
        assertTrue(aes6.didConnectionClosedEventHappen());
        assertFalse(aes6.didConnectionErrorEventHappen());
        aes6.resetState();

        // now get a connection (attached to a local)
        // attach to the global and commit it.
        // state should be that of the local after the commit.
        cs1 = xac.getConnection();
        cs1.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
        // pre-X1 commit - local
        assertConnectionState(
            ResultSet.HOLD_CURSORS_OVER_COMMIT,
            Connection.TRANSACTION_REPEATABLE_READ,
            true, false, cs1);
        xar.start(xid, XAResource.TMJOIN);
        // pre-X1 commit - X1
        assertConnectionState(
            ResultSet.CLOSE_CURSORS_AT_COMMIT,
            Connection.TRANSACTION_READ_UNCOMMITTED,
            false, ReadOnly, cs1);
        xar.end(xid, XAResource.TMSUCCESS);
        // post-X1 end - local
        assertConnectionState(
            ResultSet.HOLD_CURSORS_OVER_COMMIT,
            Connection.TRANSACTION_REPEATABLE_READ,
            true, false, cs1);
        xar.commit(xid, true);
        // post-X1 commit - local
        assertConnectionState(
            ResultSet.HOLD_CURSORS_OVER_COMMIT,
            Connection.TRANSACTION_REPEATABLE_READ,
            true, false, cs1);
        //Confirm - no connection closed event & connection error event
        assertFalse(aes6.didConnectionClosedEventHappen());
        assertFalse(aes6.didConnectionErrorEventHappen());
        aes6.resetState();
        cs1.close();
        //Check if got connection closed event but not connection error event
        assertTrue(aes6.didConnectionClosedEventHappen());
        assertFalse(aes6.didConnectionErrorEventHappen());
        aes6.resetState();
    }
View Full Code Here

    {
      Connection conn;
      ConnectionPoolDataSource ds;
      PooledConnection pc;
      Statement st;
        AssertEventCatcher aes12 = new AssertEventCatcher(12);
        //Get the correct ConnectionPoolDataSource object
        if (usingEmbedded())
        {
          ds = new EmbeddedConnectionPoolDataSource();
            ((EmbeddedConnectionPoolDataSource)ds).setDatabaseName(dbName);
        } else
        {
            ds = new ClientConnectionPoolDataSource();
            ((ClientConnectionPoolDataSource)ds).setDatabaseName(dbName);
        }
        pc = ds.getPooledConnection();
        //Add a connection event listener to ConnectionPoolDataSource
        pc.addConnectionEventListener(aes12);
        conn = pc.getConnection();
        st = conn.createStatement();
        //TAB1 does not exist and hence catch the expected exception
        try {
            st.executeUpdate("drop table TAB1");
        } catch (SQLException sqle) {
            assertSQLState("42Y55", sqle);
        }
        //No event should have been generated at this point
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        //Shutdown the Derby engine or Network Server depending on what
        //mode we are running in.
        if (usingEmbedded())
        {
          getTestConfiguration().shutdownDatabase();
        } else
        {
          stopNetworkServer();
        }
        //Now try to use various apis on the JDBC Connection object created
        //before shutdown and they all should generate connection error event.
        try {
            conn.prepareStatement("CREATE TABLE TAB1(COL1 INT NOT NULL)");
        } catch (SQLException e) {
            //The first call on JDBC Connection object after Network Server
            //shutdown will generate a communication error and that's why we
            //are checking for SQL State 08006 rather than No current connection
            //SQL State 08003. In embedded mode, we will get SQL State 08003
          //meaning No current connection
            if (usingEmbedded())
                assertSQLState("08003", e);
            else
                assertSQLState("08006", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.prepareStatement("CREATE TABLE TAB1(COL1 INT NOT NULL)", 1);
        } catch (SQLException e) {
            assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
          int[] columnIndexes = {1};
            conn.prepareStatement("CREATE TABLE TAB1(COL1 INT NOT NULL)",
                columnIndexes);
        } catch (SQLException e) {
            assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
          String[] columnNames = {"col1"};
            conn.prepareStatement("CREATE TABLE TAB1(COL1 INT NOT NULL)",
                columnNames);
        } catch (SQLException e) {
            assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.prepareStatement("CREATE TABLE TAB1(COL1 INT NOT NULL)",
                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.prepareStatement("CREATE TABLE TAB1(COL1 INT NOT NULL)",
                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
                ResultSet.CLOSE_CURSORS_AT_COMMIT);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.createStatement();
        } catch (SQLException e) {
            assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
                ResultSet.CONCUR_READ_ONLY,
                ResultSet.CLOSE_CURSORS_AT_COMMIT);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY);
        } catch (SQLException e) {
            assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.prepareCall("CREATE TABLE TAB1(COL1 INT NOT NULL)",
                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.prepareCall("CREATE TABLE TAB1(COL1 INT NOT NULL)");
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.prepareCall("CREATE TABLE TAB1(COL1 INT NOT NULL)",
                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
                ResultSet.CLOSE_CURSORS_AT_COMMIT);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.nativeSQL("CREATE TABLE TAB1(COL1 INT NOT NULL)");
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.getAutoCommit();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.setAutoCommit(false);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.getHoldability();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.setHoldability(1);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.commit();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.rollback();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.setSavepoint();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.setSavepoint("savept1");
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.rollback((Savepoint)null);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.releaseSavepoint((Savepoint)null);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.getTransactionIsolation();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.getWarnings();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.clearWarnings();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.getMetaData();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.isReadOnly();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.setReadOnly(true);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.setCatalog(null);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.getCatalog();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.getTypeMap();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        try {
            conn.setTypeMap(null);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        if (usingEmbedded())
        {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
        }else
        {
View Full Code Here

    {
      Connection conn;
      ConnectionPoolDataSource ds;
      PooledConnection pc;
      Statement st;
        AssertEventCatcher aes12 = new AssertEventCatcher(12);
        //Get the correct ConnectionPoolDataSource object
        if (usingEmbedded())
        {
          ds = new EmbeddedConnectionPoolDataSource();
            ((EmbeddedConnectionPoolDataSource)ds).setDatabaseName(dbName);
        } else
        {
            ds = new ClientConnectionPoolDataSource();
            ((ClientConnectionPoolDataSource)ds).setDatabaseName(dbName);
        }
        pc = ds.getPooledConnection();
        //Add a connection event listener to ConnectionPoolDataSource
        pc.addConnectionEventListener(aes12);
        conn = pc.getConnection();
        st = conn.createStatement();
        //TAB1 does not exist and hence catch the expected exception
        try {
            st.executeUpdate("drop table TAB1");
        } catch (SQLException sqle) {
            assertSQLState("42Y55", sqle);
        }
        //No event should have been generated at this point
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        //Shutdown the Derby engine or Network Server depending on what
        //mode we are running in.
        if (usingEmbedded())
        {
          getTestConfiguration().shutdownDatabase();
        } else
        {
          stopNetworkServer();
        }
        //Now try to use various apis on the JDBC Connection object created
        //before shutdown and they all should generate connection error event.
        try {
            conn.createArrayOf("junk", null);
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createNClob();
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createSQLXML();
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createStruct("junk", null);
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createBlob();
        } catch (SQLException e) {
            //The first call on JDBC Connection object after Network Server
            //shutdown will generate a communication error and that's why we
            //are checking for SQL State 08006 rather than No current connection
            //SQL State 08003. In embedded mode, we will get SQL State 08003
          //meaning No current connection
            if (usingEmbedded())
                assertSQLState("08003", e);
            else
                assertSQLState("08006", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.createClob();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.getClientInfo();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.getClientInfo("junk");
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.setClientInfo(null);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.setClientInfo("junk1", "junk2");
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.isWrapperFor(this.getClass());
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        if (usingEmbedded())
          assertTrue(aes12.didConnectionErrorEventHappen());
        else
          //We do not make any call on underneath JDBC Connection
          //object for isWrapperFor and hence never get Connection
          //Error event
          assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.unwrap(this.getClass());
        } catch (SQLException e) {
            if (usingEmbedded())
                assertSQLState("08003", e);
            else
              //We do not make any call on underneath JDBC Connection
              //object for unwrap and hence never get Connection
              //closed exception. Instead we got exception because
              //client driver code is trying to unwrap this.getClass
              //and it can't do that
                assertSQLState("XJ128", e);
        }
      assertFalse(aes12.didConnectionClosedEventHappen());
        if (usingEmbedded())
          assertTrue(aes12.didConnectionErrorEventHappen());
        else
          //We do not make any call on underneath JDBC Connection
          //object for isWrapperFor and hence never get Connection
          //Error event
          assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.isValid(5);
        } catch (SQLException e) {
            assertSQLState("08003", e);
        }
        if (usingEmbedded())
          assertTrue(aes12.didConnectionClosedEventHappen());
        else
          assertFalse(aes12.didConnectionClosedEventHappen());
      //As per the JDBC definition, an exception and hence an event is raised
      //for isValid only if the param value is illegal
      assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        if (usingEmbedded())
        {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
        }else
        {
View Full Code Here

     * When the Derby engine is shutdown or Network Server is brought down, any
     * api on JDBC Connection object should generate a Connection error event.
     */
    public void testConnectionErrorEvent() throws SQLException, Exception
    {
        AssertEventCatcher aes12 = new AssertEventCatcher(12);
        //Get the correct ConnectionPoolDataSource object
        ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();

        PooledConnection pc = ds.getPooledConnection();
        //Add a connection event listener to ConnectionPoolDataSource
        pc.addConnectionEventListener(aes12);
        Connection conn = pc.getConnection();
       
        dropTable(conn, "TAB1");

        //No event should have been generated at this point
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        //Shutdown the Derby engine or Network Server depending on what
        //mode we are running in.
        if (usingEmbedded())
        {
          getTestConfiguration().shutdownDatabase();
        } else
        {
          getTestConfiguration().stopNetworkServer();
        }
        //Now try to use various apis on the JDBC Connection object created
        //before shutdown and they all should generate connection error event.
        try {
            conn.createArrayOf("junk", null);
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createNClob();
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createSQLXML();
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createStruct("junk", null);
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createBlob();
        } catch (SQLException e) {
            //The first call on JDBC Connection object after Network Server
            //shutdown will generate a communication error and that's why we
            //are checking for SQL State 08006 rather than No current connection
            //SQL State 08003. In embedded mode, we will get SQL State 08003
          //meaning No current connection
            if (usingEmbedded())
                assertSQLState("08003", e);
            else
                assertSQLState("08006", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.createClob();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.getClientInfo();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.getClientInfo("junk");
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.setClientInfo(null);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.setClientInfo("junk1", "junk2");
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.isWrapperFor(this.getClass());
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        if (usingEmbedded())
          assertTrue(aes12.didConnectionErrorEventHappen());
        else
          //We do not make any call on underneath JDBC Connection
          //object for isWrapperFor and hence never get Connection
          //Error event
          assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.unwrap(this.getClass());
        } catch (SQLException e) {
            if (usingEmbedded())
                assertSQLState("08003", e);
            else
              //We do not make any call on underneath JDBC Connection
              //object for unwrap and hence never get Connection
              //closed exception. Instead we got exception because
              //client driver code is trying to unwrap this.getClass
              //and it can't do that
                assertSQLState("XJ128", e);
        }
      assertFalse(aes12.didConnectionClosedEventHappen());
        if (usingEmbedded())
          assertTrue(aes12.didConnectionErrorEventHappen());
        else
          //We do not make any call on underneath JDBC Connection
          //object for isWrapperFor and hence never get Connection
          //Error event
          assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.isValid(5);
        } catch (SQLException e) {
            assertSQLState("08003", e);
        }
        if (usingEmbedded())
          assertTrue(aes12.didConnectionClosedEventHappen());
        else
          assertFalse(aes12.didConnectionClosedEventHappen());
      //As per the JDBC definition, an exception and hence an event is raised
      //for isValid only if the param value is illegal
      assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        if (usingEmbedded())
        {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
        }else
        {
View Full Code Here

     * When the Derby engine is shutdown or Network Server is brought down, any
     * api on JDBC Connection object should generate a Connection error event.
     */
    public void testConnectionErrorEvent() throws SQLException, Exception
    {
        AssertEventCatcher aes12 = new AssertEventCatcher(12);
        //Get the correct ConnectionPoolDataSource object
        ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();

        PooledConnection pc = ds.getPooledConnection();
        //Add a connection event listener to ConnectionPoolDataSource
        pc.addConnectionEventListener(aes12);
        Connection conn = pc.getConnection();
       
        dropTable(conn, "TAB1");

        //No event should have been generated at this point
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        //Shutdown the Derby engine or Network Server depending on what
        //mode we are running in.
        if (usingEmbedded())
        {
          getTestConfiguration().shutdownDatabase();
        } else
        {
          getTestConfiguration().stopNetworkServer();
        }
        //Now try to use various apis on the JDBC Connection object created
        //before shutdown and they all should generate connection error event.
        try {
            conn.createArrayOf("junk", null);
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createNClob();
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createSQLXML();
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createStruct("junk", null);
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createBlob();
        } catch (SQLException e) {
            //The first call on JDBC Connection object after Network Server
            //shutdown will generate a communication error and that's why we
            //are checking for SQL State 08006 rather than No current connection
            //SQL State 08003. In embedded mode, we will get SQL State 08003
          //meaning No current connection
            if (usingEmbedded())
                assertSQLState("08003", e);
            else
                assertSQLState("08006", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.createClob();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.getClientInfo();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.getClientInfo("junk");
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.setClientInfo(null);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.setClientInfo("junk1", "junk2");
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.isWrapperFor(this.getClass());
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        if (usingEmbedded())
          assertTrue(aes12.didConnectionErrorEventHappen());
        else
          //We do not make any call on underneath JDBC Connection
          //object for isWrapperFor and hence never get Connection
          //Error event
          assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.unwrap(this.getClass());
        } catch (SQLException e) {
            if (usingEmbedded())
                assertSQLState("08003", e);
            else
              //We do not make any call on underneath JDBC Connection
              //object for unwrap and hence never get Connection
              //closed exception. Instead we got exception because
              //client driver code is trying to unwrap this.getClass
              //and it can't do that
                assertSQLState("XJ128", e);
        }
      assertFalse(aes12.didConnectionClosedEventHappen());
        if (usingEmbedded())
          assertTrue(aes12.didConnectionErrorEventHappen());
        else
          //We do not make any call on underneath JDBC Connection
          //object for isWrapperFor and hence never get Connection
          //Error event
          assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.isValid(5);
        } catch (SQLException e) {
            assertSQLState("08003", e);
        }
        if (usingEmbedded())
          assertTrue(aes12.didConnectionClosedEventHappen());
        else
          assertFalse(aes12.didConnectionClosedEventHappen());
      //As per the JDBC definition, an exception and hence an event is raised
      //for isValid only if the param value is illegal
      assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        if (usingEmbedded())
        {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
        }else
        {
View Full Code Here

     * When the Derby engine is shutdown or Network Server is brought down, any
     * api on JDBC Connection object should generate a Connection error event.
     */
    public void testConnectionErrorEvent() throws SQLException, Exception
    {
        AssertEventCatcher aes12 = new AssertEventCatcher(12);
        //Get the correct ConnectionPoolDataSource object
        ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();

        PooledConnection pc = ds.getPooledConnection();
        //Add a connection event listener to ConnectionPoolDataSource
        pc.addConnectionEventListener(aes12);
        Connection conn = pc.getConnection();
       
        dropTable(conn, "TAB1");

        //No event should have been generated at this point
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        //Shutdown the Derby engine or Network Server depending on what
        //mode we are running in.
        if (usingEmbedded())
        {
          getTestConfiguration().shutdownDatabase();
        } else
        {
          getTestConfiguration().stopNetworkServer();
        }
        //Now try to use various apis on the JDBC Connection object created
        //before shutdown and they all should generate connection error event.
        try {
            conn.createArrayOf("junk", null);
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createNClob();
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createSQLXML();
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createStruct("junk", null);
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createBlob();
        } catch (SQLException e) {
            //The first call on JDBC Connection object after Network Server
            //shutdown will generate a communication error and that's why we
            //are checking for SQL State 08006 rather than No current connection
            //SQL State 08003. In embedded mode, we will get SQL State 08003
          //meaning No current connection
            if (usingEmbedded())
                assertSQLState("08003", e);
            else
                assertSQLState("08006", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.createClob();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.getClientInfo();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.getClientInfo("junk");
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.setClientInfo(null);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.setClientInfo("junk1", "junk2");
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.isWrapperFor(this.getClass());
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        if (usingEmbedded())
          assertTrue(aes12.didConnectionErrorEventHappen());
        else
          //We do not make any call on underneath JDBC Connection
          //object for isWrapperFor and hence never get Connection
          //Error event
          assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.unwrap(this.getClass());
        } catch (SQLException e) {
            if (usingEmbedded())
                assertSQLState("08003", e);
            else
              //We do not make any call on underneath JDBC Connection
              //object for unwrap and hence never get Connection
              //closed exception. Instead we got exception because
              //client driver code is trying to unwrap this.getClass
              //and it can't do that
                assertSQLState("XJ128", e);
        }
      assertFalse(aes12.didConnectionClosedEventHappen());
        if (usingEmbedded())
          assertTrue(aes12.didConnectionErrorEventHappen());
        else
          //We do not make any call on underneath JDBC Connection
          //object for isWrapperFor and hence never get Connection
          //Error event
          assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.isValid(5);
        } catch (SQLException e) {
            assertSQLState("08003", e);
        }
        if (usingEmbedded())
          assertTrue(aes12.didConnectionClosedEventHappen());
        else
          assertFalse(aes12.didConnectionClosedEventHappen());
      //As per the JDBC definition, an exception and hence an event is raised
      //for isValid only if the param value is illegal
      assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        if (usingEmbedded())
        {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
        }else
        {
View Full Code Here

     * When the Derby engine is shutdown or Network Server is brought down, any
     * api on JDBC Connection object should generate a Connection error event.
     */
    public void testConnectionErrorEvent() throws SQLException, Exception
    {
        AssertEventCatcher aes12 = new AssertEventCatcher(12);
        //Get the correct ConnectionPoolDataSource object
        ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();

        PooledConnection pc = ds.getPooledConnection();
        //Add a connection event listener to ConnectionPoolDataSource
        pc.addConnectionEventListener(aes12);
        Connection conn = pc.getConnection();
       
        dropTable(conn, "TAB1");

        //No event should have been generated at this point
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        //Shutdown the Derby engine or Network Server depending on what
        //mode we are running in.
        if (usingEmbedded())
        {
          getTestConfiguration().shutdownDatabase();
        } else
        {
          getTestConfiguration().stopNetworkServer();
        }
        //Now try to use various apis on the JDBC Connection object created
        //before shutdown and they all should generate connection error event.
        try {
            conn.createArrayOf("junk", null);
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createNClob();
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createSQLXML();
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createStruct("junk", null);
        } catch (SQLException e) {
            assertSQLState("0A000", e);
        }
        try {
            conn.createBlob();
        } catch (SQLException e) {
            //The first call on JDBC Connection object after Network Server
            //shutdown will generate a communication error and that's why we
            //are checking for SQL State 08006 rather than No current connection
            //SQL State 08003. In embedded mode, we will get SQL State 08003
          //meaning No current connection
            if (usingEmbedded())
                assertSQLState("08003", e);
            else
                assertSQLState("08006", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.createClob();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.getClientInfo();
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.getClientInfo("junk");
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.setClientInfo(null);
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.setClientInfo("junk1", "junk2");
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertTrue(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.isWrapperFor(this.getClass());
        } catch (SQLException e) {
                assertSQLState("08003", e);
        }
        assertFalse(aes12.didConnectionClosedEventHappen());
        if (usingEmbedded())
          assertTrue(aes12.didConnectionErrorEventHappen());
        else
          //We do not make any call on underneath JDBC Connection
          //object for isWrapperFor and hence never get Connection
          //Error event
          assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.unwrap(this.getClass());
        } catch (SQLException e) {
            if (usingEmbedded())
                assertSQLState("08003", e);
            else
              //We do not make any call on underneath JDBC Connection
              //object for unwrap and hence never get Connection
              //closed exception. Instead we got exception because
              //client driver code is trying to unwrap this.getClass
              //and it can't do that
                assertSQLState("XJ128", e);
        }
      assertFalse(aes12.didConnectionClosedEventHappen());
        if (usingEmbedded())
          assertTrue(aes12.didConnectionErrorEventHappen());
        else
          //We do not make any call on underneath JDBC Connection
          //object for isWrapperFor and hence never get Connection
          //Error event
          assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        try {
            conn.isValid(5);
        } catch (SQLException e) {
            assertSQLState("08003", e);
        }
        if (usingEmbedded())
          assertTrue(aes12.didConnectionClosedEventHappen());
        else
          assertFalse(aes12.didConnectionClosedEventHappen());
      //As per the JDBC definition, an exception and hence an event is raised
      //for isValid only if the param value is illegal
      assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();         
        if (usingEmbedded())
        {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
        }else
        {
View Full Code Here

TOP

Related Classes of org.apache.derbyTesting.functionTests.tests.jdbcapi.AssertEventCatcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.