Class PoolableConnectionFactory
- All Implemented Interfaces:
- PooledObjectFactory<PoolableConnection>
- Direct Known Subclasses:
- PoolableManagedConnectionFactory
PooledObjectFactory that creates PoolableConnections.- Since:
- 2.0
- 
Constructor SummaryConstructorsConstructorDescriptionPoolableConnectionFactory(ConnectionFactory connFactory, ObjectName dataSourceJmxObjectName) Creates a newPoolableConnectionFactory.
- 
Method SummaryModifier and TypeMethodDescriptionvoidReinitializes an instance to be returned by the pool.voidDestroys an instance no longer needed by the pool, using the default (NORMAL) DestroyMode.voidDestroys an instance no longer needed by the pool, using the provided DestroyMode.booleanGets the cache state to propagate inmakeObject().Gets the connection factory.protected AtomicLongGets how many connections were created inmakeObject().Gets the collection of initialization SQL statements.Gets data source JMX ObjectName.Gets the data source JMX ObjectName.Gets the Default auto-commit value.Gets the default catalog.Deprecated.Gets the default query timeout Duration.Deprecated.Gets the default read-only-value.Gets the default schema.intGets the default transaction isolation.Gets the collection of SQL State codes that are not considered fatal disconnection codes.Gets SQL State codes considered to signal fatal conditions.Gets the Maximum connection duration.longGets the Maximum connection lifetime in milliseconds.protected intGets the maximum number of open prepared statements.getPool()Returns theObjectPoolin whichConnections are pooled.booleanTests whether to pool statements.Gets the validation query.Gets the query timeout in seconds.intDeprecated.protected voidInitializes the given connection with the collection of SQL statements set insetConnectionInitSql(Collection).booleanTests whether to set auto-commit onpassivateObject(PooledObject).booleanDeprecated.booleanTrue means that validation will fail immediately for connections that have previously thrown SQLExceptions with SQL State indicating fatal disconnection errors.booleanTests whether to rollback on return.Creates an instance that can be served by the pool and wrap it in aPooledObjectto be managed by the pool.voidUninitializes an instance to be returned to the idle object pool.voidsetAutoCommitOnReturn(boolean autoCommitOnReturn) Sets whether to set auto-commit onpassivateObject(PooledObject).voidsetCacheState(boolean cacheState) Sets the cache state to propagate inmakeObject().voidsetClearStatementPoolOnReturn(boolean clearStatementPoolOnReturn) Sets whether the pool of statements (which was enabled withsetPoolStatements(boolean)) should be cleared when the connection is returned to its pool.voidsetConnectionInitSql(Collection<String> connectionInitSqls) Sets the SQL statements I use to initialize newly createdConnections.voidsetDefaultAutoCommit(Boolean defaultAutoCommit) Sets the default "auto commit" setting for borrowedConnectionsvoidsetDefaultCatalog(String defaultCatalog) Sets the default "catalog" setting for borrowedConnectionsvoidsetDefaultQueryTimeout(Integer defaultQueryTimeoutSeconds) Deprecated.voidsetDefaultQueryTimeout(Duration defaultQueryTimeoutDuration) Sets the query timeout Duration.voidsetDefaultReadOnly(Boolean defaultReadOnly) Sets the default "read only" setting for borrowedConnectionsvoidsetDefaultSchema(String defaultSchema) Sets the default "schema" setting for borrowedConnectionsvoidsetDefaultTransactionIsolation(int defaultTransactionIsolation) Sets the default "Transaction Isolation" setting for borrowedConnectionsvoidsetDisconnectionIgnoreSqlCodes(Collection<String> disconnectionIgnoreSqlCodes) Sets the disconnection SQL codes to ignore.voidsetDisconnectionSqlCodes(Collection<String> disconnectionSqlCodes) Sets the disconnection SQL codes.voidsetEnableAutoCommitOnReturn(boolean autoCommitOnReturn) Deprecated.voidsetFastFailValidation(boolean fastFailValidation) voidsetMaxConn(Duration maxConnDuration) Sets the maximum lifetime in milliseconds of a connection after which the connection will always fail activation, passivation and validation.voidsetMaxConnLifetimeMillis(long maxConnLifetimeMillis) Deprecated.UsesetMaxConn(Duration).voidsetMaxOpenPreparedStatements(int maxOpenPreparedStatements) Sets the maximum number of open prepared statements.voidsetMaxOpenPrepatedStatements(int maxOpenPreparedStatements) Deprecated.voidsetPool(ObjectPool<PoolableConnection> pool) Sets theObjectPoolin which to poolConnections.voidsetPoolStatements(boolean poolStatements) Sets whether to pool statements.voidsetRollbackOnReturn(boolean rollbackOnReturn) Sets whether to rollback on return.voidsetValidationQuery(String validationQuery) Sets the query I use tovalidateConnections.voidsetValidationQueryTimeout(int validationQueryTimeoutSeconds) Deprecated.voidsetValidationQueryTimeout(Duration validationQueryTimeoutDuration) Sets the validation query timeout, the amount of time, that connection validation will wait for a response from the database when executing a validation query.voidValidates the given connection if it is open.booleanEnsures that the instance is safe to be returned by the pool.
- 
Constructor Details- 
PoolableConnectionFactoryCreates a newPoolableConnectionFactory.- Parameters:
- connFactory- the- ConnectionFactoryfrom which to obtain base- Connections
- dataSourceJmxObjectName- The JMX object name, may be null.
 
 
- 
- 
Method Details- 
activateObjectDescription copied from interface:PooledObjectFactoryReinitializes an instance to be returned by the pool.- Specified by:
- activateObjectin interface- PooledObjectFactory<PoolableConnection>
- Parameters:
- p- a- PooledObjectwrapping the instance to be activated
- Throws:
- SQLException
- See Also:
 
