コード例 #1
0
  public void test_prepCall_1() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);

    MockPreparedStatement raw = null;
    {
      PreparedStatement stmt =
          conn.prepareCall("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
      raw = stmt.unwrap(MockPreparedStatement.class);
      stmt.close();
    }
    {
      PreparedStatement stmt =
          conn.prepareCall("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
      Assert.assertEquals(raw, stmt.unwrap(MockPreparedStatement.class));
      stmt.close();
    }

    conn.getConnectionHolder().toString();
    conn.getConnectionHolder().setLastActiveTimeMillis(0);
    conn.getConnectionHolder().toString();
    conn.getConnectionHolder().getUseCount();
    conn.getConnectionHolder().getTimeMillis();

    conn.close();
  }
コード例 #2
0
  public void test_stmtCache() throws Exception {
    for (int j = 0; j < 10; ++j) {
      for (int i = 0; i < 10; ++i) {
        Connection conn = dataSource.getConnection();
        String sql = "SELECT" + i;
        PreparedStatement stmt = conn.prepareStatement(sql);
        stmt.execute();
        stmt.close();
        conn.close();
      }
    }

    dataSource.setPoolPreparedStatements(true);

    for (int j = 0; j < 10; ++j) {
      for (int i = 0; i < 10; ++i) {
        Connection conn = dataSource.getConnection();
        String sql = "SELECT" + i;
        PreparedStatement stmt = conn.prepareStatement(sql);
        stmt.execute();
        stmt.close();
        conn.close();
      }
    }

    for (int i = 0; i < 1000 * 1; ++i) {
      Connection conn = dataSource.getConnection();
      PreparedStatement stmt = conn.prepareStatement("SELECT " + i);
      stmt.execute();
      stmt.close();
      conn.close();
    }

    Connection conn = dataSource.getConnection();
    DruidPooledConnection poolableConn = conn.unwrap(DruidPooledConnection.class);
    Assert.assertNotNull(poolableConn);

    Assert.assertEquals(
        dataSource.getMaxPoolPreparedStatementPerConnectionSize(),
        poolableConn.getConnectionHolder().getStatementPool().getMap().size());

    conn.close();

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