class CPDSConnectionFactory extends java.lang.Object implements org.apache.commons.pool.PoolableObjectFactory, javax.sql.ConnectionEventListener, PooledConnectionManager
PoolableObjectFactory that creates
PoolableConnections.| Modifier and Type | Field and Description |
|---|---|
private javax.sql.ConnectionPoolDataSource |
_cpds |
private java.lang.String |
_password |
private org.apache.commons.pool.ObjectPool |
_pool |
private boolean |
_rollbackAfterValidation |
private java.lang.String |
_username |
private java.lang.String |
_validationQuery |
private static java.lang.String |
NO_KEY_MESSAGE |
private java.util.WeakHashMap |
pcMap
Map of PooledConnectionAndInfo instances
|
private java.util.Map |
validatingMap
Map of PooledConnections for which close events are ignored.
|
| Constructor and Description |
|---|
CPDSConnectionFactory(javax.sql.ConnectionPoolDataSource cpds,
org.apache.commons.pool.ObjectPool pool,
java.lang.String validationQuery,
boolean rollbackAfterValidation,
java.lang.String username,
java.lang.String password)
Create a new PoolableConnectionFactory.
|
CPDSConnectionFactory(javax.sql.ConnectionPoolDataSource cpds,
org.apache.commons.pool.ObjectPool pool,
java.lang.String validationQuery,
java.lang.String username,
java.lang.String password)
Create a new PoolableConnectionFactory.
|
| Modifier and Type | Method and Description |
|---|---|
void |
activateObject(java.lang.Object obj) |
void |
closePool(java.lang.String username)
Verifies that the username matches the user whose connections are being managed by this
factory and closes the pool if this is the case; otherwise does nothing.
|
void |
connectionClosed(javax.sql.ConnectionEvent event)
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)
If a fatal error occurs, close the underlying physical connection so as
not to be returned in the future
|
void |
destroyObject(java.lang.Object obj)
Closes the PooledConnection and stops listening for events from it.
|
org.apache.commons.pool.ObjectPool |
getPool()
Returns the object pool used to pool connections created by this factory.
|
void |
invalidate(javax.sql.PooledConnection pc)
Invalidates the PooledConnection in the pool.
|
java.lang.Object |
makeObject() |
void |
passivateObject(java.lang.Object obj) |
void |
setPassword(java.lang.String password)
Sets the database password used when creating new connections.
|
boolean |
validateObject(java.lang.Object obj) |
private static final java.lang.String NO_KEY_MESSAGE
private final javax.sql.ConnectionPoolDataSource _cpds
private final java.lang.String _validationQuery
private final boolean _rollbackAfterValidation
private final org.apache.commons.pool.ObjectPool _pool
private java.lang.String _username
private java.lang.String _password
private final java.util.Map validatingMap
private final java.util.WeakHashMap pcMap
public CPDSConnectionFactory(javax.sql.ConnectionPoolDataSource cpds,
org.apache.commons.pool.ObjectPool pool,
java.lang.String validationQuery,
java.lang.String username,
java.lang.String password)
cpds - the ConnectionPoolDataSource from which to obtain
PooledConnection'spool - the ObjectPool in which to pool those
ConnectionsvalidationQuery - a query to use to validate
Connections. Should return at least one row. May be
nullusername - password - public CPDSConnectionFactory(javax.sql.ConnectionPoolDataSource cpds,
org.apache.commons.pool.ObjectPool pool,
java.lang.String validationQuery,
boolean rollbackAfterValidation,
java.lang.String username,
java.lang.String password)
cpds - the ConnectionPoolDataSource from which to obtain
PooledConnection'spool - the ObjectPool in which to pool those ConnectionsvalidationQuery - a query to use to validate Connections. Should return at least one row.
May be nullrollbackAfterValidation - whether a rollback should be issued
after validating Connections.username - password - public org.apache.commons.pool.ObjectPool getPool()
public java.lang.Object makeObject()
makeObject in interface org.apache.commons.pool.PoolableObjectFactorypublic void destroyObject(java.lang.Object obj)
throws java.lang.Exception
destroyObject in interface org.apache.commons.pool.PoolableObjectFactoryjava.lang.Exceptionpublic boolean validateObject(java.lang.Object obj)
validateObject in interface org.apache.commons.pool.PoolableObjectFactorypublic void passivateObject(java.lang.Object obj)
passivateObject in interface org.apache.commons.pool.PoolableObjectFactorypublic void activateObject(java.lang.Object obj)
activateObject in interface org.apache.commons.pool.PoolableObjectFactorypublic void connectionClosed(javax.sql.ConnectionEvent event)
connectionClosed in interface javax.sql.ConnectionEventListenerpublic void connectionErrorOccurred(javax.sql.ConnectionEvent event)
connectionErrorOccurred in interface javax.sql.ConnectionEventListenerpublic void invalidate(javax.sql.PooledConnection pc)
throws java.sql.SQLException
invalidate in interface PooledConnectionManagerpc - PooledConnection to be invalidatedjava.sql.SQLException - if an SQL error occurs closing the connectionpublic void setPassword(java.lang.String password)
setPassword in interface PooledConnectionManagerpassword - new passwordpublic void closePool(java.lang.String username)
throws java.sql.SQLException
closePool in interface PooledConnectionManagerusername - user namejava.sql.SQLException - if an error occurs closing idle connections in the pool