- 
destroyObjectDescription copied from interface:PooledObjectFactoryDestroys an instance no longer needed by the pool, using the default (NORMAL) DestroyMode.It is important for implementations of this method to be aware that there is no guarantee about what state objwill 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. - Specified by:
- destroyObjectin interface- PooledObjectFactory<PoolableConnection>
- Parameters:
- p- a- PooledObjectwrapping the instance to be destroyed
- Throws:
- SQLException
- See Also:
 
- 
destroyObjectDescription copied from interface:PooledObjectFactoryDestroys an instance no longer needed by the pool, using the provided DestroyMode.- Specified by:
- destroyObjectin interface- PooledObjectFactory<PoolableConnection>
- Parameters:
- p- a- PooledObjectwrapping the instance to be destroyed
- mode- DestroyMode providing context to the factory
- Throws:
- SQLException
- Since:
- 2.9.0
- See Also:
 
- 
getCacheStatepublic boolean getCacheState()Gets the cache state to propagate inmakeObject().- Returns:
- The cache state.
- Since:
- 2.6.0.
 
- 
getConnectionFactoryGets the connection factory.- Returns:
- The connection factory.
- Since:
- 2.6.0.
 
- 
getConnectionIndexGets how many connections were created inmakeObject().- Returns:
- the connection count.
 
- 
getConnectionInitSqlsGets the collection of initialization SQL statements.- Returns:
- The collection of initialization SQL statements.
- Since:
- 2.6.0
 
- 
getDataSourceJmxNameGets data source JMX ObjectName.- Returns:
- The data source JMX ObjectName.
- Since:
- 2.6.0.
 
- 
getDataSourceJmxObjectNameGets the data source JMX ObjectName.- Returns:
- The data source JMX ObjectName.
- Since:
- 2.6.0
 
- 
getDefaultAutoCommitGets the Default auto-commit value.- Returns:
- The default auto-commit value.
- Since:
- 2.6.0
 
