Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

ConnectionPool Class Reference

#include <ConnectionPool.h>

Inheritance diagram for ConnectionPool

Inheritance graph

[legend]
List of all members.

Public Methods

virtual ~ConnectionPool ()
 Returns the alias for this pool. More...

const nsAReadableString& getAlias ()
 Returns the alias for this pool. More...

int getNumRequests ()
 Returns the number of times a Connection has been checked out from the pool. More...

int getNumWaits ()
 Returns the number of times a thread has had to block on wait() as a result of all PooledConnections being in use. More...

int getNumCheckoutTimeouts ()
 Returns the number of times a Connection has been closed by the reapIdleConnections() method due to being checked out for longer than the checkoutSeconds interval. More...

int getMaxConn ()
 Returns the maximum number of connections this pool can open. More...

int size ()
 Returns the current number of Connections in the pool. More...

void reapIdleConnections ()
 Check all connections to make sure they haven't: 1) gone idle for too long
2) been checked out by a thread for too long (cursor leak).
More...


void removeAllConnections ()
 Removes all connections from the pool and calls close() on them. More...

void removeConnection (Connection* pConn)
ConnectiongetConnection ()
 Returns a connection for the pool. More...

virtual ConnectionnewConnection () = 0
void returnConnection (Connection* pConn)
virtual ConnectionPool* buildPool (const nsAReadableString& alias) = 0

Public Attributes

nsString m_url
nsString m_username
nsString m_password
nsString m_alias

Protected Methods

 ConnectionPool (const nsAReadableString& alias, const nsAReadableString& url, const nsAReadableString& username, const nsAReadableString& password, int maxConn, int timeoutSeconds, int checkoutSeconds, int maxCheckout = 0)
 Creates a Connection pool. More...

void destroy ()

Private Types

typedef std::vector<Connection*> vectorConnection
typedef std::queue<Thread*> queueThread

Private Attributes

vectorConnection m_connVector
queueThread m_waitingThreads
int m_maxConn
int m_timeoutSeconds
int m_checkoutSeconds
int m_numCheckoutTimeout
int m_numRequests
int m_numWaits
int m_maxCheckout
PRLock* m_mPool

Member Typedef Documentation

typedef std::queue<Thread*> ConnectionPool::queueThread [private]
 

Definition at line 25 of file ConnectionPool.h.

typedef std::vector<Connection*> ConnectionPool::vectorConnection [private]
 

Definition at line 22 of file ConnectionPool.h.


Constructor & Destructor Documentation

ConnectionPool::ConnectionPool ( const nsAReadableString & alias,
const nsAReadableString & url,
const nsAReadableString & username,
const nsAReadableString & password,
int maxConn,
int timeoutSeconds,
int checkoutSeconds,
int maxCheckout = 0 ) [protected]
 

Creates a Connection pool.

Parameters:
alias   Name of the pool
url   JDBC URL to connect to
username   JDBC username to connect as
password   username's password in the database
maxConn   Maximum number of connections to open; When this limit is reached, threads requesting a connection are queued until a connection becomes available
timeoutSeconds   Maximum number of seconds a Connection can go unused before it is closed
checkoutSeconds   Maximum number of seconds a Thread can checkout a Connection before it is closed and returned to the pool. This is a protection against the Thread dying and leaving the Connection checked out indefinately
maxCheckout   If this is greater than 0, the number of times a Connection may be checked out before it is closed. Used as a safeguard against cursor leak, which occurs if you don't call ResultSet.close() and Statement.close()

Definition at line 51 of file ConnectionPool.cpp.

ConnectionPool::~ConnectionPool ( ) [virtual]
 

Returns the alias for this pool.

This name is defined by the user in the constructor

Definition at line 84 of file ConnectionPool.cpp.


Member Function Documentation

virtual ConnectionPool* ConnectionPool::buildPool ( const nsAReadableString & alias ) [pure virtual]
 

Reimplemented in ConnectionPoolDB2, ConnectionPoolODBC, ConnectionPoolOracle, and ConnectionPoolSybase.

void ConnectionPool::destroy ( ) [protected]
 

Definition at line 72 of file ConnectionPool.cpp.

Referenced by ~ConnectionPool(), and ConnectionPoolODBC::~ConnectionPoolODBC().

const nsAReadableString & ConnectionPool::getAlias ( )
 

Returns the alias for this pool.

This name is defined by the user in the constructor

Definition at line 93 of file ConnectionPool.cpp.

Referenced by ConnectionPoolManager::addAlias(), and ConnectionPoolManager::getPool().

Connection * ConnectionPool::getConnection ( )
 

Returns a connection for the pool.

