org.javasimon.jdbc
Class Driver

java.lang.Object
  extended by org.javasimon.jdbc.Driver
All Implemented Interfaces:
Driver

public final class Driver
extends Object
implements Driver

Simon JDBC Proxy Driver.

An application should not use this class directly. The application (if standalone) should use DriverManager only. For example:

 Connection conn = DriverManager.getConnection("jdbc:simon:oracle:thin:...", "scott", "tiger");

Simon driver has following format of JDBC connection string:

jdbc:simon:<real driver conn string>;<param1>=<value1>;...
Simon driver recognizes two parameters: `

By default, there is no need to load any driver explicitly, because drivers are loaded automatically (since JDK 1.5) if they are in class path and jar have appropriate meta information (see DriverManager).

If this is not a case for any reason, you need to register Simon proxy driver at least. For real driver Simon proxy driver contains following procedure for find and register it:

  1. Simon proxy driver tries if there is registered driver for driver key word.
  2. If not, driver tries if there is real driver parameter in info properties and then registers it.
  3. If not, driver tries to find driver by key word within internal list of well known drivers and then registers it. For now, list contains default drivers for Oracle, PostgreSQL, Enterprise DB, H2, MySQL.
  4. If not, driver tries to find real driver param within connection string and then registers it.
  5. If not, getting new connection fails.
The safest way to get Simon proxy driver work is to load the drivers, the real one (i.e. oracle) and a Simon proxy driver explicitly. This can be done using Class.forName. To load the driver and open a database connection, use following code:
 Class.forName("oracle.jdbc.driver.OracleDriver");  // loads real driver
 Class.forName("org.javasimon.jdbc.Driver");  // loads Simon proxy driver
 Connection conn = DriverManager.getConnection(
      "jdbc:simon:oracle:thin:...", "scott", "tiger");

Since:
1.0
Version:
$Revision: 304 $ $Date: 2011-04-08 10:39:02 +0200 (Fri, 08 Apr 2011) $
Author:
Radovan Sninsky
See Also:
DriverManager.getConnection(String)

Nested Class Summary
(package private) static class Driver.Url
          Class Url represents Simon JDBC url.
 
Field Summary
private static String CONSOLE
          Name for the driver property enabling JDBC logging to console (System.err) using ConsoleHandler.
static String DEFAULT_PREFIX
          Default hierarchy prefix for Simon JDBC driver.
private  Properties drivers
           
private static String FORMAT
          Name for the driver property setting format for logs.
private static String LOGFILE
          Name for the driver property enabling JDBC logging to specified file.
private static String LOGGER
          Name for the driver property enabling JDBC logging to specified JDK14 logger (@{link java.util.logging.Logger}).
static String PREFIX
          Name for the driver property holding the hierarchy prefix given to JDBC Simons.
static String REAL_DRIVER
          Name for the property holding the real driver class value.
 
Constructor Summary
Driver()
          Class constructor.
 
Method Summary
 boolean acceptsURL(String url)
          
 Connection connect(String simonUrl, Properties info)
          Opens new Simon proxy driver connection associated with real connection to specified database.
 int getMajorVersion()
          
 int getMinorVersion()
          
 DriverPropertyInfo[] getPropertyInfo(String s, Properties properties)
          
private  Driver getRealDriver(Driver.Url url, Properties info)
          Tries to determine driver class, instantiate it and register if already not registered.
 boolean jdbcCompliant()
          
private  Driver registerDriver(String name)
          Registers real driver through DriverManager.
private  void registerLoggingCallback(Driver.Url url)
          Registers JDBC logging callback to Simon manager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REAL_DRIVER

public static final String REAL_DRIVER
Name for the property holding the real driver class value.

See Also:
Constant Field Values

DEFAULT_PREFIX

public static final String DEFAULT_PREFIX
Default hierarchy prefix for Simon JDBC driver. All Simons created by Simon JDBC driver without explicitly specified prefix are started with default prefix.

See Also:
Constant Field Values

PREFIX

public static final String PREFIX
Name for the driver property holding the hierarchy prefix given to JDBC Simons.

See Also:
Constant Field Values

LOGFILE

private static final String LOGFILE
Name for the driver property enabling JDBC logging to specified file.

See Also:
Constant Field Values

LOGGER

private static final String LOGGER
Name for the driver property enabling JDBC logging to specified JDK14 logger (@{link java.util.logging.Logger}).

See Also:
Constant Field Values

CONSOLE

private static final String CONSOLE
Name for the driver property enabling JDBC logging to console (System.err) using ConsoleHandler.

See Also:
Constant Field Values

FORMAT

private static final String FORMAT
Name for the driver property setting format for logs. There are two build-in formats: human and csv. Custom format is also possible by specifing clasname, must by derived from SimonFormatter.

See Also:
Constant Field Values

drivers

private final Properties drivers
Constructor Detail

Driver

public Driver()
Class constructor. It loads well known driver list from resource file drivers.properties.

Method Detail

connect

public Connection connect(String simonUrl,
                          Properties info)
                   throws SQLException
Opens new Simon proxy driver connection associated with real connection to specified database.

Specified by:
connect in interface Driver
Parameters:
simonUrl - JDBC connection string (i.e. jdbc:simon:h2:file:test)
info - properties for connection
Returns:
open connection to database or null if provided url is not accepted by this driver
Throws:
SQLException - if there is no real driver registered/recognized or opening real connection fails
See Also:
Driver

registerLoggingCallback

private void registerLoggingCallback(Driver.Url url)
Registers JDBC logging callback to Simon manager.

Parameters:
url - instance of Driver.Url
See Also:
SimonManager.callback(), Callback.addCallback(org.javasimon.Callback)

getRealDriver

private Driver getRealDriver(Driver.Url url,
                             Properties info)
                      throws SQLException
Tries to determine driver class, instantiate it and register if already not registered. For more detail look at Driver class javadoc.

Parameters:
url - instance of url object that represents url
info - parameters from connect(String, java.util.Properties) method
Returns:
instance of real driver
Throws:
SQLException - if real driver can't be determined or is not registerd

registerDriver

private Driver registerDriver(String name)
                       throws SQLException
Registers real driver through DriverManager.

Parameters:
name - real driver class name
Returns:
instance of registered real driver
Throws:
SQLException - if registration fails

acceptsURL

public boolean acceptsURL(String url)
                   throws SQLException

Specified by:
acceptsURL in interface Driver
Throws:
SQLException

getPropertyInfo

public DriverPropertyInfo[] getPropertyInfo(String s,
                                            Properties properties)
                                     throws SQLException

Specified by:
getPropertyInfo in interface Driver
Throws:
SQLException

getMajorVersion

public int getMajorVersion()

Specified by:
getMajorVersion in interface Driver

getMinorVersion

public int getMinorVersion()

Specified by:
getMinorVersion in interface Driver

jdbcCompliant

public boolean jdbcCompliant()

Specified by:
jdbcCompliant in interface Driver


Copyright © 2011. All Rights Reserved.