org.objectweb.cjdbc.controller.connection
Class DriverManager

java.lang.Object
  extended byorg.objectweb.cjdbc.controller.connection.DriverManager

public class DriverManager
extends java.lang.Object

This class defines a DriverManager. In contrast to java.sql.DriverManager this class allows to use Drivers with the same name but with different versions, if no drivername is used it is a wrapper around java.sql.DriverManager.

Version:
1.0
Author:
Emmanuel Cecchet

Field Summary
private static java.util.Set defaultDrivers
          Driver class names read from default drivers, without driverPath
(package private) static Trace logger
          Logger instance.
private static java.util.Map namedDrivers
          We keep a reference to already loaded named drivers.
 
Constructor Summary
DriverManager()
           
 
Method Summary
static java.io.File convertToAbsolutePath(java.lang.String pathName)
          convert a path into an absolute path if the path is already an absolute path, it is just returned otherwise a relative path is considered to be relative to the drivers directory
static java.sql.Connection getConnection(java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String driverPathName, java.lang.String driverClassName)
          Attempts to establish a connection to the given database URL.
private static java.sql.Connection getConnectionForDriver(java.lang.String url, java.lang.String user, java.lang.String password, java.sql.Driver driver)
           
private static java.io.File getDriversDir()
           
private static java.sql.Driver loadDriver(java.io.File path, java.lang.String driverClassName)
           
static void loadDriverClass(java.lang.String driverClassName)
          Load the driver class
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

static Trace logger
Logger instance.


defaultDrivers

private static java.util.Set defaultDrivers
Driver class names read from default drivers, without driverPath


namedDrivers

private static java.util.Map namedDrivers
We keep a reference to already loaded named drivers. Each named driver has been loaded with a separate classloader.

Constructor Detail

DriverManager

public DriverManager()
Method Detail

getConnection

public static java.sql.Connection getConnection(java.lang.String url,
                                                java.lang.String user,
                                                java.lang.String password,
                                                java.lang.String driverPathName,
                                                java.lang.String driverClassName)
                                         throws java.sql.SQLException
Attempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.

Parameters:
url - a database url of the form jdbc:subprotocol:subname
user - the database user on whose behalf the connection is being made
password - the user's password
driverPathName - the path where the driver classes are located, null if default directory
driverClassName - the class name of the driver
Returns:
a connection to the URL
Throws:
java.sql.SQLException - if a database access error occurs

loadDriverClass

public static void loadDriverClass(java.lang.String driverClassName)
                            throws java.lang.ClassNotFoundException
Load the driver class

Parameters:
driverClassName - the class name of the driver
Throws:
java.lang.ClassNotFoundException - if the class could not be found

convertToAbsolutePath

public static java.io.File convertToAbsolutePath(java.lang.String pathName)
                                          throws java.io.IOException
convert a path into an absolute path if the path is already an absolute path, it is just returned otherwise a relative path is considered to be relative to the drivers directory

Parameters:
pathName - the relativ or absolute path
Returns:
the converted path
Throws:
java.io.IOException - if the converted path does not exist

getDriversDir

private static java.io.File getDriversDir()
                                   throws java.io.IOException
Throws:
java.io.IOException

getConnectionForDriver

private static java.sql.Connection getConnectionForDriver(java.lang.String url,
                                                          java.lang.String user,
                                                          java.lang.String password,
                                                          java.sql.Driver driver)
                                                   throws java.sql.SQLException
Throws:
java.sql.SQLException

loadDriver

private static java.sql.Driver loadDriver(java.io.File path,
                                          java.lang.String driverClassName)
                                   throws java.lang.ClassNotFoundException,
                                          java.lang.InstantiationException,
                                          java.lang.IllegalAccessException
Throws:
java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.