class KeyedCPDSConnectionFactory extends java.lang.Object implements org.apache.commons.pool.KeyedPoolableObjectFactory, javax.sql.ConnectionEventListener, PooledConnectionManager
Modifier and Type | Field and Description |
---|---|
private javax.sql.ConnectionPoolDataSource |
_cpds |
private org.apache.commons.pool.KeyedObjectPool |
_pool |
private boolean |
_rollbackAfterValidation |
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 |
---|
KeyedCPDSConnectionFactory(javax.sql.ConnectionPoolDataSource cpds,
org.apache.commons.pool.KeyedObjectPool pool,
java.lang.String validationQuery)
Create a new KeyedPoolableConnectionFactory.
|
KeyedCPDSConnectionFactory(javax.sql.ConnectionPoolDataSource cpds,
org.apache.commons.pool.KeyedObjectPool pool,
java.lang.String validationQuery,
boolean rollbackAfterValidation)
Create a new KeyedPoolableConnectionFactory.
|
Modifier and Type | Method and Description |
---|---|
void |
activateObject(java.lang.Object key,
java.lang.Object obj) |
void |
closePool(java.lang.String username)
This implementation does not fully close the KeyedObjectPool, as
this would affect all users.
|
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 key,
java.lang.Object obj)
Closes the PooledConnection and stops listening for events from it.
|
org.apache.commons.pool.KeyedObjectPool |
getPool()
Returns the keyed 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(java.lang.Object key)
Creates a new
PooledConnectionAndInfo from the given UserPassKey . |
void |
passivateObject(java.lang.Object key,
java.lang.Object obj) |
void |
setPassword(java.lang.String password)
Does nothing.
|
boolean |
validateObject(java.lang.Object key,
java.lang.Object obj)
Validates a pooled connection.
|
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.KeyedObjectPool _pool
private final java.util.Map validatingMap
private final java.util.WeakHashMap pcMap
public KeyedCPDSConnectionFactory(javax.sql.ConnectionPoolDataSource cpds, org.apache.commons.pool.KeyedObjectPool pool, java.lang.String validationQuery)
cpds
- the ConnectionPoolDataSource from which to obtain PooledConnection'spool
- the {*link ObjectPool} in which to pool those {*link Connection}svalidationQuery
- a query to use to {*link #validateObject validate} {*link Connection}s.
Should return at least one row. May be nullpublic KeyedCPDSConnectionFactory(javax.sql.ConnectionPoolDataSource cpds, org.apache.commons.pool.KeyedObjectPool pool, java.lang.String validationQuery, boolean rollbackAfterValidation)
cpds
- the ConnectionPoolDataSource from which to obtain
PooledConnectionspool
- the KeyedObjectPool
in which to pool those
Connection
svalidationQuery
- a query to use to validate
Connection
s. Should return at least one row. May be nullrollbackAfterValidation
- whether a rollback should be issued after
validating
Connection
s.public org.apache.commons.pool.KeyedObjectPool getPool()
public java.lang.Object makeObject(java.lang.Object key) throws java.lang.Exception
PooledConnectionAndInfo
from the given UserPassKey
.makeObject
in interface org.apache.commons.pool.KeyedPoolableObjectFactory
key
- UserPassKey
containing user credentialsjava.sql.SQLException
- if the connection could not be created.java.lang.Exception
KeyedPoolableObjectFactory.makeObject(java.lang.Object)
public void destroyObject(java.lang.Object key, java.lang.Object obj) throws java.lang.Exception
destroyObject
in interface org.apache.commons.pool.KeyedPoolableObjectFactory
java.lang.Exception
public boolean validateObject(java.lang.Object key, java.lang.Object obj)
validateObject
in interface org.apache.commons.pool.KeyedPoolableObjectFactory
key
- ignoredobj
- PooledConnectionAndInfo
containing the connection to validatepublic void passivateObject(java.lang.Object key, java.lang.Object obj)
passivateObject
in interface org.apache.commons.pool.KeyedPoolableObjectFactory
public void activateObject(java.lang.Object key, java.lang.Object obj)
activateObject
in interface org.apache.commons.pool.KeyedPoolableObjectFactory
public void connectionClosed(javax.sql.ConnectionEvent event)
connectionClosed
in interface javax.sql.ConnectionEventListener
public void connectionErrorOccurred(javax.sql.ConnectionEvent event)
connectionErrorOccurred
in interface javax.sql.ConnectionEventListener
public void invalidate(javax.sql.PooledConnection pc) throws java.sql.SQLException
invalidate
in interface PooledConnectionManager
pc
- PooledConnection to be invalidatedjava.sql.SQLException
- if an SQL error occurs closing the connectionpublic void setPassword(java.lang.String password)
setPassword
in interface PooledConnectionManager
password
- password used when authenticating to the databasepublic void closePool(java.lang.String username) throws java.sql.SQLException
closePool
in interface PooledConnectionManager
username
- user namejava.sql.SQLException
- if an error occurs closing idle connections in the pool