Package javax.sql

Examples of javax.sql.ConnectionPoolDataSource


     * @throws Exception
     */
    private void assertSecMecWithConnPoolingOK(
        String user, String password, Short secmec) throws Exception
    {    
        ConnectionPoolDataSource cpds = getCPDS(user,password);
       
        // call setSecurityMechanism with secmec.
        JDBCDataSource.setBeanProperty(cpds,
                "SecurityMechanism", secmec);
       
        // simulate case when connection will be re-used by getting
        // a connection, closing it and then the next call to
        // getConnection will re-use the previous connection. 
        PooledConnection pc = cpds.getPooledConnection();
        Connection conn = pc.getConnection();
        conn.close();
        conn = pc.getConnection();
        assertConnectionOK(conn);
        pc.close();
View Full Code Here


        if (user != null)
            attrs.put("user", user);
        if (password != null)
            attrs.put("password", password);
        attrs = addRequiredAttributes(attrs);
        ConnectionPoolDataSource cpds =
            J2EEDataSource.getConnectionPoolDataSource();
        for (Iterator i = attrs.keySet().iterator(); i.hasNext(); )
        {
            String property = (String) i.next();
            Object value = attrs.get(property);
View Full Code Here

     */
    public void testConnectionErrorEvent() throws SQLException, Exception
    {
        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");
View Full Code Here

    /**
     * Test that event notification doesn't fail when a null listener has
     * been registered (DERBY-3307).
     */
    public void testConnectionEventListenerIsNull() throws SQLException {
        ConnectionPoolDataSource cpds =
            J2EEDataSource.getConnectionPoolDataSource();
        subtestCloseEventWithNullListener(cpds.getPooledConnection());
        subtestErrorEventWithNullListener(cpds.getPooledConnection());

        XADataSource xads = J2EEDataSource.getXADataSource();
        subtestCloseEventWithNullListener(xads.getXAConnection());
        subtestErrorEventWithNullListener(xads.getXAConnection());
    }
View Full Code Here

     * Test that connections retrieved from {@code ConnectionPoolDataSource}
     * behave as expected when {@code close()} is called and the transaction is
     * 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);
    }
View Full Code Here

     *
     */
    public void testPooledReuseOnClose() throws SQLException
    {
      // PooledConnection from a ConnectionPoolDataSource
      ConnectionPoolDataSource cpds =
        J2EEDataSource.getConnectionPoolDataSource();
      subtestPooledReuseOnClose(cpds.getPooledConnection());
        subtestPooledCloseOnClose(cpds.getPooledConnection());
        // DERBY-3401 - removing a callback during a close causes problems.
        subtestPooledRemoveListenerOnClose(cpds.getPooledConnection());
        subtestPooledAddListenerOnClose(cpds.getPooledConnection());

      // PooledConnection from an XDataSource
      XADataSource xads = J2EEDataSource.getXADataSource();
      subtestPooledReuseOnClose(xads.getXAConnection());
        subtestPooledCloseOnClose(xads.getXAConnection());
View Full Code Here

            dssimple = (DataSource)realdssimple;
            assertConnectionOK(
                expectedValues, "SimpleDataSource", ds.getConnection());
        }
           
        ConnectionPoolDataSource dsp =
            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();
        } 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
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 if something goes wrong
     */
    public void testSchemaIsReset()
            throws SQLException {
        final String userSchema = "USERSCHEMA";
        ConnectionPoolDataSource cpDs =
                J2EEDataSource.getConnectionPoolDataSource();
        J2EEDataSource.setBeanProperty(cpDs, "createDatabase", "create");
        // Connect with a user specified, which should cause the schema to be
        // set to the user name.
        // Test without statement pooling first.
        doTestSchemaIsReset(cpDs.getPooledConnection(userSchema, "secret"),
                userSchema);

        // Try to enable statement pooling.
        // This is currently only implemented in the client driver.
        if (usingDerbyNetClient()) {
            J2EEDataSource.setBeanProperty(
                    cpDs, "maxStatements",new Integer(7));
            doTestSchemaIsReset(cpDs.getPooledConnection(userSchema, "secret"),
                    userSchema);
        }
    }
View Full Code Here

     * @throws SQLException if something goes wrong
     */
    public void testSchemaIsResetWhenDeleted()
            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)");
View Full Code Here

TOP

Related Classes of javax.sql.ConnectionPoolDataSource

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.