|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.turbine.util.db.pool.ConnectionPool
This class implements a simple connection pooling scheme. Multiple
pools are available through use of the PoolBrokerService
.
Field Summary | |
private long |
connectionAttemptsCounter
The number of times that an attempt to obtain a pooled connection has been made. |
private long |
connectionWaitTimeout
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
The ConnectionPoolDataSource if the driver is JDBC 2.0 compliant |
private DB |
db
The class containing the database specific info for connections in this pool (i.e. |
private long |
dbCheckFrequency
Thread sleep time between checks for database connectivity problems. |
private java.lang.String |
driver
The driver type for this pool. |
private long |
expiryTime
The amount of time in milliseconds that a connection will be pooled. |
private long |
maxConnectionAttempts
The number of times to attempt to obtain a pooled connection before giving up. |
private int |
maxConnections
The maximum number of database connections that can be created. |
private java.lang.String |
password
The password for this pool. |
private java.util.Stack |
pool
Pool containing database connections. |
private int |
totalConnections
The current number of database connections that have been created. |
private java.lang.String |
url
The url for this pool. |
private java.lang.String |
username
The user name for this pool. |
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. |
private DBConnection |
getInternalPooledConnection()
Gets a pooled database connection. |
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 |
private boolean |
isExpired(DBConnection connection)
Helper method which determines whether a connection has expired. |
private boolean |
isValid(DBConnection connection)
Determines if a connection is still valid. |
private DBConnection |
popConnection()
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. |
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 |
|
Field Detail |
private java.util.Stack pool
private java.lang.String driver
private java.lang.String url
private java.lang.String username
private java.lang.String password
private int totalConnections
private int maxConnections
private long expiryTime
private long maxConnectionAttempts
private long connectionAttemptsCounter
private long dbCheckFrequency
private DB db
private long connectionWaitTimeout
private javax.sql.ConnectionPoolDataSource cpds
Constructor Detail |
public ConnectionPool()
ConnectionPool
with the default
attributes.public ConnectionPool(int maxCons, long expiryTime)
ConnectionPool
with the specified
attributes.maxCons
- The maximum number of connections for this pool.expiryTime
- The expiration time in milliseconds.public ConnectionPool(java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String password)
ConnectionPool
with the default
attributes.driver
- The driver type for this pool.url
- The url for this pool.usernam
- The user name for this pool.password
- The password for this pool.public ConnectionPool(java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String password, int maxCons, long expiryTime)
ConnectionPool
with the specified
attributes.driver
- The driver type for this pool.url
- The url for this pool.usernam
- The user name 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 |
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- Anything might happen...public javax.sql.PooledConnection getPooledConnection() throws java.sql.SQLException
public javax.sql.PooledConnection getPooledConnection(java.lang.String user, java.lang.String password) throws java.sql.SQLException
public final DBConnection getConnection() throws java.lang.Exception
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.java.lang.Exception
- public final DBConnection getConnection(java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String password) throws java.lang.Exception
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.Exception.
- public DB getDB() throws java.lang.Exception
DB
associated with this pool.public java.io.PrintWriter getLogWriter() throws java.sql.SQLException
public void setLogWriter(java.io.PrintWriter out) throws java.sql.SQLException
public void setLoginTimeout(int seconds) throws java.sql.SQLException
public int getLoginTimeout() throws java.sql.SQLException
protected DBConnection getNewConnection() throws java.lang.Exception
driver
, and its connection
information by url
, username
, and
password
.java.lang.Exception
- private DBConnection popConnection() throws java.lang.Exception
java.lang.Exception
- private DBConnection getInternalPooledConnection() throws ConnectionWaitTimeoutException, java.lang.Exception
ConnectionWaitTimeoutException
- Wait time exceeded.java.lang.Exception
- No pooled connections.private boolean isExpired(DBConnection connection) throws java.lang.Exception
connection
- The connection to test.java.lang.Exception
- private boolean isValid(DBConnection connection) throws java.lang.Exception
connection
- The connection to test.java.lang.Exception
- public void releaseConnection(DBConnection dbconn) throws java.lang.Exception
connection
- The database connection to release.java.lang.Exception
- Trouble releasing the connection.public void shutdown()
public int getTotalCount()
public int getNbrAvailable()
public int getNbrCheckedOut()
public void decrementConnections()
notify()
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |