Author: fhanik Date: Tue Jun 23 14:44:24 2009 New Revision: 787693 URL: http://svn.apache.org/viewvc?rev=787693&view=rev Log: Fix slow query report to keep stats if we set the count to larger than 0
Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/SlowQueryReport.java tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TestSlowQueryReport.java Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/SlowQueryReport.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/SlowQueryReport.java?rev=787693&r1=787692&r2=787693&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/SlowQueryReport.java (original) +++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/SlowQueryReport.java Tue Jun 23 14:44:24 2009 @@ -75,6 +75,30 @@ this.maxQueries = maxQueries; } + + + @Override + protected String reportFailedQuery(String query, Object[] args, String name, long start, Throwable t) { + String sql = super.reportFailedQuery(query, args, name, start, t); + if (this.maxQueries > 0 ) { + long now = System.currentTimeMillis(); + long delta = now - start; + QueryStats qs = this.getQueryStats(sql); + qs.failure(delta, now); + } + return sql; + } + + @Override + protected String reportSlowQuery(String query, Object[] args, String name, long start, long delta) { + String sql = super.reportSlowQuery(query, args, name, start, delta); + if (this.maxQueries > 0 ) { + QueryStats qs = this.getQueryStats(sql); + qs.add(delta, start); + } + return sql; + } + /** * invoked when the connection receives the close request * Not used for now. Modified: tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TestSlowQueryReport.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TestSlowQueryReport.java?rev=787693&r1=787692&r2=787693&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TestSlowQueryReport.java (original) +++ tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TestSlowQueryReport.java Tue Jun 23 14:44:24 2009 @@ -24,7 +24,7 @@ import java.util.Map; import org.apache.tomcat.jdbc.pool.ConnectionPool; -import org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx; +import org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport; public class TestSlowQueryReport extends DefaultTestCase { @@ -36,20 +36,20 @@ int count = 3; this.init(); this.datasource.setMaxActive(1); - this.datasource.setJdbcInterceptors(SlowQueryReportJmx.class.getName()); + this.datasource.setJdbcInterceptors(SlowQueryReport.class.getName()+"(threshold=50)"); Connection con = this.datasource.getConnection(); - String slowSql = "select count(1) from test where val1 like 'ewqeq' and val2 = 'ewrre' and val3 = 'sdada' and val4 = 'dadada'"; + String slowSql = "select count(1) from test where val1 like 'ewq%eq' and val2 = 'ew%rre' and val3 = 'sda%da' and val4 = 'dad%ada'"; for (int i=0; i<count; i++) { Statement st = con.createStatement(); ResultSet rs = st.executeQuery(slowSql); rs.close(); st.close(); } - Map<String,SlowQueryReportJmx.QueryStats> map = SlowQueryReportJmx.getPoolStats(datasource.getPool().getName()); + Map<String,SlowQueryReport.QueryStats> map = SlowQueryReport.getPoolStats(datasource.getPool().getName()); assertNotNull(map); assertEquals(1,map.size()); String key = map.keySet().iterator().next(); - SlowQueryReportJmx.QueryStats stats = map.get(key); + SlowQueryReport.QueryStats stats = map.get(key); System.out.println("Stats:"+stats); for (int i=0; i<count; i++) { @@ -71,14 +71,14 @@ con.close(); tearDown(); //make sure we actually did clean up when the pool closed - assertNull(SlowQueryReportJmx.getPoolStats(pool.getName())); + assertNull(SlowQueryReport.getPoolStats(pool.getName())); } public void testFastSql() throws Exception { int count = 3; this.init(); this.datasource.setMaxActive(1); - this.datasource.setJdbcInterceptors(SlowQueryReportJmx.class.getName()); + this.datasource.setJdbcInterceptors(SlowQueryReport.class.getName()); Connection con = this.datasource.getConnection(); String slowSql = "select 1"; for (int i=0; i<count; i++) { @@ -87,20 +87,20 @@ rs.close(); st.close(); } - Map<String,SlowQueryReportJmx.QueryStats> map = SlowQueryReportJmx.getPoolStats(datasource.getPool().getName()); + Map<String,SlowQueryReport.QueryStats> map = SlowQueryReport.getPoolStats(datasource.getPool().getName()); assertNotNull(map); assertEquals(0,map.size()); ConnectionPool pool = datasource.getPool(); con.close(); tearDown(); - assertNull(SlowQueryReportJmx.getPoolStats(pool.getName())); + assertNull(SlowQueryReport.getPoolStats(pool.getName())); } public void testFailedSql() throws Exception { int count = 3; this.init(); this.datasource.setMaxActive(1); - this.datasource.setJdbcInterceptors(SlowQueryReportJmx.class.getName()); + this.datasource.setJdbcInterceptors(SlowQueryReport.class.getName()); Connection con = this.datasource.getConnection(); String slowSql = "select 1 from non_existent"; int exceptionCount = 0; @@ -115,16 +115,16 @@ st.close(); } - Map<String,SlowQueryReportJmx.QueryStats> map = SlowQueryReportJmx.getPoolStats(datasource.getPool().getName()); + Map<String,SlowQueryReport.QueryStats> map = SlowQueryReport.getPoolStats(datasource.getPool().getName()); assertNotNull(map); assertEquals(1,map.size()); ConnectionPool pool = datasource.getPool(); String key = map.keySet().iterator().next(); - SlowQueryReportJmx.QueryStats stats = map.get(key); + SlowQueryReport.QueryStats stats = map.get(key); System.out.println("Stats:"+stats); con.close(); tearDown(); - assertNull(SlowQueryReportJmx.getPoolStats(pool.getName())); + assertNull(SlowQueryReport.getPoolStats(pool.getName())); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org