Package | Class | Use | Tree | Deprecated | Index | Help
| log4jdbc3 1.1
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## net.sf.log4jdbc
Class DriverSpy

    java.lang.Object
      net.sf.log4jdbc.DriverSpy

All Implemented Interfaces:
  Driver

public class DriverSpy
extends Object
implements Driver

A JDBC driver which is a facade that delegates to one or more real underlying JDBC drivers. The driver will spy on any other JDBC driver that is loaded, simply by prepending `jdbc:log4` to the normal jdbc driver URL used by any other JDBC driver. The driver also loads several well known drivers at class load time, so that this driver can be "dropped in" to any java program that uses these drivers without making any code changes. The well known driver classes that are loaded are:

`

- oracle.jdbc.driver.OracleDriver
- com.sybase.jdbc2.jdbc.SybDriver
- net.sourceforge.jtds.jdbc.Driver
- com.microsoft.jdbc.sqlserver.SQLServerDriver
- weblogic.jdbc.sqlserver.SQLServerDriver
- com.informix.jdbc.IfxDriver
- org.apache.derby.jdbc.ClientDriver
- org.apache.derby.jdbc.EmbeddedDriver
- org.hsqldb.jdbcDriver
- org.h2.Driver

`

Additional drivers can be set via a system property: log4jdbc.drivers This can be either a single driver class name or a list of comma separated driver class names.

If any of the above driver classes cannot be loaded, the driver continues on without failing.

Note that the `getMajorVersion`, `getMinorVersion` and `jdbcCompliant` method calls attempt to delegate to the last underlying driver requested through any other call that accepts a JDBC URL.

This can cause unexpected behavior in certain circumstances. For example, if one of these 3 methods is called before any underlying driver has been established, then they will return default values that might not be correct in all situations. Similarly, if this spy driver is used to spy on more than one underlying driver concurrently, the values returned by these 3 method calls may change depending on what the last underlying driver used was at the time. This will not usually be a problem, since the driver is retrieved by it's URL from the DriverManager in the first place (thus establishing an underlying real driver), and in most applications their is only one database.

Author:
  Arthur Blake

Constructor Summary
`DriverSpy()` Default constructor.

Method Summary
`boolean` | `acceptsURL(String url)` Returns true if this is a `jdbc:log4` URL and if the URL is for an underlying driver that this DriverSpy can spy on.
`Connection` | `connect(String url, Properties info)` Get a Connection to the database from the underlying driver that this DriverSpy is spying on.
`int` | `getMajorVersion()` Get the major version of the driver.
`int` | `getMinorVersion()` Get the minor version of the driver.
`DriverPropertyInfo[]` | `getPropertyInfo(String url, Properties info)` Gets information about the possible properties for the underlying driver.
`boolean` | `jdbcCompliant()` Report whether the underlying driver is JDBC compliant.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### DriverSpy

    public DriverSpy()

  Default constructor.

Method Detail

### getMajorVersion

    public int getMajorVersion()

  Get the major version of the driver. This call will be delegated to the underlying driver that is being spied upon (if there is no underlying driver found, then 1 will be returned.)

  Specified by:
    `getMajorVersion` in interface `Driver`
  Returns:
    the major version of the JDBC driver.

### getMinorVersion

    public int getMinorVersion()

  Get the minor version of the driver. This call will be delegated to the underlying driver that is being spied upon (if there is no underlying driver found, then 0 will be returned.)

  Specified by:
    `getMinorVersion` in interface `Driver`
  Returns:
    the minor version of the JDBC driver.

### jdbcCompliant

    public boolean jdbcCompliant()

  Report whether the underlying driver is JDBC compliant. If there is no underlying driver, false will be returned, because the driver cannot actually do any work without an underlying driver.

  Specified by:
    `jdbcCompliant` in interface `Driver`
  Returns:
    `true` if the underlying driver is JDBC Compliant; `false` otherwise.

### acceptsURL

    public boolean acceptsURL(String url)
                       throws SQLException

  Returns true if this is a `jdbc:log4` URL and if the URL is for an underlying driver that this DriverSpy can spy on.

  Specified by:
    `acceptsURL` in interface `Driver`
  Throws:
    `SQLException` - if a database access error occurs
  Parameters:
    `url` - JDBC URL.
  Returns:
    true if this Driver can handle the URL.

### connect

    public Connection connect(String url,
                              Properties info)
                       throws SQLException

  Get a Connection to the database from the underlying driver that this DriverSpy is spying on. If logging is not enabled, an actual Connection to the database returned. If logging is enabled, a ConnectionSpy object which wraps the real Connection is returned.

  Specified by:
    `connect` in interface `Driver`
  Throws:
    `SQLException` - if a database access error occurs
  Parameters:
    `url` - JDBC connection URL .
    `info` - a list of arbitrary string tag/value pairs as connection arguments. Normally at least a "user" and "password" property should be included.
  Returns:
    a `Connection` object that represents a connection to the URL.

### getPropertyInfo

    public DriverPropertyInfo[] getPropertyInfo(String url,
                                                Properties info)
                                         throws SQLException

  Gets information about the possible properties for the underlying driver.

  Specified by:
    `getPropertyInfo` in interface `Driver`
  Throws:
    `SQLException` - if a database access error occurs
  Parameters:
    `url` - the URL of the database to which to connect
    `info` - a proposed list of tag/value pairs that will be sent on connect open
  Returns:
    an array of `DriverPropertyInfo` objects describing possible properties. This array may be an empty array if no properties are required.

Package | Class | Use | Tree | Deprecated | Index | Help
| log4jdbc3 1.1
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD