Examples of DruidPooledPreparedStatement


Examples of com.alibaba.druid.pool.DruidPooledPreparedStatement

        PreparedStatementHolder stmtHoler_3;
        PreparedStatementHolder stmtHoler_4;
       
        // sql_0连续执行两次
        {
            DruidPooledPreparedStatement stmt_0 = (DruidPooledPreparedStatement) conn.prepareStatement(sql_0);

            Assert.assertFalse(stmt_0.getPreparedStatementHolder().isPooling());

            stmt_0.close();
            Assert.assertEquals(1, stmtPool.size());
            Assert.assertTrue(stmt_0.getPreparedStatementHolder().isPooling());
        }
        {
            DruidPooledPreparedStatement stmt_0 = (DruidPooledPreparedStatement) conn.prepareStatement(sql_0);
            Assert.assertEquals(1, stmtPool.size());
            Assert.assertTrue(stmt_0.getPreparedStatementHolder().isInUse());
            Assert.assertTrue(stmt_0.getPreparedStatementHolder().isPooling());

            stmt_0.close();

            Assert.assertFalse(stmt_0.getPreparedStatementHolder().isInUse());
            Assert.assertTrue(stmt_0.getPreparedStatementHolder().isPooling());
            Assert.assertEquals(1, stmtPool.size());
        }
       
        DruidPooledPreparedStatement stmt_0 = (DruidPooledPreparedStatement) conn.prepareStatement(sql_0);
       
        stmtHoler_0 = stmt_0.getPreparedStatementHolder();
       
        Assert.assertTrue(stmtHoler_0.isInUse());
        Assert.assertTrue(stmtHoler_0.isPooling());
       
        stmt_0.execute();
       
        {
            DruidPooledPreparedStatement stmt_1 = (DruidPooledPreparedStatement) conn.prepareStatement(sql_1);
            Assert.assertEquals(1, stmtPool.size());
           
            stmtHoler_1 = stmt_1.getPreparedStatementHolder();
           
            Assert.assertTrue(stmt_1.getPreparedStatementHolder().isInUse());
            Assert.assertFalse(stmt_1.getPreparedStatementHolder().isPooling());

            stmt_1.close();

            Assert.assertFalse(stmt_1.getPreparedStatementHolder().isInUse());
            Assert.assertTrue(stmt_1.getPreparedStatementHolder().isPooling());
            Assert.assertTrue(stmt_1.getPreparedStatementHolder().isPooling());
            Assert.assertEquals(2, stmtPool.size());
        }
       
        Assert.assertTrue(stmtHoler_0.isPooling());
        Assert.assertTrue(stmtHoler_1.isPooling());
       
        {
            DruidPooledPreparedStatement stmt_2 = (DruidPooledPreparedStatement) conn.prepareStatement(sql_2);
            Assert.assertEquals(2, stmtPool.size());
           
            stmtHoler_2 = stmt_2.getPreparedStatementHolder();
           
            Assert.assertTrue(stmt_2.getPreparedStatementHolder().isInUse());
            Assert.assertFalse(stmt_2.getPreparedStatementHolder().isPooling());
           
            stmt_2.close();
           
            Assert.assertFalse(stmt_2.getPreparedStatementHolder().isInUse());
            Assert.assertTrue(stmt_2.getPreparedStatementHolder().isPooling());
            Assert.assertTrue(stmt_2.getPreparedStatementHolder().isPooling());
            Assert.assertEquals(3, stmtPool.size());
        }
       
        Assert.assertTrue(stmtHoler_0.isPooling());
        Assert.assertTrue(stmtHoler_1.isPooling());
        Assert.assertTrue(stmtHoler_2.isPooling());
       
        {
            DruidPooledPreparedStatement stmt_3 = (DruidPooledPreparedStatement) conn.prepareStatement(sql_3);
            Assert.assertEquals(3, stmtPool.size());
           
            stmtHoler_3 = stmt_3.getPreparedStatementHolder();
           
            Assert.assertTrue(stmt_3.getPreparedStatementHolder().isInUse());
            Assert.assertFalse(stmt_3.getPreparedStatementHolder().isPooling());
           
            stmt_3.close();
           
            Assert.assertFalse(stmt_3.getPreparedStatementHolder().isInUse());
            Assert.assertTrue(stmt_3.getPreparedStatementHolder().isPooling());
            Assert.assertTrue(stmt_3.getPreparedStatementHolder().isPooling());
            Assert.assertEquals(3, stmtPool.size());
        }
       
       
        Assert.assertFalse(stmtHoler_0.isPooling());
        Assert.assertTrue(stmtHoler_1.isPooling());
        Assert.assertTrue(stmtHoler_2.isPooling());
        Assert.assertTrue(stmtHoler_3.isPooling());
       
        {
            DruidPooledPreparedStatement stmt_4 = (DruidPooledPreparedStatement) conn.prepareStatement(sql_4);
            Assert.assertEquals(3, stmtPool.size());
           
            stmtHoler_4 = stmt_4.getPreparedStatementHolder();
           
            Assert.assertTrue(stmt_4.getPreparedStatementHolder().isInUse());
            Assert.assertFalse(stmt_4.getPreparedStatementHolder().isPooling());
           
            stmt_4.close();
           
            Assert.assertFalse(stmt_4.getPreparedStatementHolder().isInUse());
            Assert.assertTrue(stmt_4.getPreparedStatementHolder().isPooling());
            Assert.assertTrue(stmt_4.getPreparedStatementHolder().isPooling());
            Assert.assertEquals(3, stmtPool.size());
        }
       
        Assert.assertFalse(stmtHoler_0.isPooling());
        Assert.assertFalse(stmtHoler_1.isPooling());
