All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sdi.wap.ConnectionPoolManager

java.lang.Object
   |
   +----com.sdi.wap.ConnectionPoolManager

public class ConnectionPoolManager
extends Object
bjc: http://www.WebDevelopersJournal.com/columns/connection_pool.html This class is a Singleton that provides access to one or many connection pools defined in a Property file. A client gets access to the single instance through the static getInstance() method and can then check-out and check-in connections from a pool. When the client shuts down it should call the release() method to close all open connections and do other clean up.


Variable Index

 o clients
 o drivers
 o instance
 o log
 o pools

Constructor Index

 o ConnectionPoolManager()
A private constructor since this is a Singleton

Method Index

 o createPools(Properties)
Creates instances of DBConnectionPool based on the properties.
 o freeConnection(String, Connection)
Returns a connection to the named pool.
 o freeConnections(String)
Insert the method's description here.
 o getConnection(String)
Returns an open connection.
 o getConnection(String, long)
Returns an open connection.
 o getInstance()
Returns the single instance, creating one if it's the first time this method is called.
 o init()
Loads properties and initializes the instance with its values.
 o loadDrivers(Properties)
Loads and registers all JDBC drivers.
 o log(String)
Writes a message to the log file.
 o log(Throwable, String)
Writes a message with an Exception to the log file.
 o maxConnections(String)
Insert the method's description here.
 o release()
Closes all open connections and deregisters all drivers.
 o usedConnections(String)
Insert the method's description here.

Variables

 o instance
 private static ConnectionPoolManager instance
 o clients
 private static int clients
 o drivers
 private Vector drivers
 o log
 private PrintWriter log
 o pools
 private Hashtable pools

Constructors

 o ConnectionPoolManager
 private ConnectionPoolManager()
A private constructor since this is a Singleton

Methods

 o createPools
 private void createPools(Properties props)
Creates instances of DBConnectionPool based on the properties. A DBConnectionPool can be defined with the following properties:
 <poolname>.url					The JDBC URL for the database
 <poolname>.user				A database user (optional)
 <poolname>.password		A database user password (if user specified)
 <poolname>.maxconn			The maximal number of connections (optional)
 

Parameters:
props - The connection pool properties
 o freeConnection
 public void freeConnection(String name,
                            Connection con)
Returns a connection to the named pool.

Parameters:
name - The pool name as defined in the properties file
con - The Connection
 o freeConnections
 public static int freeConnections(String name)
Insert the method's description here. Creation date: (02/20/00 20:19:49)

 o getConnection
 public Connection getConnection(String name)
Returns an open connection. If no one is available, and the max number of connections has not been reached, a new connection is created.

Parameters:
name - The pool name as defined in the properties file
Returns:
Connection The connection or null
 o getConnection
 public Connection getConnection(String name,
                                 long time)
Returns an open connection. If no one is available, and the max number of connections has not been reached, a new connection is created. If the max number has been reached, waits until one is available or the specified time has elapsed.

Parameters:
name - The pool name as defined in the properties file
time - The number of milliseconds to wait
Returns:
Connection The connection or null
 o getInstance
 public static synchronized ConnectionPoolManager getInstance()
Returns the single instance, creating one if it's the first time this method is called.

Returns:
DBConnectionManager The single instance.
 o init
 private void init()
Loads properties and initializes the instance with its values.

 o loadDrivers
 private void loadDrivers(Properties props)
Loads and registers all JDBC drivers. This is done by the DBConnectionManager, as opposed to the DBConnectionPool, since many pools may share the same driver.

Parameters:
props - The connection pool properties
 o log
 private void log(String msg)
Writes a message to the log file.

 o log
 private void log(Throwable e,
                  String msg)
Writes a message with an Exception to the log file.

 o maxConnections
 public static int maxConnections(String name)
Insert the method's description here. Creation date: (02/20/00 20:19:49)

 o release
 public synchronized void release()
Closes all open connections and deregisters all drivers.

 o usedConnections
 public static int usedConnections(String name)
Insert the method's description here. Creation date: (02/20/00 20:19:49)


All Packages  Class Hierarchy  This Package  Previous  Next  Index