KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > p6spy > CountLogger


1 /**
2  * User: oliverm
3  * $Id: CountLogger.java,v 1.4 2003/12/23 09:55:03 brj Exp $
4  */

5 package org.apache.ojb.p6spy;
6
7 import com.p6spy.engine.logging.appender.P6Logger;
8 import com.p6spy.engine.logging.appender.FileLogger;
9
10
11 import org.apache.ojb.broker.util.logging.Logger;
12 import org.apache.ojb.broker.util.logging.LoggerFactory;
13
14 /**
15  * Use this class in order to log and count jdbc statements
16  *
17  * @author <a HREF="mailto:om@ppi.de">Oliver Matz</a>
18  * @version $Id: CountLogger.java,v 1.4 2003/12/23 09:55:03 brj Exp $
19  */

20 public class CountLogger extends FileLogger implements P6Logger
21 {
22   protected String JavaDoc lastEntry;
23   private final Logger logger = LoggerFactory.getLogger(this.getClass());
24
25   private static int countSQL;
26
27   public CountLogger()
28   {
29     logger.debug("start logging");
30   }
31
32   /**
33    * count the statements in case counting is enabled.
34    *
35    * @see com.p6spy.engine.logging.appender.FormattedLogger#logSQL
36    */

37   public void logSQL(int i, String JavaDoc s, long l, String JavaDoc s1, String JavaDoc s2, String JavaDoc s3)
38   {
39     if (s1.equals("resultset"))
40     {
41         // BRJ: p6spy workaround
42
// resultset cannot be excluded using p6spy properties
43
return;
44     }
45     
46     super.logSQL(i, s, l, s1, s2, s3);
47     countSQL++;
48     logger.info("sql: " + s1 + "|" + s3);
49   }
50
51   /**
52    * @return the number of statements issued so far.
53    */

54   public static int getSQLStatementCount()
55   {
56     return countSQL;
57   }
58 }
59
Popular Tags