View Full Code Here

Examples of com.alibaba.druid.pool.DruidPooledPreparedStatement

        MockConnection mockConn = new MockConnection();
        DruidConnectionHolder connHolder = new DruidConnectionHolder(dataSource, mockConn);
        DruidPooledConnection conn = new DruidPooledConnection(connHolder);

        raw = new MockPreparedStatement(null, null);
        stmt = new DruidPooledPreparedStatement(conn, new PreparedStatementHolder(new PreparedStatementKey("", null,
                                                                                                           null, 0, 0,
                                                                                                           0), raw)) {

            protected SQLException checkException(Throwable error) throws SQLException {
                if (error instanceof SQLException) {
View Full Code Here

Examples of com.alibaba.druid.pool.DruidPooledPreparedStatement

            PreparedStatement stmt = conn.prepareStatement(sql);
            stmt.close();
        }

        PreparedStatement stmt0 = conn.prepareStatement(sql);
        DruidPooledPreparedStatement pooledStmt0 = (DruidPooledPreparedStatement) stmt0;

        Assert.assertEquals(1, pooledStmt0.getPreparedStatementHolder().getInUseCount());

        PreparedStatement stmt1 = conn.prepareStatement(sql);
        DruidPooledPreparedStatement pooledStmt1 = (DruidPooledPreparedStatement) stmt1;

        Assert.assertSame(pooledStmt0.getPreparedStatementHolder(), pooledStmt1.getPreparedStatementHolder());

        stmt0.close();
        stmt1.close();

        conn.close();
View Full Code Here

Examples of com.alibaba.druid.pool.DruidPooledPreparedStatement

            PreparedStatement stmt = conn.prepareStatement(sql);
            stmt.close();
        }

        PreparedStatement stmt0 = conn.prepareStatement(sql);
        DruidPooledPreparedStatement pooledStmt0 = (DruidPooledPreparedStatement) stmt0;

        Assert.assertEquals(1, pooledStmt0.getPreparedStatementHolder().getInUseCount());

        PreparedStatement stmt1 = conn.prepareStatement(sql);
        DruidPooledPreparedStatement pooledStmt1 = (DruidPooledPreparedStatement) stmt1;

        Assert.assertSame(pooledStmt0.getPreparedStatementHolder(), pooledStmt1.getPreparedStatementHolder());

        stmt0.close();
        stmt1.close();

        conn.close();
View Full Code Here

Examples of com.alibaba.druid.pool.DruidPooledPreparedStatement

        Connection conn = dataSource.getConnection();

        String sql = "select 1";

        PreparedStatement stmt0 = conn.prepareStatement(sql);
        DruidPooledPreparedStatement pooledStmt0 = (DruidPooledPreparedStatement) stmt0;
        stmt0.close();

        PreparedStatement stmt1 = conn.prepareStatement(sql);
        DruidPooledPreparedStatement pooledStmt1 = (DruidPooledPreparedStatement) stmt1;

        Assert.assertEquals(1, pooledStmt1.getPreparedStatementHolder().getInUseCount());
        Assert.assertSame(pooledStmt1.getPreparedStatementHolder(), pooledStmt0.getPreparedStatementHolder()); // same

        PreparedStatement stmt2 = conn.prepareStatement(sql);
        DruidPooledPreparedStatement pooledStmt2 = (DruidPooledPreparedStatement) stmt2;

        Assert.assertNotSame(pooledStmt1.getPreparedStatementHolder(), pooledStmt2.getPreparedStatementHolder()); // not same

        stmt1.close();
        stmt2.close();

        conn.close();
View Full Code Here

Examples of com.alibaba.druid.pool.DruidPooledPreparedStatement

        conn.setAutoCommit(false);

        String sql = "select 1";

        PreparedStatement stmt0 = conn.prepareStatement(sql);
        DruidPooledPreparedStatement pooledStmt0 = (DruidPooledPreparedStatement) stmt0;
        stmt0.close();

        PreparedStatement stmt1 = conn.prepareStatement(sql);
        DruidPooledPreparedStatement pooledStmt1 = (DruidPooledPreparedStatement) stmt1;

        Assert.assertEquals(1, pooledStmt1.getPreparedStatementHolder().getInUseCount());
        Assert.assertSame(pooledStmt1.getPreparedStatementHolder(), pooledStmt0.getPreparedStatementHolder()); // same

        PreparedStatement stmt2 = conn.prepareStatement(sql);
        DruidPooledPreparedStatement pooledStmt2 = (DruidPooledPreparedStatement) stmt2;

        Assert.assertNotSame(pooledStmt1.getPreparedStatementHolder(), pooledStmt2.getPreparedStatementHolder()); // not same

        stmt1.close();
        stmt2.close();

        conn.close();
View Full Code Here

Examples of com.alibaba.druid.pool.DruidPooledPreparedStatement

        Assert.assertEquals(0, dataSource.getActiveCount());
    }

    public void test_closePoolableStatement() throws Exception {
        DruidPooledConnection conn = (DruidPooledConnection) dataSource.getConnection();
        DruidPooledPreparedStatement stmt = (DruidPooledPreparedStatement) conn.prepareStatement("select 1");
        conn.close();
        conn.closePoolableStatement(stmt);
    }
