Package org.apache.derby.client.am.stmtcache

Examples of org.apache.derby.client.am.stmtcache.JDBCStatementCache


     */
    public void testCloseBehaviorExternalPs()
            throws SQLException {
        final String sql = "values 7";
        java.sql.PreparedStatement ps = prepareStatement(sql);
        JDBCStatementCache cache = new JDBCStatementCache(10);
        insertStatementIntoCache(cache, ps, sql);
        LogicalStatementEntity logic =
                createLogicalStatementEntity(sql, false, cache);
        assertSame(ps, logic.getPhysPs());
        assertFalse(logic.isLogicalEntityClosed());
View Full Code Here


     */
    public void testCloseBehaviorExternalCs()
            throws SQLException {
        final String sql = "values 3";
        java.sql.CallableStatement cs = prepareCall(sql);
        JDBCStatementCache cache = new JDBCStatementCache(10);
        insertStatementIntoCache(cache, cs, sql);
        LogicalStatementEntity logic =
                createLogicalStatementEntity(sql, true, cache);
        assertSame(cs, logic.getPhysCs());
        assertFalse(logic.isLogicalEntityClosed());
View Full Code Here

    public void testCloseOnDuplicateStatement()
            throws SQLException {
        // Initial setup.
        final String sql = "values 7";
        java.sql.PreparedStatement ps = prepareStatement(sql);
        JDBCStatementCache cache = new JDBCStatementCache(10);
        StatementKey stmtKey = insertStatementIntoCache(cache, ps, sql);
        LogicalStatementEntity logic =
                createLogicalStatementEntity(sql, false, cache);
        assertSame(ps, logic.getPhysPs());
        assertFalse(logic.isLogicalEntityClosed());

        // Put a statement into the cache.
        //assertTrue(cache.cacheStatement(stmtKey, ps));
        // Create a second statement, equal to the first.
        java.sql.PreparedStatement psDupe = prepareStatement(sql);
        insertStatementIntoCache(cache, psDupe, sql);
        LogicalStatementEntity logicDupe =
                createLogicalStatementEntity(sql, false, cache);
        // Close the first logical entry, to put the physical statement back
        // into the cache.
        logic.close();
        // When we ask the logical entity to close the statement now, the
        // underlying physical prepared statement should actually be closed.
        logicDupe.close();
        assertTrue(logicDupe.isLogicalEntityClosed());
        // Since we are possibly running in a pre-JDBC 4 environment, try do do
        // something to provoke an exception.
        try {
            psDupe.execute();
            fail("Statement should have been closed and throw an exception");
        } catch (SQLException sqle) {
            assertSQLState("XJ012", sqle);
        }

        // The cached statement should still be open.
        java.sql.PreparedStatement psCached = cache.getCached(stmtKey);
        assertSame(ps, psCached);
        java.sql.ResultSet rs = psCached.executeQuery();
        JDBC.assertSingleValueResultSet(rs, "7");
    }
View Full Code Here

    public void testCloseWhenStatementShallBeCached()
            throws SQLException {
        // Initial setup.
        final String sql = "values 9";
        java.sql.PreparedStatement ps = prepareStatement(sql);
        JDBCStatementCache cache = new JDBCStatementCache(10);
        StatementKey stmtKey = insertStatementIntoCache(cache, ps, sql);
        LogicalStatementEntity logic =
                createLogicalStatementEntity(sql, false, cache);
        assertSame(ps, logic.getPhysPs());
        assertFalse(logic.isLogicalEntityClosed());

        // Close the statement, it should go into the cache.
        logic.close();
        assertTrue(logic.isLogicalEntityClosed());
        // Use the physical statement.
        java.sql.ResultSet rs = ps.executeQuery();
        JDBC.assertSingleValueResultSet(rs, "9");
        // Get the statement from the cache.
        assertSame(ps, cache.getCached(stmtKey));
    }
View Full Code Here

    public void testClosedUnderlyingStatement()
            throws SQLException {
        // Initial setup.
        final String sql = "values 19";
        java.sql.PreparedStatement ps = prepareStatement(sql);
        JDBCStatementCache cache = new JDBCStatementCache(10);
        insertStatementIntoCache(cache, ps, sql);
        LogicalStatementEntity logic =
                createLogicalStatementEntity(sql, false, cache);
        assertSame(ps, logic.getPhysPs());
        assertFalse(logic.isLogicalEntityClosed());
View Full Code Here

     * @throws SQLException if a JDBC operation fails
     */
    public void testEvictionFromCache()
            throws SQLException {
        // Initial setup.
        JDBCStatementCache cache = new JDBCStatementCache(2);
        final String sql1 = "values 1";
        final String sql2 = "values 2";
        final String sql3 = "values 3";
        // Create three physical prepares statements.
        java.sql.PreparedStatement ps1 = prepareStatement(sql1);
        java.sql.PreparedStatement ps2 = prepareStatement(sql2);
        java.sql.PreparedStatement ps3 = prepareStatement(sql3);
        // Insert the two first physical statements, the get logical wrappers.
        StatementKey stmtKey1 = insertStatementIntoCache(cache, ps1, sql1);
        StatementKey stmtKey2 = insertStatementIntoCache(cache, ps2, sql2);
        LogicalStatementEntity logic1 =
                createLogicalStatementEntity(sql1, false, cache);
        LogicalStatementEntity logic2 =
                createLogicalStatementEntity(sql2, false, cache);
        // Insert the last physical statement and get the logical wrapper.
        StatementKey stmtKey3 = insertStatementIntoCache(cache, ps3, sql3);
        LogicalStatementEntity logic3 =
                createLogicalStatementEntity(sql3, false, cache);
        assertSame(ps1, logic1.getPhysPs());
        assertSame(ps2, logic2.getPhysPs());
        assertSame(ps3, logic3.getPhysPs());

        // Close two first logical statements, putting them back into the cache.
        logic1.close();
        logic2.close();
        // Assert both of the statements are open.
        JDBC.assertSingleValueResultSet(ps1.executeQuery(), "1");
        JDBC.assertSingleValueResultSet(ps2.executeQuery(), "2");
        // Close the third statement. It should be cached, but since the cache
        // will exceed its maximum capacity, the first statement will be thrown
        // out and it should be closed in the process.
        logic3.close();
        JDBC.assertSingleValueResultSet(ps3.executeQuery(), "3");
        assertNull("ps1 still in the cache", cache.getCached(stmtKey1));
        try {
            ps1.executeQuery();
            fail("ps1 should have been closed by the cache");
        } catch (SQLException sqle) {
            assertSQLState("XJ012", sqle);
        }
        // Make sure the right statements are returned from the cache.
        assertSame(ps2, cache.getCached(stmtKey2));
        assertSame(ps3, cache.getCached(stmtKey3));
    }
View Full Code Here

        if (ds.maxStatementsToPool() <= 0) {
            this.statementCache = null;
        } else {
            this.statementCache =
                    new JDBCStatementCache(ds.maxStatementsToPool());
        }

        try {
            //pass the client pooled connection instance to this
            //instance of the NetConnection object
View Full Code Here

     * The overhead would come from always throwing out the newly inserted
     * element.
     */
    public void testCreateCacheWithZeroOrNegativeMaxSize() {
        try {
            new JDBCStatementCache(-10);
            fail("Negative max size should not be allowed");
        } catch (IllegalArgumentException iae) {
            // As expected
        }
        try {
            new JDBCStatementCache(0);
            fail("Zero max size should not be allowed");
        } catch (IllegalArgumentException iae) {
            // As expected
        }
    }
View Full Code Here

     * @throws SQLException if obtaining a PreparedStatement fails
     */
    public void testBasicInsertion()
            throws SQLException {
        String sql = "values 1";
        JDBCStatementCache cache = new JDBCStatementCache(10);
        PreparedStatement ps = prepareStatement(sql);
        StatementKey key = StatementKeyFactory.newPrepared(sql, "app", 1);
        assertTrue(cache.cacheStatement(key, ps));
        assertEquals(ps, cache.getCached(key));
    }
View Full Code Here

     * @throws SQLException if obtaining a PreparedStatement fails
     */
    public void testBasicDuplicateKeyInsertion()
            throws SQLException {
        String sql = "values 1";
        JDBCStatementCache cache = new JDBCStatementCache(10);
        PreparedStatement ps = prepareStatement(sql);
        StatementKey key = StatementKeyFactory.newPrepared(sql, "app", 1);
        assertTrue(cache.cacheStatement(key, ps));
        // Duplicates shall not be inserted.
        assertFalse(cache.cacheStatement(key, ps));
        assertEquals(ps, cache.getCached(key));
    }
View Full Code Here

TOP

Related Classes of org.apache.derby.client.am.stmtcache.JDBCStatementCache

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.