The P6Spy Framework

P6Spy provides a pluggable framework for applications that intercept and optionally manipulate database statements. This framework supports any application that uses JDBC. All of this is done in a seamless manner that requires no change to the client application and enables the application to be installed with minimal effort. P6Spy packages several useful applications with the framework including P6Log, P6Outage, and P6Cache.

The P6Spy framework works by starting with a loader driver (figure 1.1) that loads the functionality that the end user has chosen to enable. This is accomplished by using "stackable drivers". Each module is a self-contained database driver that passes through database requests to the next stacked driver at which time each driver is allowed to handle the request in turn.

 

figure 1.1

At runtime only the enabled modules are loaded, causing only the required code to be executed. If no modules are selected, then only the real database driver is loaded, effectively incurring zero overhead. Figure 1.2 shows an example of how this might work with actual modules.

figure 1.2

 

Further, the framework is designed to make it easy to build modules, and to make the installation as simple as possible for the end user. To achieve this the framework provides a series of core wrapper classes that wrap every JDBC statement. The developer is only required to the extend those classes and override the specific methods they wish to intercept. Not only does this provide fast development, but as JDBC provides additional methods, only the core classes need to implement wrappers, while the modules themselves will automatically inherit the changes to the core classes.

 

Building the Source

To build the source you must first download the GNU RegEx engine and download the Jakarta RegEx engine. Copy the RegEx .jar files to the lib/ directory which is a subdirectory of your main directory (the directory with the source code). You must also download and install Jakarta Ant. You then just type ant in the directory with the build.xml file and the code will build. The following are useful targets:

  • [no target] creates a p6spy.jar file in the dist/ directory
  • [clean] cleans the directory of build files and tool generated backup files
  • [release] creates the Javadocs, the war file, and all distribution .zip and .jar files
  • [test] runs the standard Junit tests (see notes below)
  • [perform] runs the performance specific JUnit tests (see notes below)

To run the Junit tests, first you must download and install JUnit. Once that is complete you must edit the P6Test.properties file and specify two databases. The configuration is setup for Oracle and MySQL (though you will have to change the Oracle URL at a minimum). You must also copy the vendor database JDBC drivers .jar files of the two databases you use into the lib/ directory.