View Full Code Here

Examples of com.alibaba.druid.pool.DruidPooledPreparedStatement

        PreparedStatementHolder stmtHoler_0;
        PreparedStatementHolder stmtHoler_1_A;
        PreparedStatementHolder stmtHoler_1_B;
        PreparedStatementHolder stmtHoler_1_C;

        DruidPooledPreparedStatement stmt_0;
        DruidPooledPreparedStatement stmt_1_A;
        DruidPooledPreparedStatement stmt_1_B;
        DruidPooledPreparedStatement stmt_1_C;
        DruidPooledPreparedStatement stmt_1_D;
        DruidPooledPreparedStatement stmt_1_E;
        DruidPooledPreparedStatement stmt_1_F;
        DruidPooledPreparedStatement stmt_1_G;
        DruidPooledPreparedStatement stmt_1_H;
       
        DruidPooledResultSet rs_0;
        DruidPooledResultSet rs_1_A;
        DruidPooledResultSet rs_1_B;
        DruidPooledResultSet rs_1_C;
        DruidPooledResultSet rs_1_D;
        DruidPooledResultSet rs_1_E;
        DruidPooledResultSet rs_1_F;
        DruidPooledResultSet rs_1_G;
        DruidPooledResultSet rs_1_H;

        stmt_0 = (DruidPooledPreparedStatement) conn.prepareStatement(sql_0);
        rs_0 = (DruidPooledResultSet) stmt_0.executeQuery();
       
        Assert.assertTrue(stmt_0.getPreparedStatementHolder().isInUse());

        stmt_1_A = (DruidPooledPreparedStatement) conn.prepareStatement(sql_1);
        rs_1_A = (DruidPooledResultSet) stmt_1_A.executeQuery();
       
        Assert.assertTrue(stmt_0.getPreparedStatementHolder().isInUse());
        Assert.assertTrue(stmt_1_A.getPreparedStatementHolder().isInUse());
       
        stmt_1_B = (DruidPooledPreparedStatement) conn.prepareStatement(sql_1);
        rs_1_B = (DruidPooledResultSet) stmt_1_B.executeQuery();
        rs_1_B.close();
        stmt_1_B.close();
       
        Assert.assertTrue(stmt_0.getPreparedStatementHolder().isInUse());
        Assert.assertTrue(stmt_1_A.getPreparedStatementHolder().isInUse());
        Assert.assertFalse(stmt_1_B.getPreparedStatementHolder().isInUse());
       
        stmt_1_C = (DruidPooledPreparedStatement) conn.prepareStatement(sql_1);
        rs_1_C = (DruidPooledResultSet) stmt_1_C.executeQuery();
        rs_1_C.close();
        stmt_1_C.close();
       
        Assert.assertTrue(stmt_0.getPreparedStatementHolder().isInUse());
        Assert.assertTrue(stmt_1_A.getPreparedStatementHolder().isInUse());
        Assert.assertFalse(stmt_1_B.getPreparedStatementHolder().isInUse());
        Assert.assertFalse(stmt_1_C.getPreparedStatementHolder().isInUse());
       
        stmt_1_D = (DruidPooledPreparedStatement) conn.prepareStatement(sql_1);
        rs_1_D = (DruidPooledResultSet) stmt_1_D.executeQuery();
        rs_1_D.close();
        stmt_1_D.close();
       
        Assert.assertTrue(stmt_0.getPreparedStatementHolder().isInUse());
        Assert.assertTrue(stmt_1_A.getPreparedStatementHolder().isInUse());
        Assert.assertFalse(stmt_1_B.getPreparedStatementHolder().isInUse());
        Assert.assertFalse(stmt_1_C.getPreparedStatementHolder().isInUse());
        Assert.assertFalse(stmt_1_D.getPreparedStatementHolder().isInUse());
       
        stmt_1_E = (DruidPooledPreparedStatement) conn.prepareStatement(sql_1);
        rs_1_E = (DruidPooledResultSet) stmt_1_E.executeQuery();
        rs_1_E.close();
        stmt_1_E.close();
       
        rs_1_A.close();
        stmt_1_A.close();
       
        stmt_1_F = (DruidPooledPreparedStatement) conn.prepareStatement(sql_1);
        rs_1_F = (DruidPooledResultSet) stmt_1_F.executeQuery();
        rs_1_F.close();
        stmt_1_F.close();
       
        stmt_1_G = (DruidPooledPreparedStatement) conn.prepareStatement(sql_1);
        rs_1_G = (DruidPooledResultSet) stmt_1_G.executeQuery();
       
        stmt_1_H = (DruidPooledPreparedStatement) conn.prepareStatement(sql_1);
        rs_1_H = (DruidPooledResultSet) stmt_1_H.executeQuery();
        rs_1_H.close();
        stmt_1_H.close();
       
        rs_1_G.close();
        stmt_1_G.close();
       
        conn.close();
