org.apache.turbine.util.db.pool
Class ConnectionPool

java.lang.Object
  |
  +--org.apache.turbine.util.db.pool.ConnectionPool

public class ConnectionPool
extends java.lang.Object

This class implements a simple connection pooling scheme. Multiple pools are available through use of the PoolBrokerService.

Version:
$Id$
Author:
Costas Stergiou, Frank Y. Kim, Brett McLaughlin, Greg Ritter, Daniel L. Rall, Paul O'Leary, Magnús Þór Torfason, Jon S. Stevens

Constructor Summary
ConnectionPool()
          Deprecated. Use the constructor specifying db parameters.
ConnectionPool(int maxCons, long expiryTime)
          Deprecated. Use the constructor specifying db parameters.
ConnectionPool(java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String password)
          Creates a ConnectionPool with the default attributes.
ConnectionPool(java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String password, int maxCons, long expiryTime)
          Creates a ConnectionPool with the specified attributes.
 
Method Summary
 void decrementConnections()
          Decreases the count of connections in the pool and also calls notify().
protected  void finalize()
          Close any open connections when this object is garbage collected.
 DBConnection getConnection()
          Returns a connection that maintains a link to the pool it came from.
 DBConnection getConnection(java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String password)
          Deprecated. Database parameters should not be specified each time a DBConnection is fetched from the pool.
 DB getDB()
          Returns an instance of the database adapter associated with this pool.
 int getLoginTimeout()
           
 java.io.PrintWriter getLogWriter()
          The log writer is a character output stream to which all logging and tracing messages for this data source object instance will be printed.
 int getNbrAvailable()
          Returns the available connections in the pool
 int getNbrCheckedOut()
          Returns the checked out connections in the pool
protected  DBConnection getNewConnection()
          Returns a fresh connection to the database.
 javax.sql.PooledConnection getPooledConnection()
          Attempt to establish a database connection.
 javax.sql.PooledConnection getPooledConnection(java.lang.String user, java.lang.String password)
          Attempt to establish a database connection.
 int getTotalCount()
          Re turns the Total connections in the pool
 void releaseConnection(DBConnection dbconn)
          This method returns a connection to the pool, and must be called by the requestor when finished with the connection.
 void setLoginTimeout(int seconds)
          Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.
 void setLogWriter(java.io.PrintWriter out)
          The log writer is a character output stream to which all logging and tracing messages for this data source object instance will be printed.
 void shutdown()
          Close all connections to the database,
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionPool

public ConnectionPool()
Deprecated. Use the constructor specifying db parameters.

Creates a ConnectionPool with the default attributes.


ConnectionPool

public ConnectionPool(int maxCons,
                      long expiryTime)
Deprecated. Use the constructor specifying db parameters.

Creates a ConnectionPool with the specified attributes.

Parameters:
maxCons - The maximum number of connections for this pool.
expiryTime - The expiration time in milliseconds.

ConnectionPool

public ConnectionPool(java.lang.String driver,
                      java.lang.String url,
                      java.lang.String username,
                      java.lang.String password)
Creates a ConnectionPool with the default attributes.

Parameters:
driver - The driver type for this pool.
url - The url for this pool.
password - The password for this pool.

ConnectionPool

public ConnectionPool(java.lang.String driver,
                      java.lang.String url,
                      java.lang.String username,
                      java.lang.String password,
                      int maxCons,
                      long expiryTime)
Creates a ConnectionPool with the specified attributes.

Parameters:
driver - The driver type for this pool.
url - The url for this pool.
password - The password for this pool.
maxCons - The maximum number of connections for this pool.
expiryTime - The expiration time in milliseconds.
Method Detail

finalize

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

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable - Anything might happen...

getPooledConnection

public javax.sql.PooledConnection getPooledConnection()
                                               throws java.sql.SQLException
Attempt to establish a database connection.

java.sql.SQLException

getPooledConnection

public javax.sql.PooledConnection getPooledConnection(java.lang.String user,
                                                      java.lang.String password)
                                               throws java.sql.SQLException
Attempt to establish a database connection.

java.sql.SQLException

getConnection

public final DBConnection getConnection()
                                 throws java.lang.Exception
Returns a connection that maintains a link to the pool it came from.

Returns:
A database connection.
Throws:
java.lang.Exception

getConnection

public final DBConnection getConnection(java.lang.String driver,
                                        java.lang.String url,
                                        java.lang.String username,
                                        java.lang.String password)
                                 throws java.lang.Exception
Deprecated. Database parameters should not be specified each time a DBConnection is fetched from the pool.

This function is unsafe to use, since the user passed parameters that he has no way to know if are used.

Parameters:
driver - The fully-qualified name of the JDBC driver to use.
url - The URL of the database from which the connection is desired.
username - The name of the database user.
password - The password of the database user.
Returns:
A database connection.
Throws:
Exception.
java.lang.Exception

getDB

public DB getDB()
         throws java.lang.Exception
Returns an instance of the database adapter associated with this pool.

Returns:
The DB associated with this pool.
java.lang.Exception

getLogWriter

public java.io.PrintWriter getLogWriter()
                                 throws java.sql.SQLException
The log writer is a character output stream to which all logging and tracing messages for this data source object instance will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the java.sql.Drivermanager class. When a data source object is created the log writer is initially null, in other words, logging is disabled. If using JDBC2.0 dispatch to the ConnectionPoolDataSource

java.sql.SQLException

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
                  throws java.sql.SQLException
The log writer is a character output stream to which all logging and tracing messages for this data source object instance will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the java.sql.Drivermanager class. When a data source object is created the log writer is initially null, in other words, logging is disabled. If using JDBC2.0 dispatch to the ConnectionPoolDataSource

java.sql.SQLException

setLoginTimeout

public void setLoginTimeout(int seconds)
                     throws java.sql.SQLException
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise it specifies that there is no timeout. When a data source object is created the login timeout is initially zero.

java.sql.SQLException

getLoginTimeout

public int getLoginTimeout()
                    throws java.sql.SQLException
java.sql.SQLException

getNewConnection

protected DBConnection getNewConnection()
                                 throws java.lang.Exception
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.lang.Exception

releaseConnection

public void releaseConnection(DBConnection dbconn)
                       throws java.lang.Exception
This method returns a connection to the pool, and must be called by the requestor when finished with the connection.

Throws:
java.lang.Exception - Trouble releasing the connection.

shutdown

public void shutdown()
Close all connections to the database,


getTotalCount

public int getTotalCount()
Re turns the Total connections in the pool


getNbrAvailable

public int getNbrAvailable()
Returns the available connections in the pool


getNbrCheckedOut

public int getNbrCheckedOut()
Returns the checked out connections in the pool


decrementConnections

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



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