- 
getDefaultCatalogGets the default catalog.- Returns:
- The default catalog.
- Since:
- 2.6.0
 
- 
getDefaultQueryTimeoutDeprecated.Gets the default query timeout in seconds.- Returns:
- The default query timeout in seconds.
 
- 
getDefaultQueryTimeoutDurationGets the default query timeout Duration.- Returns:
- The default query timeout Duration.
- Since:
- 2.10.0
 
- 
getDefaultQueryTimeoutSecondsDeprecated.Gets the default query timeout in seconds.- Returns:
- The default query timeout in seconds.
- Since:
- 2.6.0
 
- 
getDefaultReadOnlyGets the default read-only-value.- Returns:
- The default read-only-value.
- Since:
- 2.6.0
 
- 
getDefaultSchema
- 
getDefaultTransactionIsolationpublic int getDefaultTransactionIsolation()Gets the default transaction isolation.- Returns:
- The default transaction isolation.
- Since:
- 2.6.0
 
- 
getDisconnectionIgnoreSqlCodesGets the collection of SQL State codes that are not considered fatal disconnection codes.This method returns the collection of SQL State codes that have been set to be ignored when determining if a SQLExceptionsignals a disconnection. These codes are excluded from being treated as fatal even if they match the typical disconnection criteria.- Returns:
- a Collectionof SQL State codes that should be ignored for disconnection checks.
- Since:
- 2.13.0
 
- 
getDisconnectionSqlCodesGets SQL State codes considered to signal fatal conditions.Overrides the defaults in Utils.getDisconnectionSqlCodes()(plus anything starting withUtils.DISCONNECTION_SQL_CODE_PREFIX). If this property is non-null andisFastFailValidation()istrue, 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()isfalsesetting this property has no effect.- Returns:
- SQL State codes overriding defaults
- Since:
- 2.1
 
- 
getMaxConnDurationGets the Maximum connection duration.- Returns:
- Maximum connection duration.
- Since:
- 2.10.0
 
- 
getMaxConnLifetimeMillispublic long getMaxConnLifetimeMillis()Gets the Maximum connection lifetime in milliseconds.- Returns:
- Maximum connection lifetime in milliseconds.
- Since:
- 2.6.0
 
- 
getMaxOpenPreparedStatementsprotected int getMaxOpenPreparedStatements()Gets the maximum number of open prepared statements.- Returns:
- The maximum number of open prepared statements.
 
- 
getPoolReturns theObjectPoolin whichConnections are pooled.- Returns:
- the connection pool
 
- 
getPoolStatementspublic boolean getPoolStatements()Tests whether to pool statements.- Returns:
- Whether to pool statements.
- Since:
- 2.6.0.
 
- 
getValidationQueryGets the validation query.- Returns:
- Validation query.
- Since:
- 2.6.0
 
- 
getValidationQueryTimeoutDurationGets the query timeout in seconds.- Returns:
- Validation query timeout in seconds.
- Since:
- 2.10.0
 
- 
getValidationQueryTimeoutSecondsDeprecated.Gets the query timeout in seconds.- Returns:
- Validation query timeout in seconds.
- Since:
- 2.6.0
 
- 
initializeConnectionInitializes the given connection with the collection of SQL statements set insetConnectionInitSql(Collection).- Parameters:
- conn- the connection to initialize.
- Throws:
- SQLException- if a database access error occurs or this method is called on a closed connection.
- See Also:
 
- 
isAutoCommitOnReturnpublic boolean isAutoCommitOnReturn()Tests whether to set auto-commit onpassivateObject(PooledObject).- Returns:
- Whether to set auto-commit on passivateObject(PooledObject).
- Since:
- 2.6.0
 
- 
isEnableAutoCommitOnReturnDeprecated.Tests whether to set auto-commit onpassivateObject(PooledObject).- Returns:
- Whether to set auto-commit on passivateObject(PooledObject).
 