View Full Code Here

Examples of com.alibaba.druid.pool.DruidPooledPreparedStatement

    public void test_hitCount() throws Exception {
        String sql = "select ?";
        {
            Connection conn = dataSource.getConnection();
            DruidPooledPreparedStatement stmt = (DruidPooledPreparedStatement) conn.prepareStatement(sql);
           
            Assert.assertEquals(0, stmt.getFetchSize());
            Assert.assertEquals(0, stmt.getFetchDirection());
            Assert.assertEquals(0, stmt.getMaxRows());
            Assert.assertEquals(0, stmt.getMaxFieldSize());
            Assert.assertEquals(0, stmt.getQueryTimeout());
            Assert.assertEquals(sql, stmt.getSql());

            stmt.setFetchSize(1);
            stmt.setFetchDirection(2);
            stmt.setMaxRows(3);
            stmt.setMaxFieldSize(4);
            stmt.setQueryTimeout(5);
           
            Assert.assertEquals(1, stmt.getFetchSize());
            Assert.assertEquals(2, stmt.getFetchDirection());
            Assert.assertEquals(3, stmt.getMaxRows());
            Assert.assertEquals(4, stmt.getMaxFieldSize());
            Assert.assertEquals(5, stmt.getQueryTimeout());
           
            stmt.setString(1, "xx");
            ResultSet rs = stmt.executeQuery();
            Assert.assertTrue(rs.next());
            Assert.assertFalse(rs.next());
            rs.close();
            conn.close();

            Assert.assertEquals(0, stmt.getHitCount());
        }
        {
            Connection conn = dataSource.getConnection();
            DruidPooledPreparedStatement stmt = (DruidPooledPreparedStatement) conn.prepareStatement(sql);
           
            Assert.assertEquals(0, stmt.getFetchSize());
            Assert.assertEquals(0, stmt.getFetchDirection());
            Assert.assertEquals(0, stmt.getMaxRows());
            Assert.assertEquals(0, stmt.getMaxFieldSize());
            Assert.assertEquals(0, stmt.getQueryTimeout());
           
            stmt.setString(1, "xx");
            ResultSet rs = stmt.executeQuery();
            Assert.assertTrue(rs.next());
            Assert.assertFalse(rs.next());
            rs.close();
            conn.close();
           
            Assert.assertEquals(1, stmt.getHitCount());
            Assert.assertNotNull(stmt.getKey());
        }
    }
