com.jimischopp.jdbcstatwrapper
Class JDBCStatWrapperMonitor

java.lang.Object
  extended by com.jimischopp.jdbcstatwrapper.JDBCStatWrapperMonitor

public class JDBCStatWrapperMonitor
extends java.lang.Object

A JDBC Tracing utility. This utility allows you to "wrap" all JDBC database activity, starting with the database driver, with an end to

The trace even prints out a stack trace of opened statements that were not closed, so you can see exactly where it gets opened.

This tool is most useful when you use unit-test based development, so that after each run of a service, you can log all the database activity that the service used, and then make the correct adjustments to your code for best performance.

To use it, all you need to do is: prepend "jdbc:statJdbcDriver:" to the beginning of your normal JDBC URL, and ensure that the StatDriver class is also loaded. For example, a typical scenario would be,

BEFORE:

        Class.forName("oracle.jdbc.driver.OracleDriver");
  Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//myhost:1521/orcl", "scott", "tiger"); 
 
AFTER:
  Class.forName("oracle.jdbc.driver.OracleDriver");
  Class.forName("com.jimischopp.jdbcstatwrapper.StatDriver");
  Connection conn = DriverManager.getConnection("jdbc:statJdbcDriver:oracle:thin:@//myhost:1521/orcl", "scott", "tiger");
 
Then when you wish to see the stats, simply call:
  JDBCStatWrapperMonitor.logStats();
 

Copyright 2007, James Schopp

Author:
James Schopp

Nested Class Summary
static class JDBCStatWrapperMonitor.QueryStats
          Internal class for maintaining the statistics.
 
Constructor Summary
JDBCStatWrapperMonitor()
           
 
Method Summary
static long getConnectionsClosed()
           
static long getConnectionsOpened()
           
static void incrementConnectionsClosed(int objectId)
           
static void incrementConnectionsOpened(int objectId)
           
static void incrementResultSetsClosed(java.lang.String query, java.util.SortedMap params, int objectId)
           
static void incrementResultSetsOpened(java.lang.String query, java.util.SortedMap params, int objectId)
           
static void incrementStatementsClosed(java.lang.String query, int objectId)
           
static void incrementStatementsOpened(java.lang.String query, int objectId)
           
static void incrementTimesExecuted(java.lang.String query, java.util.SortedMap params, long execTime, int objectId)
           
static void logStats()
           
static void setConnectionsClosed(long connectionsClosed)
           
static void setConnectionsOpened(long connectionsOpened)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCStatWrapperMonitor

public JDBCStatWrapperMonitor()
Method Detail

getConnectionsClosed

public static long getConnectionsClosed()

setConnectionsClosed

public static void setConnectionsClosed(long connectionsClosed)

getConnectionsOpened

public static long getConnectionsOpened()

setConnectionsOpened

public static void setConnectionsOpened(long connectionsOpened)

incrementTimesExecuted

public static void incrementTimesExecuted(java.lang.String query,
                                          java.util.SortedMap params,
                                          long execTime,
                                          int objectId)

incrementResultSetsOpened

public static void incrementResultSetsOpened(java.lang.String query,
                                             java.util.SortedMap params,
                                             int objectId)

incrementResultSetsClosed

public static void incrementResultSetsClosed(java.lang.String query,
                                             java.util.SortedMap params,
                                             int objectId)

incrementStatementsOpened

public static void incrementStatementsOpened(java.lang.String query,
                                             int objectId)

incrementStatementsClosed

public static void incrementStatementsClosed(java.lang.String query,
                                             int objectId)

incrementConnectionsOpened

public static void incrementConnectionsOpened(int objectId)

incrementConnectionsClosed

public static void incrementConnectionsClosed(int objectId)

logStats

public static void logStats()