- 
isFastFailValidationpublic boolean isFastFailValidation()True means that validation will fail immediately for connections that have previously thrown SQLExceptions with SQL State indicating fatal disconnection errors.- Returns:
- true if connections created by this factory will fast fail validation.
- Since:
- 2.1, 2.5.0 Defaults to true, previous versions defaulted to false.
- See Also:
 
- 
isRollbackOnReturnpublic boolean isRollbackOnReturn()Tests whether to rollback on return.- Returns:
- Whether to rollback on return.
 
- 
makeObjectDescription copied from interface:PooledObjectFactoryCreates an instance that can be served by the pool and wrap it in aPooledObjectto be managed by the pool.- Specified by:
- makeObjectin interface- PooledObjectFactory<PoolableConnection>
- Returns:
- a PooledObjectwrapping an instance that can be served by the pool, not null.
- Throws:
- SQLException
 
- 
passivateObjectDescription copied from interface:PooledObjectFactoryUninitializes an instance to be returned to the idle object pool.- Specified by:
- passivateObjectin interface- PooledObjectFactory<PoolableConnection>
- Parameters:
- p- a- PooledObjectwrapping the instance to be passivated
- Throws:
- SQLException
- See Also:
 
- 
setAutoCommitOnReturnpublic void setAutoCommitOnReturn(boolean autoCommitOnReturn) Sets whether to set auto-commit onpassivateObject(PooledObject).- Parameters:
- autoCommitOnReturn- whether to set auto-commit.
 
- 
setCacheStatepublic void setCacheState(boolean cacheState) Sets the cache state to propagate inmakeObject().- Parameters:
- cacheState- the cache state to propagate.
 
- 
setClearStatementPoolOnReturnpublic void setClearStatementPoolOnReturn(boolean clearStatementPoolOnReturn) Sets whether the pool of statements (which was enabled withsetPoolStatements(boolean)) should be cleared when the connection is returned to its pool. Default is false.- Parameters:
- clearStatementPoolOnReturn- clear or not
- Since:
- 2.8.0
 
- 
setConnectionInitSqlSets the SQL statements I use to initialize newly createdConnections. Usingnullturns off connection initialization.- Parameters:
- connectionInitSqls- SQL statement to initialize- Connections.
 
- 
setDefaultAutoCommitSets the default "auto commit" setting for borrowedConnections- Parameters:
- defaultAutoCommit- the default "auto commit" setting for borrowed- Connections
 
- 
setDefaultCatalogSets the default "catalog" setting for borrowedConnections- Parameters:
- defaultCatalog- the default "catalog" setting for borrowed- Connections
 
- 
setDefaultQueryTimeoutSets the query timeout Duration.- Parameters:
- defaultQueryTimeoutDuration- the query timeout Duration.
- Since:
- 2.10.0
 
- 
setDefaultQueryTimeoutDeprecated.Sets the query timeout in seconds.- Parameters:
- defaultQueryTimeoutSeconds- the query timeout in seconds.
 
- 
setDefaultReadOnlySets the default "read only" setting for borrowedConnections- Parameters:
- defaultReadOnly- the default "read only" setting for borrowed- Connections
 
- 
setDefaultSchemaSets the default "schema" setting for borrowedConnections- Parameters:
- defaultSchema- the default "schema" setting for borrowed- Connections
- Since:
- 2.5.0
 
- 
setDefaultTransactionIsolationpublic void setDefaultTransactionIsolation(int defaultTransactionIsolation) Sets the default "Transaction Isolation" setting for borrowedConnections- Parameters:
- defaultTransactionIsolation- the default "Transaction Isolation" setting for returned- Connections
 
- 
setDisconnectionIgnoreSqlCodesSets the disconnection SQL codes to ignore.- Parameters:
- disconnectionIgnoreSqlCodes- The collection of SQL State codes to be ignored.
- Throws:
- IllegalArgumentException- if any SQL state codes overlap with those in- disconnectionSqlCodes.
- Since:
- 2.13.0
- See Also:
 