View Full Code Here

Examples of com.alibaba.druid.pool.DruidPooledPreparedStatement

            Connection conn = dataSource.getConnection();

            String sql = "select 1";

            PreparedStatement stmt0 = conn.prepareStatement(sql);
            DruidPooledPreparedStatement pooledStmt0 = (DruidPooledPreparedStatement) stmt0;
            stmt0.close();

            PreparedStatement stmt1 = conn.prepareStatement(sql);
            DruidPooledPreparedStatement pooledStmt1 = (DruidPooledPreparedStatement) stmt1;

            Assert.assertEquals(1, pooledStmt1.getPreparedStatementHolder().getInUseCount());
            Assert.assertSame(pooledStmt1.getPreparedStatementHolder(), pooledStmt0.getPreparedStatementHolder()); // same

            PreparedStatement stmt2 = conn.prepareStatement(sql);
            DruidPooledPreparedStatement pooledStmt2 = (DruidPooledPreparedStatement) stmt2;

            Assert.assertNotSame(pooledStmt1.getPreparedStatementHolder(), pooledStmt2.getPreparedStatementHolder()); // not
                                                                                                                      // same

            conn.close();
        }
        {
            Connection conn = dataSource.getConnection();

            conn.setAutoCommit(false);

            String sql = "select 1";

            PreparedStatement stmt0 = conn.prepareStatement(sql);
            DruidPooledPreparedStatement pooledStmt0 = (DruidPooledPreparedStatement) stmt0;
            stmt0.close();

            PreparedStatement stmt1 = conn.prepareStatement(sql);
            DruidPooledPreparedStatement pooledStmt1 = (DruidPooledPreparedStatement) stmt1;

            Assert.assertEquals(1, pooledStmt1.getPreparedStatementHolder().getInUseCount());
            Assert.assertSame(pooledStmt1.getPreparedStatementHolder(), pooledStmt0.getPreparedStatementHolder()); // same

            PreparedStatement stmt2 = conn.prepareStatement(sql);
            DruidPooledPreparedStatement pooledStmt2 = (DruidPooledPreparedStatement) stmt2;

            Assert.assertNotSame(pooledStmt1.getPreparedStatementHolder(), pooledStmt2.getPreparedStatementHolder()); // not
                                                                                                                      // same

            stmt1.close();
            stmt2.close();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.