Exemple #1
0
  public void reset() {
    blobOpenCount.set(0);
    clobOpenCount.set(0);

    connectionStat.reset();
    statementStat.reset();
    resultSetStat.reset();
    connectionHoldHistogram.reset();

    lock.writeLock().lock();
    try {
      Iterator<Map.Entry<String, JdbcSqlStat>> iter = sqlStatMap.entrySet().iterator();
      while (iter.hasNext()) {
        Map.Entry<String, JdbcSqlStat> entry = iter.next();
        JdbcSqlStat stat = entry.getValue();
        if (stat.getExecuteCount() == 0 && stat.getRunningCount() == 0) {
          stat.setRemoved(true);
          iter.remove();
        } else {
          stat.reset();
        }
      }
    } finally {
      lock.writeLock().unlock();
    }

    for (JdbcConnectionStat.Entry connectionStat : connections.values()) {
      connectionStat.reset();
    }
  }
  public void test_stat_1() throws Exception {
    Connection conn = dataSource.getConnection();

    String sql = "select 'x'";
    PreparedStatement stmt = conn.prepareStatement("select 'x'");

    JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);

    Assert.assertEquals(0, sqlStat.getInputStreamOpenCount());

    ResultSet rs = stmt.executeQuery();
    rs.next();
    rs.getAsciiStream("1");
    rs.getAsciiStream("2");
    rs.getAsciiStream("3");
    rs.close();
    stmt.close();

    conn.close();

    Assert.assertEquals(3, sqlStat.getInputStreamOpenCount());

    sqlStat.reset();
    Assert.assertEquals(0, sqlStat.getInputStreamOpenCount());
  }