net.sourceforge.esw.util.database
Class DBConnectionPoolManager

java.lang.Object
  |
  +--net.sourceforge.esw.util.database.DBConnectionPoolManager

public class DBConnectionPoolManager
extends java.lang.Object

A Factory for the creation and access of DBConnectionPool instances.

This is a Singleton design pattern.

The DBConnectionPoolManager is used to create and get access to DBConnectionPool instances. Access to an DBConnectionPool instance is provided through the getPool methods.

A DBConnectionPool instance has a URL and, if required, a UserID that can be used to uniquely identify the source data that the connection represents. Some databases allow the UserID and/or Password to be specified in the URL. Some do not require secure access, so neither the UserID or Password is required to use a DBConnectionPool instance.

A DBConnectionPool instance does not initialize the database driver directly, but the DBConnectionPoolManager has a method to initialize the driver for you called initializeDriver( aDriver ). You can also follow the JDBC standard method for registering your JDBC driver in the Java VM using the DriverManager. You should only need to register a unique driver once during a Java VM session.

Examples:

    DBConnectionPoolManager.initializeDriver( aDriver );
    DBConnectionPool pl = DBConnectionPoolManager.getInstance().getPool( getURL(),
                                                                        getUserID() );
 


Field Summary
protected  java.util.HashMap dbPools
          Contains the availiable DBConnectionPool instances.
protected static DBConnectionPoolManager instance
          The singleton reference.
 
Constructor Summary
protected DBConnectionPoolManager()
          Creates a new DBConnectionPoolManager instance.
 
Method Summary
 void addPool(DBConnectionPool aPool)
          Adds the specified DBConnectionPool instance to this DBConnectionPoolManager instance.
static DBConnectionPoolManager getInstance()
          Returns the singleton DBConnectionPoolManager instance.
 DBConnectionPool getPool(java.lang.String aURL)
          Returns the pool of connections for the given JDBC URL.
 DBConnectionPool getPool(java.lang.String aURL, java.lang.String aUserID)
          Returns the pool of connections for the given JDBC URL and user identifier.
static void initializeDriver(java.lang.String aDriver)
          Initializes the named driver with the JDBC DriverManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dbPools

protected java.util.HashMap dbPools
Contains the availiable DBConnectionPool instances.

instance

protected static DBConnectionPoolManager instance
The singleton reference.
Constructor Detail

DBConnectionPoolManager

protected DBConnectionPoolManager()
Creates a new DBConnectionPoolManager instance.
Method Detail

getInstance

public static DBConnectionPoolManager getInstance()
Returns the singleton DBConnectionPoolManager instance.

getPool

public DBConnectionPool getPool(java.lang.String aURL)
                         throws java.sql.SQLException
Returns the pool of connections for the given JDBC URL. If the requested DBConnectionPool instance does not exist, one will be created and returned.
Parameters:
aURL - The URL for which to get the pool of connections.
Throws:
java.sql.SQLException - If an error occurs during creation of the DBConnectionPool instance.

getPool

public DBConnectionPool getPool(java.lang.String aURL,
                                java.lang.String aUserID)
                         throws java.sql.SQLException
Returns the pool of connections for the given JDBC URL and user identifier. If the requested DBConnectionPool instance does not exist, one will be created and returned.
Parameters:
aURL - The URL for which to get the pool of connections.
aUserID - The userID for which to get the pool of connections.
Throws:
java.sql.SQLException - If an error occurs during creation of the DBConnectionPool instance.

addPool

public void addPool(DBConnectionPool aPool)
Adds the specified DBConnectionPool instance to this DBConnectionPoolManager instance. The DBConnectionPool instances are keyed on their URL+UserID combination, since that should be a unique key for each unique data source. The added DBConnectionPool instance can be then referenced by a call to the getPool() method with the correct values for URL and UserID.
Parameters:
aPool - The DBConnectionPool instance to add.

initializeDriver

public static void initializeDriver(java.lang.String aDriver)
                             throws java.sql.SQLException
Initializes the named driver with the JDBC DriverManager.
Parameters:
aDriver - The driver to initialize.
Throws:
java.sql.SQLException - If an error occurs during initialization of the driver either because the class name is invalid, or because the driver had a problem talking to the database.


Copyright 2002 Free Software Foundation. All Rights Reserved.