There are three ways this can happen:

  1. If a connection in the pool is free, it is locked and returned immediately
  2. If no connections are free, but the pool is not full, a new Connection is opened and returned
  3. If no connections are free, and the pool is full, the thread calls wait() and blocks until a connection is returned

Definition at line 253 of file ConnectionPool.cpp.

Referenced by ConnectionPoolODBC::buildPool(), ConnectionPoolManager::connect(), and px7xpdbc::getConnection().

int ConnectionPool::getMaxConn ( )
 

Returns the maximum number of connections this pool can open.

Definition at line 140 of file ConnectionPool.cpp.

int ConnectionPool::getNumCheckoutTimeouts ( )
 

Returns the number of times a Connection has been closed by the reapIdleConnections() method due to being checked out for longer than the checkoutSeconds interval.

If this is greater than 0 it means that you either have queries that take longer to execute than the checkoutSeconds interval allows, or it means that you are forgetting to call conn.close() somewhere in your application. Both conditions are undesirable, but they have different solutions. In the latter case either tune your query to execute more quickly, or increase the checkoutSeconds parameter to the pool. In the former case you simply need to find the code that calls DriverManager.getConnection() but not conn.close()

Definition at line 132 of file ConnectionPool.cpp.

int ConnectionPool::getNumRequests ( )
 

Returns the number of times a Connection has been checked out from the pool.

Definition at line 102 of file ConnectionPool.cpp.

int ConnectionPool::getNumWaits ( )
 

Returns the number of times a thread has had to block on wait() as a result of all PooledConnections being in use.

Useful diagnostic tool to see if your pool needs more nodes (which could require a database license upgrade if you're running Oracle for instance)

Definition at line 113 of file ConnectionPool.cpp.

virtual Connection* ConnectionPool::newConnection ( ) [pure virtual]
 

Reimplemented in ConnectionPoolDB2, ConnectionPoolODBC, ConnectionPoolOracle, and ConnectionPoolSybase.

Referenced by getConnection().

void ConnectionPool::reapIdleConnections ( )
 

Check all connections to make sure they haven't: 1) gone idle for too long
2) been checked out by a thread for too long (cursor leak).

Definition at line 159 of file ConnectionPool.cpp.

Referenced by ConnectionPoolManager::run().

void ConnectionPool::removeAllConnections ( )
 

Removes all connections from the pool and calls close() on them.

It squelches any SQLExceptions that might results from close(). That's probably not ideal.

Definition at line 189 of file ConnectionPool.cpp.

Referenced by ConnectionPoolManager::removeAlias().

void ConnectionPool::removeConnection ( Connection * pConn )
 

Definition at line 203 of file ConnectionPool.cpp.

Referenced by reapIdleConnections(), removeAllConnections(), and returnConnection().

void ConnectionPool::returnConnection ( Connection * pConn )
 

Definition at line 292 of file ConnectionPool.cpp.

Referenced by Connection::close().

int ConnectionPool::size ( )
 

Returns the current number of Connections in the pool.

Definition at line 148 of file ConnectionPool.cpp.


Member Data Documentation

nsString ConnectionPool::m_alias
 

Definition at line 32 of file ConnectionPool.h.

int ConnectionPool::m_checkoutSeconds [private]
 

Definition at line 35 of file ConnectionPool.h.

vectorConnection ConnectionPool::m_connVector [private]
 

Definition at line 23 of file ConnectionPool.h.

PRLock * ConnectionPool::m_mPool [private]
 

Definition at line 37 of file ConnectionPool.h.

int ConnectionPool::m_maxCheckout [private]
 

Definition at line 36 of file ConnectionPool.h.

int ConnectionPool::m_maxConn [private]
 

Definition at line 35 of file ConnectionPool.h.

int ConnectionPool::m_numCheckoutTimeout [private]
 

Definition at line 35 of file ConnectionPool.h.

int ConnectionPool::m_numRequests [private]
 

Definition at line 36 of file ConnectionPool.h.

int ConnectionPool::m_numWaits [private]
 

Definition at line 36 of file ConnectionPool.h.

nsString ConnectionPool::m_password
 

Definition at line 31 of file ConnectionPool.h.

int ConnectionPool::m_timeoutSeconds [private]
 

Definition at line 35 of file ConnectionPool.h.

nsString ConnectionPool::m_url
 

Definition at line 29 of file ConnectionPool.h.

nsString ConnectionPool::m_username
 

Definition at line 30 of file ConnectionPool.h.

queueThread ConnectionPool::m_waitingThreads [private]
 

Definition at line 26 of file ConnectionPool.h.


The documentation for this class was generated from the following files:
Generated at Tue Sep 12 16:29:48 2000 by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000