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()); }
public JdbcSqlStat createSqlStat(String sql) { lock.writeLock().lock(); try { JdbcSqlStat sqlStat = sqlStatMap.get(sql); if (sqlStat == null) { sqlStat = new JdbcSqlStat(sql); sqlStat.setDbType(this.dbType); sqlStatMap.put(sql, sqlStat); } return sqlStat; } finally { lock.writeLock().unlock(); } }
@Override public TabularData getSqlList() throws JMException { Map<String, JdbcSqlStat> sqlStatMap = this.getSqlStatMap(); CompositeType rowType = JdbcSqlStat.getCompositeType(); String[] indexNames = rowType.keySet().toArray(new String[rowType.keySet().size()]); TabularType tabularType = new TabularType("SqlListStatistic", "SqlListStatistic", rowType, indexNames); TabularData data = new TabularDataSupport(tabularType); for (Map.Entry<String, JdbcSqlStat> entry : sqlStatMap.entrySet()) { data.put(entry.getValue().getCompositeData()); } return data; }