01: /**
02: * User: oliverm
03: * $Id: CountLogger.java,v 1.4 2003/12/23 09:55:03 brj Exp $
04: */package org.apache.ojb.p6spy;
05:
06: import com.p6spy.engine.logging.appender.P6Logger;
07: import com.p6spy.engine.logging.appender.FileLogger;
08:
09: import org.apache.ojb.broker.util.logging.Logger;
10: import org.apache.ojb.broker.util.logging.LoggerFactory;
11:
12: /**
13: * Use this class in order to log and count jdbc statements
14: *
15: * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
16: * @version $Id: CountLogger.java,v 1.4 2003/12/23 09:55:03 brj Exp $
17: */
18: public class CountLogger extends FileLogger implements P6Logger {
19: protected String lastEntry;
20: private final Logger logger = LoggerFactory.getLogger(this
21: .getClass());
22:
23: private static int countSQL;
24:
25: public CountLogger() {
26: logger.debug("start logging");
27: }
28:
29: /**
30: * count the statements in case counting is enabled.
31: *
32: * @see com.p6spy.engine.logging.appender.FormattedLogger#logSQL
33: */
34: public void logSQL(int i, String s, long l, String s1, String s2,
35: String s3) {
36: if (s1.equals("resultset")) {
37: // BRJ: p6spy workaround
38: // resultset cannot be excluded using p6spy properties
39: return;
40: }
41:
42: super .logSQL(i, s, l, s1, s2, s3);
43: countSQL++;
44: logger.info("sql: " + s1 + "|" + s3);
45: }
46:
47: /**
48: * @return the number of statements issued so far.
49: */
50: public static int getSQLStatementCount() {
51: return countSQL;
52: }
53: }
|