Class ProxyDriver

java.lang.Object
clazzfish.jdbc.ProxyDriver
All Implemented Interfaces:
Driver

public class ProxyDriver extends Object implements Driver
This JDBC driver acts like a proxy between PatternTesting and the real JDBC driver to be able to monitor JDBC access. It was inspired by the JAMonDriver of the JAMon framework.

This driver is registered for JDBC URLs beginning with "jdbc:proxy: ...". This prefix must follow the real driver path. E.g. if you want to use HSQL as database your URL make look like "jdbc:proxy:hsqldb:file:/tmp/oli".

Since:
0.9
Author:
oliver
  • Constructor Details

    • ProxyDriver

      public ProxyDriver()
  • Method Details

    • register

      public static void register()
      Registers the driver as JDBC driver.

      Because the implementation how the DriverManager finds the corresponding driver for a given JDBC-URL is a little stupid - it tries out all drivers if it can work with the URL. In case of problems (e.g. if the network is down) it throws the first SQLException it got and rethrow it - but this may be not the reason for the error message that the protocoll "jdbc:proxy:..." can not be understood.

      This is the reason why first all registered drivers are first deregistered and the registered again. This guarantees that the ProxyDriver is the first registered driver.

    • getRealURL

      public static String getRealURL(String jdbcURL)
      Gets the real JDBC URL of the underlying driver.
      Parameters:
      jdbcURL - the jdbc url, e.g. "jdbc:proxy:hsqldb:mem:testdb"
      Returns:
      the real driver name
    • getRealDriverName

      public static String getRealDriverName(String jdbcURL)
      Gets the real driver name of the underlying driver.
      Parameters:
      jdbcURL - the jdbc url, e.g. "jdbc:proxy:hsqldb:mem:testdb"
      Returns:
      the real driver name
    • getRealDriver

      public static Driver getRealDriver(String jdbcURL)
      Gets the real driver.
      Parameters:
      jdbcURL - the jdbc url, e.g. "jdbc:proxy:hsqldb:mem:testdb"
      Returns:
      the real driver
    • acceptsURL

      public boolean acceptsURL(String url)
      Retrieves whether the driver thinks that it can open a connection to the given URL. Accepted URLs are URLs beginning with:
      • jdbc:proxy:...
      • jdbc:jamon:... (if JAMon is in the classpath)
      Specified by:
      acceptsURL in interface Driver
      Parameters:
      url - the JDBC URL
      Returns:
      true, if successful
      See Also:
    • connect

      public Connection connect(String url, Properties info) throws SQLException
      Attempts to make a database connection to the given URL. The driver returns "null" if it realizes it is the wrong kind of driver to connect to the given URL. This will be common, as when the JDBC driver manager is asked to connect to a given URL it passes the URL to each loaded driver in turn.
      Specified by:
      connect in interface Driver
      Parameters:
      url - the url
      info - the info (e.g. user/password)
      Returns:
      the connection
      Throws:
      SQLException - the sQL exception
      See Also:
    • getMajorVersion

      public int getMajorVersion()
      Gets the major version.
      Specified by:
      getMajorVersion in interface Driver
      Returns:
      major version
    • getMinorVersion

      public int getMinorVersion()
      Gets the minor version.
      Specified by:
      getMinorVersion in interface Driver
      Returns:
      the minor version
    • getPropertyInfo

      public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException
      Gets the property info.
      Specified by:
      getPropertyInfo in interface Driver
      Parameters:
      url - the url
      info - the info
      Returns:
      the property info
      Throws:
      SQLException - the SQL exception
    • jdbcCompliant

      public boolean jdbcCompliant()
      Jdbc compliant.
      Specified by:
      jdbcCompliant in interface Driver
      Returns:
      true, if successful
    • getParentLogger

      public Logger getParentLogger() throws SQLFeatureNotSupportedException
      Gets the parent logger. This method is needed for the support of Java 5.
      Specified by:
      getParentLogger in interface Driver
      Returns:
      the parent logger
      Throws:
      SQLFeatureNotSupportedException - the SQL feature not supported exception
    • toString

      public String toString()
      Better toString implementation which supports logging and debugging.
      Overrides:
      toString in class Object
      Returns:
      the string
      See Also: