com.nec.tdd.tools.dbMapper
Class ConnectionPoolDataSource

java.lang.Object
  |
  +--com.nec.tdd.tools.dbMapper.ConnectionPoolDataSource
All Implemented Interfaces:
DataSource

public class ConnectionPoolDataSource
extends java.lang.Object
implements DataSource

Default database connection manager implementation provided by database module.

ConnectionPoolDataSource manages a pool of PoolableDBConnection objects to efficiently manage database resources. Pooling allows concurrent database operations in multi-threaded applications, with added bonus of DBConnection statement caching.

A number of PoolableDBConnection objects are created in advance (specified by initialCapacity property) and placed in pool. Once a user is done with a PoolableDBConnection, it returned to the pool (instead of closing and creating all connections and statements again).

The maxCapacity parameter defines an upper bound on number of opened connections at any time by this connection manager. If all the pooled connections for this connection manager are in use, the ConnectionPoolDataSource attempts to establish more database connection based on capacityIncrement property. In any case, the maxCapacity property is always honored. Some useful ConnectionPoolDataSource settings: 1. Fixed size (n) pool (all connections created at init time): initialCapacity=n; capacityIncrement=0; maxCapacity>=n 2. Growing pool with upper bound (n): initialCapacity>=0; capacityIncrement>=1; maxCapacity=n 3. Infinite growing pool : initialCapacity>=0; capacityIncrement>=1; maxCapacity=0


Constructor Summary
ConnectionPoolDataSource(DBConnectionInfo dbInfoBean)
          Constructs a ConnectionPoolDataSource object with given database connection information.
ConnectionPoolDataSource(DBConnectionInfo dbInfoBean, int initialCapacity, int capacityIncrement)
          Constructs a ConnectionPoolDataSource object with given database connection information, initialCapacity and capacityIncrement.
ConnectionPoolDataSource(DBConnectionInfo dbInfoBean, int initialCapacity, int capacityIncrement, int maxCapacity)
          Constructs a ConnectionPoolDataSource object with given database connection information, and pool parameters (initialCapacity, capacityIncrement and maxCapacity).
 
Method Summary
 void destroy()
          Destry the connection manager.
protected  void finalize()
          Override Object's finalize method to shutdown all the database connections in pool during garbage collection.
 DBConnection getConnection()
          Get a DBConnection from the pool associated with this connection manager.
 void releaseConnection(DBConnection conn)
          Method to release an previously acquired PoolableDBConnection to the pool.
 java.lang.String toString()
          Returns string representation of ConnectionPoolDataSource, containing the string representation of pool and of each poolable item contained in the pool.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConnectionPoolDataSource

public ConnectionPoolDataSource(DBConnectionInfo dbInfoBean)
                         throws java.lang.Exception
Constructs a ConnectionPoolDataSource object with given database connection information. This method attempts to create and initialize a pool of PoolableDBConnection with default initialCapacity, capacityIncrement and maxCapacity values. It also registers/loads JDBC driver class given in DBConnectionInfo.
Parameters:
dbInfoBean - database connection information (JDBC url, driver name, user & password).
Throws:
java.lang.Exception - if a database access error occurs.

ConnectionPoolDataSource

public ConnectionPoolDataSource(DBConnectionInfo dbInfoBean,
                                int initialCapacity,
                                int capacityIncrement)
                         throws java.lang.Exception
Constructs a ConnectionPoolDataSource object with given database connection information, initialCapacity and capacityIncrement. This method attempts to create and initialize a pool of PoolableDBConnection with these parameters and default maxCapacity.
It also registers/loads JDBC driver class given in DBConnectionInfo.
Parameters:
dbInfoBean - database connection information (JDBC url, driver name, user & password).
initialCapacity - the initial capacity of the pool.
capacityIncrement - the amount by which the capacity is increased when the pool overflows.
Throws:
java.lang.Exception - if a database access error occurs.

ConnectionPoolDataSource

public ConnectionPoolDataSource(DBConnectionInfo dbInfoBean,
                                int initialCapacity,
                                int capacityIncrement,
                                int maxCapacity)
                         throws java.lang.Exception
Constructs a ConnectionPoolDataSource object with given database connection information, and pool parameters (initialCapacity, capacityIncrement and maxCapacity). This method attempts to create and initialize a pool of PoolableDBConnection with these parameters.
It also registers/loads JDBC driver class given in DBConnectionInfo.
Parameters:
dbInfoBean - database connection information (JDBC url, driver name, user & password).
initialCapacity - the initial capacity of the pool.
capacityIncrement - the amount by which the capacity is increased when the pool overflows.
maxCapacity - maximum number of connections opened at a time by this connection manager. A <=0 value is treated as unlimited connections.
Throws:
java.lang.Exception - if a database access error occurs.
Method Detail

finalize

protected void finalize()
                 throws java.lang.Exception
Override Object's finalize method to shutdown all the database connections in pool during garbage collection.
Overrides:
finalize in class java.lang.Object

getConnection

public DBConnection getConnection()
Get a DBConnection from the pool associated with this connection manager.
Specified by:
getConnection in interface DataSource
Returns:
A DBConnection from the pool if available. Null if all connections are already in use for this connection manager.

releaseConnection

public void releaseConnection(DBConnection conn)
Method to release an previously acquired PoolableDBConnection to the pool.
Specified by:
releaseConnection in interface DataSource
Parameters:
conn - DBConnection to be released.

destroy

public void destroy()
Destry the connection manager. Close all PoolableDBConnection object.

toString

public java.lang.String toString()
Returns string representation of ConnectionPoolDataSource, containing the string representation of pool and of each poolable item contained in the pool.
Overrides:
toString in class java.lang.Object