public class PoolableConnectionFactory extends Object implements PooledObjectFactory<PoolableConnection>
PooledObjectFactory that creates
PoolableConnections.| Constructor and Description |
|---|
PoolableConnectionFactory(ConnectionFactory connFactory,
ObjectName dataSourceJmxName)
Create a new
PoolableConnectionFactory. |
| Modifier and Type | Method and Description |
|---|---|
void |
activateObject(PooledObject<PoolableConnection> p)
Reinitialize an instance to be returned by the pool.
|
void |
destroyObject(PooledObject<PoolableConnection> p)
Destroys an instance no longer needed by the pool.
|
protected boolean |
getCacheState() |
protected ConnectionFactory |
getConnectionFactory() |
Integer |
getDefaultQueryTimeout() |
protected int |
getMaxOpenPreparedStatements() |
ObjectPool<PoolableConnection> |
getPool()
Returns the
ObjectPool in which Connections are pooled. |
protected boolean |
getPoolStatements() |
protected void |
initializeConnection(Connection conn) |
boolean |
isEnableAutoCommitOnReturn() |
boolean |
isRollbackOnReturn() |
PooledObject<PoolableConnection> |
makeObject()
Create an instance that can be served by the pool and wrap it in a
PooledObject to be managed by the pool. |
void |
passivateObject(PooledObject<PoolableConnection> p)
Uninitialize an instance to be returned to the idle object pool.
|
void |
setCacheState(boolean cacheState) |
void |
setConnectionInitSql(Collection<String> connectionInitSqls)
Sets the SQL statements I use to initialize newly created
Connections. |
void |
setDefaultAutoCommit(Boolean defaultAutoCommit)
Sets the default "auto commit" setting for borrowed
Connections |
void |
setDefaultCatalog(String defaultCatalog)
Sets the default "catalog" setting for borrowed
Connections |
void |
setDefaultQueryTimeout(Integer defaultQueryTimeout) |
void |
setDefaultReadOnly(Boolean defaultReadOnly)
Sets the default "read only" setting for borrowed
Connections |
void |
setDefaultTransactionIsolation(int defaultTransactionIsolation)
Sets the default "Transaction Isolation" setting for borrowed
Connections |
void |
setEnableAutoCommitOnReturn(boolean enableAutoCommitOnReturn) |
void |
setMaxConnLifetimeMillis(long maxConnLifetimeMillis)
Sets the maximum lifetime in milliseconds of a connection after which the
connection will always fail activation, passivation and validation.
|
void |
setMaxOpenPrepatedStatements(int maxOpenPreparedStatements) |
void |
setPool(ObjectPool<PoolableConnection> pool)
Sets the
ObjectPool in which to pool Connections. |
void |
setPoolStatements(boolean poolStatements) |
void |
setRollbackOnReturn(boolean rollbackOnReturn) |
void |
setValidationQuery(String validationQuery)
Sets the query I use to
validate Connections. |
void |
setValidationQueryTimeout(int timeout)
Sets the validation query timeout, the amount of time, in seconds, that
connection validation will wait for a response from the database when
executing a validation query.
|
void |
validateConnection(PoolableConnection conn) |
boolean |
validateObject(PooledObject<PoolableConnection> p)
Ensures that the instance is safe to be returned by the pool.
|
public PoolableConnectionFactory(ConnectionFactory connFactory, ObjectName dataSourceJmxName)
PoolableConnectionFactory.connFactory - the ConnectionFactory from which to obtain
base Connectionspublic void setValidationQuery(String validationQuery)
validate Connections.
Should return at least one row. If not specified,
Connection.isValid(int) will be used to validate connections.validationQuery - a query to use to validate Connections.public void setValidationQueryTimeout(int timeout)
timeout - new validation query timeout value in secondspublic void setConnectionInitSql(Collection<String> connectionInitSqls)
Connections.
Using null turns off connection initialization.connectionInitSqls - SQL statement to initialize Connections.public void setPool(ObjectPool<PoolableConnection> pool)
ObjectPool in which to pool Connections.pool - the ObjectPool in which to pool those Connectionspublic ObjectPool<PoolableConnection> getPool()
ObjectPool in which Connections are pooled.public void setDefaultReadOnly(Boolean defaultReadOnly)
ConnectionsdefaultReadOnly - the default "read only" setting for borrowed Connectionspublic void setDefaultAutoCommit(Boolean defaultAutoCommit)
ConnectionsdefaultAutoCommit - the default "auto commit" setting for borrowed Connectionspublic void setDefaultTransactionIsolation(int defaultTransactionIsolation)
ConnectionsdefaultTransactionIsolation - the default "Transaction Isolation" setting for returned Connectionspublic void setDefaultCatalog(String defaultCatalog)
ConnectionsdefaultCatalog - the default "catalog" setting for borrowed Connectionspublic void setCacheState(boolean cacheState)
public void setPoolStatements(boolean poolStatements)
public void setMaxOpenPrepatedStatements(int maxOpenPreparedStatements)
public void setMaxConnLifetimeMillis(long maxConnLifetimeMillis)
public boolean isEnableAutoCommitOnReturn()
public void setEnableAutoCommitOnReturn(boolean enableAutoCommitOnReturn)
public boolean isRollbackOnReturn()
public void setRollbackOnReturn(boolean rollbackOnReturn)
public Integer getDefaultQueryTimeout()
public void setDefaultQueryTimeout(Integer defaultQueryTimeout)
public PooledObject<PoolableConnection> makeObject() throws Exception
PooledObjectFactoryPooledObject to be managed by the pool.makeObject in interface PooledObjectFactory<PoolableConnection>PooledObject wrapping an instance that can be served by the poolException - if there is a problem creating a new instance,
this will be propagated to the code requesting an object.protected void initializeConnection(Connection conn) throws SQLException
SQLExceptionpublic void destroyObject(PooledObject<PoolableConnection> p) throws Exception
PooledObjectFactory
It is important for implementations of this method to be aware that there
is no guarantee about what state obj will be in and the
implementation should be prepared to handle unexpected errors.
Also, an implementation must take in to consideration that instances lost to the garbage collector may never be destroyed.
destroyObject in interface PooledObjectFactory<PoolableConnection>p - a PooledObject wrapping the instance to be destroyedException - should be avoided as it may be swallowed by
the pool implementation.PooledObjectFactory.validateObject(org.apache.tomcat.dbcp.pool2.PooledObject<T>),
ObjectPool.invalidateObject(T)public boolean validateObject(PooledObject<PoolableConnection> p)
PooledObjectFactoryvalidateObject in interface PooledObjectFactory<PoolableConnection>p - a PooledObject wrapping the instance to be validatedfalse if obj is not valid and should
be dropped from the pool, true otherwise.public void validateConnection(PoolableConnection conn) throws SQLException
SQLExceptionpublic void passivateObject(PooledObject<PoolableConnection> p) throws Exception
PooledObjectFactorypassivateObject in interface PooledObjectFactory<PoolableConnection>p - a PooledObject wrapping the instance to be passivatedException - if there is a problem passivating obj,
this exception may be swallowed by the pool.PooledObjectFactory.destroyObject(org.apache.tomcat.dbcp.pool2.PooledObject<T>)public void activateObject(PooledObject<PoolableConnection> p) throws Exception
PooledObjectFactoryactivateObject in interface PooledObjectFactory<PoolableConnection>p - a PooledObject wrapping the instance to be activatedException - if there is a problem activating obj,
this exception may be swallowed by the pool.PooledObjectFactory.destroyObject(org.apache.tomcat.dbcp.pool2.PooledObject<T>)protected ConnectionFactory getConnectionFactory()
protected boolean getPoolStatements()
protected int getMaxOpenPreparedStatements()
protected boolean getCacheState()
Copyright © 2000-2015 Apache Software Foundation. All Rights Reserved.