public class PoolableConnectionFactory extends Object implements PooledObjectFactory<PoolableConnection>
PooledObjectFactory
that creates PoolableConnection
s.Constructor and Description |
---|
PoolableConnectionFactory(ConnectionFactory connFactory,
ObjectName dataSourceJmxObjectName)
Creates a new
PoolableConnectionFactory . |
Modifier and Type | Method and Description |
---|---|
void |
activateObject(PooledObject<PoolableConnection> p) |
void |
destroyObject(PooledObject<PoolableConnection> p) |
boolean |
getCacheState() |
ConnectionFactory |
getConnectionFactory() |
protected AtomicLong |
getConnectionIndex() |
Collection<String> |
getConnectionInitSqls() |
ObjectName |
getDataSourceJmxName() |
ObjectName |
getDataSourceJmxObjectName() |
Boolean |
getDefaultAutoCommit() |
String |
getDefaultCatalog() |
Integer |
getDefaultQueryTimeout() |
Integer |
getDefaultQueryTimeoutSeconds() |
Boolean |
getDefaultReadOnly() |
String |
getDefaultSchema() |
int |
getDefaultTransactionIsolation() |
Collection<String> |
getDisconnectionSqlCodes()
SQL_STATE codes considered to signal fatal conditions.
|
long |
getMaxConnLifetimeMillis() |
protected int |
getMaxOpenPreparedStatements() |
ObjectPool<PoolableConnection> |
getPool()
Returns the
ObjectPool in which Connection s are pooled. |
boolean |
getPoolStatements() |
String |
getValidationQuery() |
int |
getValidationQueryTimeoutSeconds() |
protected void |
initializeConnection(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() |
void |
passivateObject(PooledObject<PoolableConnection> p) |
void |
setAutoCommitOnReturn(boolean autoCommitOnReturn) |
void |
setCacheState(boolean cacheState) |
void |
setConnectionInitSql(Collection<String> connectionInitSqls)
Sets the SQL statements I use to initialize newly created
Connection s. |
void |
setDefaultAutoCommit(Boolean defaultAutoCommit)
Sets the default "auto commit" setting for borrowed
Connection s |
void |
setDefaultCatalog(String defaultCatalog)
Sets the default "catalog" setting for borrowed
Connection s |
void |
setDefaultQueryTimeout(Integer defaultQueryTimeoutSeconds) |
void |
setDefaultReadOnly(Boolean defaultReadOnly)
Sets the default "read only" setting for borrowed
Connection s |
void |
setDefaultSchema(String defaultSchema)
Sets the default "schema" setting for borrowed
Connection s |
void |
setDefaultTransactionIsolation(int defaultTransactionIsolation)
Sets the default "Transaction Isolation" setting for borrowed
Connection s |
void |
setDisconnectionSqlCodes(Collection<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 Connection s. |
void |
setPoolStatements(boolean poolStatements) |
void |
setRollbackOnReturn(boolean rollbackOnReturn) |
void |
setValidationQuery(String validationQuery)
Sets the query I use to
validate Connection s. |
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) |
public PoolableConnectionFactory(ConnectionFactory connFactory, ObjectName dataSourceJmxObjectName)
PoolableConnectionFactory
.connFactory
- the ConnectionFactory
from which to obtain base Connection
sdataSourceJmxObjectName
- The JMX object name, may be null.public void activateObject(PooledObject<PoolableConnection> p) throws Exception
activateObject
in interface PooledObjectFactory<PoolableConnection>
Exception
public void destroyObject(PooledObject<PoolableConnection> p) throws Exception
destroyObject
in interface PooledObjectFactory<PoolableConnection>
Exception
public boolean getCacheState()
public ConnectionFactory getConnectionFactory()
protected AtomicLong getConnectionIndex()
public Collection<String> getConnectionInitSqls()
public ObjectName getDataSourceJmxName()
public ObjectName getDataSourceJmxObjectName()
public Boolean getDefaultAutoCommit()
public String getDefaultCatalog()
public Integer getDefaultQueryTimeout()
public Integer getDefaultQueryTimeoutSeconds()
public Boolean getDefaultReadOnly()
public String getDefaultSchema()
public int getDefaultTransactionIsolation()
public Collection<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 Connection
s are pooled.public boolean getPoolStatements()
public String getValidationQuery()
public int getValidationQueryTimeoutSeconds()
protected void initializeConnection(Connection conn) throws SQLException
SQLException
public boolean isAutoCommitOnReturn()
@Deprecated public boolean isEnableAutoCommitOnReturn()
isAutoCommitOnReturn()
.public boolean isFastFailValidation()
setDisconnectionSqlCodes(Collection)
public boolean isRollbackOnReturn()
public PooledObject<PoolableConnection> makeObject() throws Exception
makeObject
in interface PooledObjectFactory<PoolableConnection>
Exception
public void passivateObject(PooledObject<PoolableConnection> p) throws Exception
passivateObject
in interface PooledObjectFactory<PoolableConnection>
Exception
public void setAutoCommitOnReturn(boolean autoCommitOnReturn)
public void setCacheState(boolean cacheState)
public void setConnectionInitSql(Collection<String> connectionInitSqls)
Connection
s. Using null
turns off
connection initialization.connectionInitSqls
- SQL statement to initialize Connection
s.public void setDefaultAutoCommit(Boolean defaultAutoCommit)
Connection
sdefaultAutoCommit
- the default "auto commit" setting for borrowed Connection
spublic void setDefaultCatalog(String defaultCatalog)
Connection
sdefaultCatalog
- the default "catalog" setting for borrowed Connection
spublic void setDefaultQueryTimeout(Integer defaultQueryTimeoutSeconds)
public void setDefaultReadOnly(Boolean defaultReadOnly)
Connection
sdefaultReadOnly
- the default "read only" setting for borrowed Connection
spublic void setDefaultSchema(String defaultSchema)
Connection
sdefaultSchema
- the default "schema" setting for borrowed Connection
spublic void setDefaultTransactionIsolation(int defaultTransactionIsolation)
Connection
sdefaultTransactionIsolation
- the default "Transaction Isolation" setting for returned Connection
spublic void setDisconnectionSqlCodes(Collection<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 Connection
s.pool
- the ObjectPool
in which to pool those Connection
spublic void setPoolStatements(boolean poolStatements)
public void setRollbackOnReturn(boolean rollbackOnReturn)
public void setValidationQuery(String validationQuery)
validate
Connection
s. 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
Connection
s.public void setValidationQueryTimeout(int validationQueryTimeoutSeconds)
validationQueryTimeoutSeconds
- new validation query timeout value in secondspublic void validateConnection(PoolableConnection conn) throws SQLException
SQLException
public boolean validateObject(PooledObject<PoolableConnection> p)
validateObject
in interface PooledObjectFactory<PoolableConnection>
Copyright © 2001–2019 The Apache Software Foundation. All rights reserved.