Search in sources :

Example 1 with DruidPooledResultSet

use of com.alibaba.druid.pool.DruidPooledResultSet in project druid by alibaba.

the class DruidPooledResultSetTest method test_notSupport_1.

public void test_notSupport_1() throws Exception {
    String sql = "select ?";
    Connection conn = dataSource.getConnection();
    PreparedStatement stmt = conn.prepareStatement(sql);
    stmt.setString(1, "xxx");
    DruidPooledResultSet rs = (DruidPooledResultSet) stmt.executeQuery();
    Exception error = null;
    try {
        rs.getObject("1", String.class);
    } catch (SQLFeatureNotSupportedException e) {
        error = e;
    }
    Assert.assertNotNull(error);
    rs.close();
    conn.close();
}
Also used : SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) DruidPooledResultSet(com.alibaba.druid.pool.DruidPooledResultSet) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException)

Example 2 with DruidPooledResultSet

use of com.alibaba.druid.pool.DruidPooledResultSet in project druid by alibaba.

the class DruidPooledResultSetTest method test_notSupport.

public void test_notSupport() throws Exception {
    String sql = "select ?";
    Connection conn = dataSource.getConnection();
    PreparedStatement stmt = conn.prepareStatement(sql);
    stmt.setString(1, "xxx");
    DruidPooledResultSet rs = (DruidPooledResultSet) stmt.executeQuery();
    Exception error = null;
    try {
        rs.getObject(1, String.class);
    } catch (SQLFeatureNotSupportedException e) {
        error = e;
    }
    Assert.assertNotNull(error);
    rs.close();
    conn.close();
}
Also used : SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) DruidPooledResultSet(com.alibaba.druid.pool.DruidPooledResultSet) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException)

Example 3 with DruidPooledResultSet

use of com.alibaba.druid.pool.DruidPooledResultSet in project druid by alibaba.

the class DruidPooledResultSetTest method test_rowCount.

public void test_rowCount() throws Exception {
    String sql = "select ?";
    Connection conn = dataSource.getConnection();
    PreparedStatement stmt = conn.prepareStatement(sql);
    stmt.setString(1, "xxx");
    DruidPooledResultSet rs = (DruidPooledResultSet) stmt.executeQuery();
    Assert.assertEquals(true, rs.next());
    Assert.assertEquals(false, rs.next());
    Assert.assertEquals(1, rs.getFetchRowCount());
    Assert.assertEquals(true, rs.previous());
    Assert.assertEquals(false, rs.previous());
    Assert.assertEquals(1, rs.getFetchRowCount());
    Assert.assertEquals(true, rs.next());
    Assert.assertEquals(false, rs.next());
    Assert.assertEquals(1, rs.getFetchRowCount());
    Assert.assertFalse(rs.rowUpdated());
    rs.close();
    conn.close();
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) DruidPooledResultSet(com.alibaba.druid.pool.DruidPooledResultSet)

Example 4 with DruidPooledResultSet

use of com.alibaba.druid.pool.DruidPooledResultSet in project druid by alibaba.

the class ResultSetTest method setUp.

protected void setUp() throws Exception {
    stmt = new DruidPooledStatement(null, null) {

        protected SQLException checkException(Throwable error) throws SQLException {
            if (error instanceof SQLException) {
                return (SQLException) error;
            }
            return new SQLException(error);
        }
    };
    raw = new MockResultSet(null);
    raw.getRows().add(new Object[] { null });
    resultSet = new DruidPooledResultSet(stmt, raw);
}
Also used : DruidPooledStatement(com.alibaba.druid.pool.DruidPooledStatement) SQLException(java.sql.SQLException) MockResultSet(com.alibaba.druid.mock.MockResultSet) DruidPooledResultSet(com.alibaba.druid.pool.DruidPooledResultSet)

Example 5 with DruidPooledResultSet

use of com.alibaba.druid.pool.DruidPooledResultSet in project druid by alibaba.

the class PSCacheTest4 method test_pscache.

public void test_pscache() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection();
    DruidConnectionHolder holder = conn.getConnectionHolder();
    PreparedStatementPool stmtPool = holder.getStatementPool();
    final String sql_0 = "select 0";
    final String sql_1 = "select 1";
    Assert.assertEquals(0, stmtPool.size());
    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();
}
Also used : PreparedStatementHolder(com.alibaba.druid.pool.PreparedStatementHolder) PreparedStatementPool(com.alibaba.druid.pool.PreparedStatementPool) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) DruidPooledPreparedStatement(com.alibaba.druid.pool.DruidPooledPreparedStatement) DruidConnectionHolder(com.alibaba.druid.pool.DruidConnectionHolder) DruidPooledResultSet(com.alibaba.druid.pool.DruidPooledResultSet)

Aggregations

DruidPooledResultSet (com.alibaba.druid.pool.DruidPooledResultSet)7 MockResultSet (com.alibaba.druid.mock.MockResultSet)3 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 SQLException (java.sql.SQLException)3 DruidPooledStatement (com.alibaba.druid.pool.DruidPooledStatement)2 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)2 DruidConnectionHolder (com.alibaba.druid.pool.DruidConnectionHolder)1 DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)1 DruidPooledPreparedStatement (com.alibaba.druid.pool.DruidPooledPreparedStatement)1 PreparedStatementHolder (com.alibaba.druid.pool.PreparedStatementHolder)1 PreparedStatementPool (com.alibaba.druid.pool.PreparedStatementPool)1