Package javax.sql

Examples of javax.sql.PooledConnection


         * @param event an event object describing the source of
         * the event and containing the <code>SQLException</code> that the
         * driver is about to throw
         */
        public void connectionErrorOccurred(ConnectionEvent event) {
            PooledConnection pconn = (PooledConnection)event.getSource();
            pconn.removeConnectionEventListener(this);
            ConnectionInfo cinfo = connMap.get(pconn);
            if (cinfo == null) {
                throw new IllegalStateException(
                "connectionErrorOccurred: No mapping for PooledConnection 0x"+
                 pconn.hashCode()+"["+pconn.getClass().getName()+"]");
            }
            SQLException ex = event.getSQLException();
            logger.log(logger.WARNING,
                       br.getKString(br.W_DB_CONN_ERROR_EVENT,
                       ""+cinfo, ""+ex)+toString());
View Full Code Here


    {
        AssertEventCatcher aes12 = new AssertEventCatcher(12);
       
        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());
View Full Code Here

     * active.
     */
    public void testCloseActiveConnection_CP() throws SQLException {
        ConnectionPoolDataSource ds =
            J2EEDataSource.getConnectionPoolDataSource();
        PooledConnection pc = ds.getPooledConnection();
        testCloseActiveConnection(pc.getConnection(), true, false);
        Connection c = pc.getConnection();
        c.setAutoCommit(false);
        testCloseActiveConnection(c, false, false);
        pc.close();
    }
View Full Code Here

        /**
         * Mimic a pool handler that returns the PooledConnection
         * to the pool and then reallocates it to a new logical connection.
         */
      public void connectionClosed(ConnectionEvent event) {
        PooledConnection pce = (PooledConnection) event.getSource();
        assertSame(pc, pce);
        try {
          // open a new logical connection and pass
          // back to the fixture.
          newConn[0] = pce.getConnection();
        } catch (SQLException e) {
                    // Need to catch the exception here because
                    // we cannot throw a checked exception through
                    // the api method. Wrap it in a RuntimeException.
                    throw new RuntimeException(e);
View Full Code Here

            /**
             * Mimic a pool handler that closes the PooledConnection
             * (say it no longer needs it, pool size being reduced)
             */
            public void connectionClosed(ConnectionEvent event) {
                PooledConnection pce = (PooledConnection) event.getSource();
                assertSame(pc, pce);
                try {
                    pce.close();
                } catch (SQLException e) {
                    // Need to catch the exception here because
                    // we cannot throw a checked exception through
                    // the api method. Wrap it in a RuntimeException.
                    throw new RuntimeException(e);
View Full Code Here

            /**
             * Mimic a pool handler that removes the listener during
             * a logical close.
             */
            public void connectionClosed(ConnectionEvent event) {
                PooledConnection pce = (PooledConnection) event.getSource();
                assertSame(pc, pce);
                count1[0]++;
                pce.removeConnectionEventListener(this);
            }

            public void connectionErrorOccurred(ConnectionEvent event) {
            }
           
        });
       
        // and have another listener to ensure removing one leaves
        // the other working and intact.
        final int[] count2 = new int[1];
        pc.addConnectionEventListener(new ConnectionEventListener() {

            /**
             * Mimic a pool handler that closes the PooledConnection
             * (say it no longer needs it, pool size being reduced)
             */
            public void connectionClosed(ConnectionEvent event) {            
                PooledConnection pce = (PooledConnection) event.getSource();
                assertSame(pc, pce);
                count2[0]++;
            }

            public void connectionErrorOccurred(ConnectionEvent event) {
View Full Code Here

            J2EEDataSource.getConnectionPoolDataSource();     
       
        if (usingEmbedded())
            assertToString(dsp);

        PooledConnection pc = dsp.getPooledConnection();
        // checks currently only implemented for embedded
        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();

        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();
            fail("SQLException of 40XC0 should be thrown!");
        } 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();
View Full Code Here

    public void testClosedCPDSConnection() throws SQLException, Exception {
        // verify that outstanding updates from a closed connection, obtained
        // from a ConnectionPoolDataSource, are not committed, but rolled back.
        ConnectionPoolDataSource dsp =
            J2EEDataSource.getConnectionPoolDataSource();      
        PooledConnection pc = dsp.getPooledConnection();
        Connection c1 = pc.getConnection();
        Statement s = c1.createStatement();
        // start by deleting all rows from intTable
        s.executeUpdate("delete from intTable");
        c1.setAutoCommit(false);

        // this update should get rolled back later
        s.executeUpdate("insert into intTable values(1)");
        // this should automatically close the original connection
        c1 = pc.getConnection();

        ResultSet rs =
            c1.createStatement().executeQuery("select count(*) from intTable");
        rs.next();
        assertEquals(0, rs.getInt(1));
        c1.close();
       
        // check connection objects are closed once connection is closed
        try {
            rs.next();
            fail("ResultSet is open for a closed connection obtained from PooledConnection");
        } catch (SQLException sqle) {
            // 08003 - No current connection; XCL16 - ResultSet not open
            if (usingEmbedded())
                assertSQLState("08003", sqle);
            else if (usingDerbyNetClient())
                assertSQLState("XCL16", sqle);
        }

        try {
            s.executeUpdate("update intTable set i = 1");
            fail("Statement is open for a closed connection " +
                "obtained from PooledConnection");
        } catch (SQLException sqle) {
            assertSQLState("08003", sqle);
        }

        pc.close();
        pc = null;
        PoolReset("ConnectionPoolDataSource", dsp.getPooledConnection());
        s.close();
        rs.close();
        c1.close();
View Full Code Here

            throws SQLException {
        final String userSchema = "AUSER";
        ConnectionPoolDataSource cpDs =
                J2EEDataSource.getConnectionPoolDataSource();
        J2EEDataSource.setBeanProperty(cpDs, "createDatabase", "create");
        PooledConnection pc = cpDs.getPooledConnection(userSchema, "secret");
        // Get first connection, create a table, then drop schema.
        Connection con = pc.getConnection();
        JDBC.assertCurrentSchema(con, userSchema);
        Statement stmt = con.createStatement();
        stmt.executeUpdate("create table schematest (id int)");
        stmt.executeUpdate("drop table schematest");
        stmt.executeUpdate("drop schema " + userSchema + " restrict");
        stmt.close();
        con.close();
        // Get second connection.
        con = pc.getConnection();
        JDBC.assertCurrentSchema(con, userSchema);
        stmt = con.createStatement();
        stmt.executeUpdate("create table schematest (id int)");
        stmt.executeUpdate("drop table schematest");
        stmt.close();
        JDBC.assertCurrentSchema(con, userSchema);
        con.close();
        pc.close();
    }
View Full Code Here

        ConnectionPoolDataSource cpds = null;
        try {
            cpds = J2EEDataSource.getConnectionPoolDataSource();       
            cpds.setLoginTimeout(10);
            PooledConnection pc = cpds.getPooledConnection();
            Connection conn = pc.getConnection();
            CallableStatement cs = conn.prepareCall("CALL TESTROUTINE.SLEEP(20000)");
            cs.execute();
            //rollback to make sure our connection is ok.
            conn.rollback();

            // Close the logical connection and get a new one.
            // This will invoke reset which also needs its timeout reset
            conn.close();
            conn = pc.getConnection();
            cs = conn.prepareCall("CALL TESTROUTINE.SLEEP(20000)");
            cs.execute();
            //rollback to make sure our connection is ok.
            conn.rollback();
        } finally {
View Full Code Here

TOP

Related Classes of javax.sql.PooledConnection

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.