org.apache.torque.pool
Class ConnectionPool

java.lang.Object
  extended byorg.apache.torque.pool.ConnectionPool
All Implemented Interfaces:
javax.sql.ConnectionEventListener, java.util.EventListener

Deprecated. as of version 3.1

class ConnectionPool
extends java.lang.Object
implements javax.sql.ConnectionEventListener

This class implements a simple connection pooling scheme.

Version:
$Id: ConnectionPool.java,v 1.27 2003/08/18 21:48:11 mpoeschl Exp $
Author:
Costas Stergiou, Frank Y. Kim, Brett McLaughlin, Greg Ritter, Daniel L. Rall, Paul O'Leary, Magnús Þór Torfason, Jon S. Stevens, John McNally, Henning P. Schmiedehausen

Nested Class Summary
protected  class ConnectionPool.Monitor
          Deprecated. This inner class monitors the PoolBrokerService.
 
Field Summary
private  long connectionWaitTimeout
          Deprecated. Amount of time a thread asking the pool for a cached connection will wait before timing out and throwing an error.
private  javax.sql.ConnectionPoolDataSource cpds
          Deprecated. The ConnectionPoolDataSource
static int DEFAULT_CONNECTION_WAIT_TIMEOUT
          Deprecated. Default Connect Wait Timeout: 10 Seconds
static int DEFAULT_EXPIRY_TIME
          Deprecated. Default Expiry Time for a pool: 1 hour
static int DEFAULT_MAX_CONNECTIONS
          Deprecated. Default maximum Number of connections from this pool: One
private  long expiryTime
          Deprecated. The amount of time in milliseconds that a connection will be pooled.
private static org.apache.commons.logging.Log log
          Deprecated. The logging logger.
private  int logInterval
          Deprecated. Interval (in seconds) that the monitor thread reports the pool state
private  int maxConnections
          Deprecated. The maximum number of database connections that can be created.
private  ConnectionPool.Monitor monitor
          Deprecated. Monitor thread reporting the pool state
private  java.lang.String password
          Deprecated. The password for this pool.
private  java.util.Stack pool
          Deprecated. Pool containing database connections.
private  java.util.Map timeStamps
          Deprecated. Keep track of when connections were created.
private  int totalConnections
          Deprecated. The current number of database connections that have been created.
private  java.lang.String url
          Deprecated. The url for this pool.
private  java.lang.String username
          Deprecated. The user name for this pool.
private  int waitCount
          Deprecated. Counter that keeps track of the number of threads that are in the wait state, waiting to aquire a connection.
 
Constructor Summary
(package private) ConnectionPool(javax.sql.ConnectionPoolDataSource cpds, java.lang.String username, java.lang.String password, int maxConnections, int expiryTime, int connectionWaitTimeout, int logInterval)
          Deprecated. Creates a ConnectionPool with the default attributes.
 
Method Summary
private  void closePooledConnection(javax.sql.PooledConnection pcon)
          Deprecated.  
 void connectionClosed(javax.sql.ConnectionEvent event)
          Deprecated. This will be called if the Connection returned by the getConnection method came from a PooledConnection, and the user calls the close() method of this connection object.
 void connectionErrorOccurred(javax.sql.ConnectionEvent event)
          Deprecated. If a fatal error occurs, close the underlying physical connection so as not to be returned in the future
(package private)  void decrementConnections()
          Deprecated. Decreases the count of connections in the pool and also calls notify().
protected  void finalize()
          Deprecated. Close any open connections when this object is garbage collected.
(package private)  javax.sql.PooledConnection getConnection(java.lang.String username, java.lang.String password)
          Deprecated. Returns a connection that maintains a link to the pool it came from.
private  javax.sql.PooledConnection getInternalPooledConnection()
          Deprecated. Gets a pooled database connection.
(package private)  int getNbrAvailable()
          Deprecated. Returns the available connections in the pool
(package private)  int getNbrCheckedOut()
          Deprecated. Returns the checked out connections in the pool
private  javax.sql.PooledConnection getNewConnection()
          Deprecated. Returns a fresh connection to the database.
(package private)  java.lang.String getPoolName()
          Deprecated. Get the name of the pool
(package private)  int getTotalCount()
          Deprecated. Returns the Total connections in the pool
private  boolean isExpired(javax.sql.PooledConnection pc)
          Deprecated. Helper method which determines whether a connection has expired.
private  boolean isValid(javax.sql.PooledConnection connection)
          Deprecated. Determines if a connection is still valid.
private  javax.sql.PooledConnection popConnection()
          Deprecated. Helper function that attempts to pop a connection off the pool's stack, handling the case where the popped connection has become invalid by creating a new connection.
private  void releaseConnection(javax.sql.PooledConnection pcon)
          Deprecated. This method returns a connection to the pool, and must be called by the requestor when finished with the connection.
(package private)  void shutdown()
          Deprecated. Close all connections to the database,
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_CONNECTIONS

public static final int DEFAULT_MAX_CONNECTIONS
Deprecated. 
Default maximum Number of connections from this pool: One

See Also:
Constant Field Values

DEFAULT_EXPIRY_TIME

public static final int DEFAULT_EXPIRY_TIME
Deprecated. 
Default Expiry Time for a pool: 1 hour

See Also:
Constant Field Values

DEFAULT_CONNECTION_WAIT_TIMEOUT

public static final int DEFAULT_CONNECTION_WAIT_TIMEOUT
Deprecated. 
Default Connect Wait Timeout: 10 Seconds

See Also:
Constant Field Values

pool

private java.util.Stack pool
Deprecated. 
Pool containing database connections.


url

private java.lang.String url
Deprecated. 
The url for this pool.


username

private java.lang.String username
Deprecated. 
The user name for this pool.


