Tuesday, July 17, 2007
Integrate P6Spy with Spring
P6Spy is a tool to debug JDBC interaction with a database. It's a wrapper of all JDBC elements ( Connection, PreparedStatement, ResultSet... ) and it has a powerful feature in order to log all informations about those interactions.
JDBC wrapper is described in the "Java Performance Tuning" book of Jack Shirazi ( O'Reilly) in the chapter 16.
All elements wrappers have a constructor with the element to wrap. We can use it but there is another mode for datasource. This last mode must be used to wrap a datasource defined in an application server for example.
However since we can manage our objects ( beans ) in Spring ( and datasources too ), it's possible to add a P6Spy datasource and link it with the real datasource with constructor injection.
<?xml version="1.0" encoding="ISO-8859-1"?>
Moreover a p6spy.log file must be add to the classpath of the application to specify the location of the log file.
module.log=com.p6spy.engine.logging.P6LogFactory
The output can be graphically view with a tool like Iron Track SQL.
The advantages of this solution are the following: