public class PoolableConnectionFactory extends java.lang.Object implements PooledObjectFactory<PoolableConnection>
PooledObjectFactory that creates PoolableConnections.| Constructor and Description |
|---|
PoolableConnectionFactory(ConnectionFactory connFactory,
javax.management.ObjectName dataSourceJmxObjectName)
Creates a new
PoolableConnectionFactory. |
| Modifier and Type | Method and Description |
|---|---|
void |
activateObject(PooledObject<PoolableConnection> p)
Reinitializes an instance to be returned by the pool.
|
void |
destroyObject(PooledObject<PoolableConnection> p)
Destroys an instance no longer needed by the pool.
|
boolean |
getCacheState() |
ConnectionFactory |
getConnectionFactory() |
protected java.util.concurrent.atomic.AtomicLong |
getConnectionIndex() |
java.util.Collection<java.lang.String> |
getConnectionInitSqls() |
javax.management.ObjectName |
getDataSourceJmxName() |
javax.management.ObjectName |
getDataSourceJmxObjectName() |
java.lang.Boolean |
getDefaultAutoCommit() |
java.lang.String |
getDefaultCatalog() |
java.lang.Integer |
getDefaultQueryTimeout() |
java.lang.Integer |
getDefaultQueryTimeoutSeconds() |
java.lang.Boolean |
getDefaultReadOnly() |
java.lang.String |
getDefaultSchema() |
int |
getDefaultTransactionIsolation() |
java.util.Collection<java.lang.String> |
getDisconnectionSqlCodes()
SQL_STATE codes considered to signal fatal conditions.
|
long |
getMaxConnLifetimeMillis() |
protected int |
getMaxOpenPreparedStatements() |
ObjectPool<PoolableConnection> |
getPool()
Returns the
ObjectPool in which Connections are pooled. |
boolean |
getPoolStatements() |
java.lang.String |
getValidationQuery() |
int |
getValidationQueryTimeoutSeconds() |
protected void |
initializeConnection(java.sql.Connection conn) |
boolean |
isAutoCommitOnReturn() |
boolean |
isEnableAutoCommitOnReturn()
Deprecated.
|
boolean |
isFastFailValidation()
True means that validation will fail immediately for connections that have previously thrown SQLExceptions with
SQL_STATE indicating fatal disconnection errors.
|
boolean |
isRollbackOnReturn() |
PooledObject<PoolableConnection> |
makeObject()
Creates 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)
Uninitializes an instance to be returned to the idle object pool.
|
void |
setAutoCommitOnReturn(boolean autoCommitOnReturn) |
void |
setCacheState(boolean cacheState) |
void |
setConnectionInitSql(java.util.Collection<java.lang.String> connectionInitSqls)
Sets the SQL statements I use to initialize newly created
Connections. |
void |
setDefaultAutoCommit(java.lang.Boolean defaultAutoCommit)
Sets the default "auto commit" setting for borrowed
Connections |
void |
setDefaultCatalog(java.lang.String defaultCatalog)
Sets the default "catalog" setting for borrowed
Connections |
void |
setDefaultQueryTimeout(java.lang.Integer defaultQueryTimeoutSeconds) |
void |
setDefaultReadOnly(java.lang.Boolean defaultReadOnly)
Sets the default "read only" setting for borrowed
Connections |
void |
setDefaultSchema(java.lang.String defaultSchema)
Sets the default "schema" setting for borrowed
Connections |
void |
setDefaultTransactionIsolation(int defaultTransactionIsolation)
Sets the default "Transaction Isolation" setting for borrowed
Connections |
void |
setDisconnectionSqlCodes(java.util.Collection<java.lang.String> disconnectionSqlCodes) |
void |
setEnableAutoCommitOnReturn(boolean autoCommitOnReturn)
Deprecated.
|
void |
setFastFailValidation(boolean fastFailValidation) |
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 |
setMaxOpenPreparedStatements(int maxOpenPreparedStatements)
Sets the maximum number of open prepared statements.
|
void |
setMaxOpenPrepatedStatements(int maxOpenPreparedStatements)
Deprecated.
|
void |
setPool(ObjectPool<PoolableConnection> pool)
Sets the
ObjectPool in which to pool Connections. |
void |
setPoolStatements(boolean poolStatements) |
void |
setRollbackOnReturn(boolean rollbackOnReturn) |
void |
setValidationQuery(java.lang.String validationQuery)
Sets the query I use to
validate Connections. |
void |
setValidationQueryTimeout(int validationQueryTimeoutSeconds)
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, javax.management.ObjectName dataSourceJmxObjectName)
PoolableConnectionFactory.connFactory - the ConnectionFactory from which to obtain base ConnectionsdataSourceJmxObjectName - The JMX object name, may be null.public void activateObject(PooledObject<PoolableConnection> p) throws java.lang.Exception
PooledObjectFactoryactivateObject in interface PooledObjectFactory<PoolableConnection>p - a PooledObject wrapping the instance to be activatedjava.lang.Exception - if there is a problem activating obj,
this exception may be swallowed by the pool.PooledObjectFactory.destroyObject(org.apache.tomcat.dbcp.pool2.PooledObject<T>)public void destroyObject(PooledObject<PoolableConnection> p) throws java.lang.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 destroyedjava.lang.Exception - 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 getCacheState()
public ConnectionFactory getConnectionFactory()
protected java.util.concurrent.atomic.AtomicLong getConnectionIndex()
public java.util.Collection<java.lang.String> getConnectionInitSqls()
public javax.management.ObjectName getDataSourceJmxName()
public javax.management.ObjectName getDataSourceJmxObjectName()
public java.lang.Boolean getDefaultAutoCommit()
public java.lang.String getDefaultCatalog()
public java.lang.Integer getDefaultQueryTimeout()
public java.lang.Integer getDefaultQueryTimeoutSeconds()
public java.lang.Boolean getDefaultReadOnly()
public java.lang.String getDefaultSchema()
public int getDefaultTransactionIsolation()
public java.util.Collection<java.lang.String> getDisconnectionSqlCodes()
Overrides the defaults in Utils.DISCONNECTION_SQL_CODES (plus anything starting with
Utils.DISCONNECTION_SQL_CODE_PREFIX). If this property is non-null and isFastFailValidation() is
true, whenever connections created by this factory generate exceptions with SQL_STATE codes in this list,
they will be marked as "fatally disconnected" and subsequent validations will fail fast (no attempt at isValid or
validation query).
If isFastFailValidation() is false setting this property has no effect.
public long getMaxConnLifetimeMillis()
protected int getMaxOpenPreparedStatements()
public ObjectPool<PoolableConnection> getPool()
ObjectPool in which Connections are pooled.public boolean getPoolStatements()
public java.lang.String getValidationQuery()
public int getValidationQueryTimeoutSeconds()
protected void initializeConnection(java.sql.Connection conn)
throws java.sql.SQLException
java.sql.SQLExceptionpublic boolean isAutoCommitOnReturn()
@Deprecated public boolean isEnableAutoCommitOnReturn()
isAutoCommitOnReturn().public boolean isFastFailValidation()
setDisconnectionSqlCodes(Collection)public boolean isRollbackOnReturn()
public PooledObject<PoolableConnection> makeObject() throws java.lang.Exception
PooledObjectFactoryPooledObject to be managed by the pool.makeObject in interface PooledObjectFactory<PoolableConnection>PooledObject wrapping an instance that can be served by the pooljava.lang.Exception - if there is a problem creating a new instance,
this will be propagated to the code requesting an object.public void passivateObject(PooledObject<PoolableConnection> p) throws java.lang.Exception
PooledObjectFactorypassivateObject in interface PooledObjectFactory<PoolableConnection>p - a PooledObject wrapping the instance to be passivatedjava.lang.Exception - 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 setAutoCommitOnReturn(boolean autoCommitOnReturn)
public void setCacheState(boolean cacheState)
public void setConnectionInitSql(java.util.Collection<java.lang.String> connectionInitSqls)
Connections. Using null turns off
connection initialization.connectionInitSqls - SQL statement to initialize Connections.public void setDefaultAutoCommit(java.lang.Boolean defaultAutoCommit)
ConnectionsdefaultAutoCommit - the default "auto commit" setting for borrowed Connectionspublic void setDefaultCatalog(java.lang.String defaultCatalog)
ConnectionsdefaultCatalog - the default "catalog" setting for borrowed Connectionspublic void setDefaultQueryTimeout(java.lang.Integer defaultQueryTimeoutSeconds)
public void setDefaultReadOnly(java.lang.Boolean defaultReadOnly)
ConnectionsdefaultReadOnly - the default "read only" setting for borrowed Connectionspublic void setDefaultSchema(java.lang.String defaultSchema)
ConnectionsdefaultSchema - the default "schema" setting for borrowed Connectionspublic void setDefaultTransactionIsolation(int defaultTransactionIsolation)
ConnectionsdefaultTransactionIsolation - the default "Transaction Isolation" setting for returned Connectionspublic void setDisconnectionSqlCodes(java.util.Collection<java.lang.String> disconnectionSqlCodes)
disconnectionSqlCodes - The disconnection SQL codes.getDisconnectionSqlCodes()@Deprecated public void setEnableAutoCommitOnReturn(boolean autoCommitOnReturn)
setAutoCommitOnReturn(boolean).autoCommitOnReturn - Whether to auto-commit on return.public void setFastFailValidation(boolean fastFailValidation)
fastFailValidation - true means connections created by this factory will fast fail validationisFastFailValidation()public void setMaxConnLifetimeMillis(long maxConnLifetimeMillis)
maxConnLifetimeMillis - The maximum lifetime in milliseconds.public void setMaxOpenPreparedStatements(int maxOpenPreparedStatements)
maxOpenPreparedStatements - The maximum number of open prepared statements.@Deprecated public void setMaxOpenPrepatedStatements(int maxOpenPreparedStatements)
setMaxOpenPreparedStatements(int).maxOpenPreparedStatements - The maximum number of open prepared statements.public void setPool(ObjectPool<PoolableConnection> pool)
ObjectPool in which to pool Connections.pool - the ObjectPool in which to pool those Connectionspublic void setPoolStatements(boolean poolStatements)
public void setRollbackOnReturn(boolean rollbackOnReturn)
public void setValidationQuery(java.lang.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 validationQueryTimeoutSeconds)
validationQueryTimeoutSeconds - new validation query timeout value in secondspublic void validateConnection(PoolableConnection conn) throws java.sql.SQLException
java.sql.SQLExceptionpublic 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.Copyright © 2000-2019 Apache Software Foundation. All Rights Reserved.