password

private java.lang.String password
Deprecated. 
The password for this pool.


totalConnections

private int totalConnections
Deprecated. 
The current number of database connections that have been created.


maxConnections

private int maxConnections
Deprecated. 
The maximum number of database connections that can be created.


expiryTime

private long expiryTime
Deprecated. 
The amount of time in milliseconds that a connection will be pooled.


waitCount

private int waitCount
Deprecated. 
Counter that keeps track of the number of threads that are in the wait state, waiting to aquire a connection.


log

private static org.apache.commons.logging.Log log
Deprecated. 
The logging logger.


logInterval

private int logInterval
Deprecated. 
Interval (in seconds) that the monitor thread reports the pool state


monitor

private ConnectionPool.Monitor monitor
Deprecated. 
Monitor thread reporting the pool state


connectionWaitTimeout

private long connectionWaitTimeout
Deprecated. 
Amount of time a thread asking the pool for a cached connection will wait before timing out and throwing an error.


cpds

private javax.sql.ConnectionPoolDataSource cpds
Deprecated. 
The ConnectionPoolDataSource


timeStamps

private java.util.Map timeStamps
Deprecated. 
Keep track of when connections were created. Keyed by a PooledConnection and value is a java.util.Date

Constructor Detail

ConnectionPool

ConnectionPool(javax.sql.ConnectionPoolDataSource cpds,
               java.lang.String username,
               java.lang.String password,
               int maxConnections,
               int expiryTime,
               int connectionWaitTimeout,
               int logInterval)
Deprecated. 
Creates a ConnectionPool with the default attributes.

Parameters:
cpds - The datasource
username - The user name for this pool.
password - The password for this pool.
maxConnections - max number of connections
expiryTime - connection expiry time
connectionWaitTimeout - timeout
logInterval - log interval
Method Detail

getConnection

final javax.sql.PooledConnection getConnection(java.lang.String username,
                                               java.lang.String password)
                                        throws java.sql.SQLException
Deprecated. 
Returns a connection that maintains a link to the pool it came from.

Parameters:
username - The name of the database user.
password - The password of the database user.
Returns:
A database connection.
Throws:
java.sql.SQLException - if there is aproblem with the db connection

getNewConnection

private javax.sql.PooledConnection getNewConnection()
                                             throws java.sql.SQLException
Deprecated. 
Returns a fresh connection to the database. The database type is specified by driver, and its connection information by url, username, and password.

Returns:
A database connection.
Throws:
java.sql.SQLException - if there is aproblem with the db connection

getInternalPooledConnection

private javax.sql.PooledConnection getInternalPooledConnection()
                                                        throws ConnectionWaitTimeoutException,
                                                               java.lang.Exception
Deprecated. 
Gets a pooled database connection.

Returns:
A database connection.
Throws:
ConnectionWaitTimeoutException - Wait time exceeded.
java.lang.Exception - No pooled connections.

popConnection

private javax.sql.PooledConnection popConnection()
                                          throws java.lang.Exception
Deprecated. 
Helper function that attempts to pop a connection off the pool's stack, handling the case where the popped connection has become invalid by creating a new connection.

Returns:
An existing or new database connection.
Throws:
java.lang.Exception - if the pool is empty

isExpired

private boolean isExpired(javax.sql.PooledConnection pc)
Deprecated. 
Helper method which determines whether a connection has expired.

Parameters:
pc - The connection to test.
Returns:
True if the connection is expired, false otherwise.

isValid

private boolean isValid(javax.sql.PooledConnection connection)
Deprecated. 
Determines if a connection is still valid.

Parameters:
connection - The connection to test.
Returns:
True if the connection is valid, false otherwise.

finalize

protected void finalize()
                 throws java.lang.Throwable
Deprecated. 
Close any open connections when this object is garbage collected.

Throws:
java.lang.Throwable - Anything might happen...

shutdown

void shutdown()
Deprecated. 
Close all connections to the database,


getTotalCount

int getTotalCount()
Deprecated. 
Returns the Total connections in the pool

Returns:
total connections in the pool

getNbrAvailable

int getNbrAvailable()
Deprecated. 
Returns the available connections in the pool

Returns:
number of available connections in the pool

getNbrCheckedOut

int getNbrCheckedOut()
Deprecated. 
Returns the checked out connections in the pool

Returns:
number of checked out connections in the pool

decrementConnections

void decrementConnections()
Deprecated. 
Decreases the count of connections in the pool and also calls notify().


getPoolName

java.lang.String getPoolName()
Deprecated. 
Get the name of the pool

Returns:
the name of the pool

connectionClosed

public void connectionClosed(javax.sql.ConnectionEvent event)
Deprecated. 
This will be called if the Connection returned by the getConnection method came from a PooledConnection, and the user calls the close() method of this connection object. What we need to do here is to release this PooledConnection from our pool...

Specified by:
connectionClosed in interface javax.sql.ConnectionEventListener
Parameters:
event - the connection event

connectionErrorOccurred

public void connectionErrorOccurred(javax.sql.ConnectionEvent event)
Deprecated. 
If a fatal error occurs, close the underlying physical connection so as not to be returned in the future

Specified by:
connectionErrorOccurred in interface javax.sql.ConnectionEventListener
Parameters:
event - the connection event

releaseConnection

private void releaseConnection(javax.sql.PooledConnection pcon)
Deprecated. 
This method returns a connection to the pool, and must be called by the requestor when finished with the connection.

Parameters:
pcon - The database connection to release.

closePooledConnection

private void closePooledConnection(javax.sql.PooledConnection pcon)
Deprecated. 
Parameters:
pcon - The database connection to close.


Copyright © 2000-2003 Apache Software Foundation. All Rights Reserved.