EspressReport
v 6.0

quadbase.common.util.internal
Class ConnectionPool

java.lang.Object
  |
  +--quadbase.common.util.internal.ConnectionPool

public class ConnectionPool
extends java.lang.Object

A class that manages a set of open Connection objects. This class is used mainly by QbConnection. The logic of the ConnectionPool manager is as follows:
A Vector is used to hold a set of ConectionDetail objects. A ConnectionDetail object basically contains a variable that holds the underlying java.sql.Connection, and some information about the Connection itself (dburl, username, password) so that it may use these information to reconnect if necessary.
User of this class simply calls getConnection to get a QbConnection object. Depending on the state of the ConnectionPool, a new QbConnection (thus a java.sql.Connection) is created or an unused QbConnection object is fetched and returned from the pool.
If the current size of the pool (the number of Connections in the pool) is less than its capacity, then a new Qbconnection is created. If the forceAllocate flag is true when calling the getConnection method, a new QbConnection is created. If the size of the pool is the same as the capacity, then it will first look for an available (unused/free) and matching (same url, user, passwd) QbConnection to return to the user. If none is found, then it will allocate a new QbConnection object outside of the pool to return to the user. The QbConection that is allocated outside of the pool is not put inside the pool and will never be reused once it is closed.
Read the getConnection method for more details on how ConnectionPool works.


Constructor Summary
ConnectionPool()
          Allocates a new ConnectionPool.
 
Method Summary
 int capacity()
          the size limit of the pool
 void cleanup()
          Removes unused connection(s) from the pool.
 void close(QbConnection qbc, java.sql.Connection c)
          Close the connection.
 java.sql.Connection getConnection(java.lang.String url, java.util.Properties info, boolean forceAllocate)
          If the pool is not full, create a new QbCoonnection, put it in the pool and return the QbConnection to the user.
 java.sql.Connection removeAndGetConnection(java.sql.Connection c, java.lang.String url, java.util.Properties info)
          removes the specified connection from the pool, and get a new connection which must be a newly allocated connection.
 int size()
          The number of Connections in the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionPool

public ConnectionPool()
Allocates a new ConnectionPool.
Method Detail

capacity

public int capacity()
the size limit of the pool

size

public int size()
The number of Connections in the pool.

cleanup

public void cleanup()
Removes unused connection(s) from the pool. This method is called periodically by the CleanupThread. The reason for removing unused connections periodically is to ensure that Connections that might be timed out, due to long idle time, is not returned to the user when getConnection is called.

getConnection

public java.sql.Connection getConnection(java.lang.String url,
                                         java.util.Properties info,
                                         boolean forceAllocate)
                                  throws java.sql.SQLException
If the pool is not full, create a new QbCoonnection, put it in the pool and return the QbConnection to the user. If it is full, then create a new QbConnection and return it to the user. The QbConnection outside of the pool is never reused.
Parameters:
url - the url where the database instance resides
info - at least "user" and "password"

removeAndGetConnection

public java.sql.Connection removeAndGetConnection(java.sql.Connection c,
                                                  java.lang.String url,
                                                  java.util.Properties info)
                                           throws java.sql.SQLException
removes the specified connection from the pool, and get a new connection which must be a newly allocated connection.

close

public void close(QbConnection qbc,
                  java.sql.Connection c)
           throws java.sql.SQLException
Close the connection. In reality, if the QbConnection came from the pool, it simply decrease the use count of the ConnectionDetail object. If it is not from the pool, then call QbConnection.closeConnection().

EspressReport
v 6.0