- 
setDisconnectionSqlCodesSets the disconnection SQL codes.- Parameters:
- disconnectionSqlCodes- The disconnection SQL codes.
- Throws:
- IllegalArgumentException- if any SQL state codes overlap with those in- disconnectionIgnoreSqlCodes.
- Since:
- 2.1
- See Also:
 
- 
setEnableAutoCommitOnReturnDeprecated.Sets whether to set auto-commit onpassivateObject(PooledObject).- Parameters:
- autoCommitOnReturn- whether to set auto-commit.
 
- 
setFastFailValidationpublic void setFastFailValidation(boolean fastFailValidation) - Parameters:
- fastFailValidation- true means connections created by this factory will fast fail validation
- Since:
- 2.1
- See Also:
 
- 
setMaxConnSets the maximum lifetime in milliseconds of a connection after which the connection will always fail activation, passivation and validation. A value of zero or less indicates an infinite lifetime. The default value is -1.- Parameters:
- maxConnDuration- The maximum lifetime in milliseconds.
- Since:
- 2.10.0
 
- 
setMaxConnLifetimeMillisDeprecated.UsesetMaxConn(Duration).Sets the maximum lifetime in milliseconds of a connection after which the connection will always fail activation, passivation and validation. A value of zero or less indicates an infinite lifetime. The default value is -1.- Parameters:
- maxConnLifetimeMillis- The maximum lifetime in milliseconds.
 
- 
setMaxOpenPreparedStatementspublic void setMaxOpenPreparedStatements(int maxOpenPreparedStatements) Sets the maximum number of open prepared statements.- Parameters:
- maxOpenPreparedStatements- The maximum number of open prepared statements.
 
- 
setMaxOpenPrepatedStatementsDeprecated.Deprecated due to typo in method name.- Parameters:
- maxOpenPreparedStatements- The maximum number of open prepared statements.
 
- 
setPoolSets theObjectPoolin which to poolConnections.- Parameters:
- pool- the- ObjectPoolin which to pool those- Connections
 
- 
setPoolStatementspublic void setPoolStatements(boolean poolStatements) Sets whether to pool statements.- Parameters:
- poolStatements- whether to pool statements.
 
- 
setRollbackOnReturnpublic void setRollbackOnReturn(boolean rollbackOnReturn) Sets whether to rollback on return.- Parameters:
- rollbackOnReturn- whether to rollback on return.
 
- 
setValidationQuerySets the query I use tovalidateConnections. Should return at least one row. If not specified,Connection.isValid(int)will be used to validate connections.- Parameters:
- validationQuery- a query to use to- validate- Connections.
 
- 
setValidationQueryTimeoutSets the validation query timeout, the amount of time, that connection validation will wait for a response from the database when executing a validation query. Use a value less than or equal to 0 for no timeout.- Parameters:
- validationQueryTimeoutDuration- new validation query timeout duration.
- Since:
- 2.10.0
 
- 
setValidationQueryTimeoutDeprecated.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. Use a value less than or equal to 0 for no timeout.- Parameters:
- validationQueryTimeoutSeconds- new validation query timeout value in seconds
 
- 
validateConnectionValidates the given connection if it is open.- Parameters:
- conn- the connection to validate.
- Throws:
- SQLException- if the connection is closed or validate fails.
 
- 
validateObjectDescription copied from interface:PooledObjectFactoryEnsures that the instance is safe to be returned by the pool.- Specified by:
- validateObjectin interface- PooledObjectFactory<PoolableConnection>
- Parameters:
- p- a- PooledObjectwrapping the instance to be validated
- Returns:
- falseif- objis not valid and should be dropped from the pool,- trueotherwise.
 
 
- 
getDefaultQueryTimeoutDuration().