Class PoolableConnectionFactory
- All Implemented Interfaces:
PooledObjectFactory<PoolableConnection>
PooledObjectFactory that creates PoolableConnections.- Since:
- 2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate booleanprivate final ConnectionFactoryprivate final AtomicLongprivate Collection<String> private final ObjectNameprivate Booleanprivate Stringprivate Integerprivate Booleanprivate Stringprivate intprivate Collection<String> private booleanprivate static final org.datanucleus.util.NucleusLoggerprivate longprivate intprivate ObjectPool<PoolableConnection> private booleanprivate boolean(package private) static final intInternal constant to indicate the level is not set.private Stringprivate int -
Constructor Summary
ConstructorsConstructorDescriptionPoolableConnectionFactory(ConnectionFactory connFactory, ObjectName dataSourceJmxObjectName) Creates a newPoolableConnectionFactory. -
Method Summary
Modifier and TypeMethodDescriptionvoidReinitializes an instance to be returned by the pool.voidDestroys an instance no longer needed by the pool.booleanprotected AtomicLongintSQL_STATE codes considered to signal fatal conditions.longprotected intgetPool()Returns theObjectPoolin whichConnections are pooled.booleanintprotected voidbooleanbooleanDeprecated.booleanTrue means that validation will fail immediately for connections that have previously thrown SQLExceptions with SQL_STATE indicating fatal disconnection errors.booleanCreates 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) voidsetCacheState(boolean cacheState) 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) 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 borrowedConnectionsvoidsetDisconnectionSqlCodes(Collection<String> disconnectionSqlCodes) voidsetEnableAutoCommitOnReturn(boolean autoCommitOnReturn) Deprecated.voidsetFastFailValidation(boolean fastFailValidation) voidsetMaxConnLifetimeMillis(long maxConnLifetimeMillis) Sets the maximum lifetime in milliseconds of a connection after which the connection will always fail activation, passivation and validation.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) voidsetRollbackOnReturn(boolean rollbackOnReturn) voidsetValidationQuery(String validationQuery) Sets the query I use tovalidateConnections.voidsetValidationQueryTimeout(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.voidprivate voidbooleanEnsures that the instance is safe to be returned by the pool.
-
Field Details
-
log
private static final org.datanucleus.util.NucleusLogger log -
UNKNOWN_TRANSACTION_ISOLATION
static final int UNKNOWN_TRANSACTION_ISOLATIONInternal constant to indicate the level is not set.- See Also:
-
connectionFactory
-
dataSourceJmxObjectName
-
validationQuery
-
validationQueryTimeoutSeconds
private volatile int validationQueryTimeoutSeconds -
connectionInitSqls
-
disconnectionSqlCodes
-
fastFailValidation
private boolean fastFailValidation -
pool
-
defaultReadOnly
-
defaultAutoCommit
-
autoCommitOnReturn
private boolean autoCommitOnReturn -
rollbackOnReturn
private boolean rollbackOnReturn -
defaultTransactionIsolation
private int defaultTransactionIsolation -
defaultCatalog
-
defaultSchema
-
cacheState
private boolean cacheState -
poolStatements
private boolean poolStatements -
maxOpenPreparedStatements
private int maxOpenPreparedStatements -
maxConnLifetimeMillis
private long maxConnLifetimeMillis -
connectionIndex
-
defaultQueryTimeoutSeconds
-
-
Constructor Details
-
PoolableConnectionFactory
Creates a newPoolableConnectionFactory.- Parameters:
connFactory- theConnectionFactoryfrom which to obtain baseConnectionsdataSourceJmxObjectName- The JMX object name, may be null.
-
-
Method Details
-
activateObject
Description copied from interface:PooledObjectFactoryReinitializes an instance to be returned by the pool.- Specified by:
activateObjectin interfacePooledObjectFactory<PoolableConnection>- Parameters:
p- aPooledObjectwrapping the instance to be activated- Throws:
Exception- if there is a problem activatingobj, this exception may be swallowed by the pool.- See Also:
-
destroyObject
Description copied from interface:PooledObjectFactoryDestroys an instance no longer needed by the pool.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 interfacePooledObjectFactory<PoolableConnection>- Parameters:
p- aPooledObjectwrapping the instance to be destroyed- Throws:
Exception- should be avoided as it may be swallowed by the pool implementation.- See Also:
-
getCacheState
public boolean getCacheState()- Returns:
- The cache state.
- Since:
- Made public in 2.6.0.
-
getConnectionFactory
- Returns:
- The connection factory.
- Since:
- Made public in 2.6.0.
-
getConnectionIndex
-
getConnectionInitSqls
- Returns:
- The collection of initialization SQL statements.
- Since:
- 2.6.0
-
getDataSourceJmxName
- Returns:
- The data source JMX ObjectName
- Since:
- Made public in 2.6.0.
-
getDataSourceJmxObjectName
- Returns:
- The data source JMS ObjectName.
- Since:
- 2.6.0
-
getDefaultAutoCommit
- Returns:
- Default auto-commit value.
- Since:
- 2.6.0
-
getDefaultCatalog
- Returns:
- Default catalog.
- Since:
- 2.6.0
-
getDefaultQueryTimeout
- Returns:
- Default query timeout in seconds.
-
getDefaultQueryTimeoutSeconds
- Returns:
- Default query timeout in seconds.
- Since:
- 2.6.0
-
getDefaultReadOnly
- Returns:
- Default read-only-value.
- Since:
- 2.6.0
-
getDefaultSchema
- Returns:
- Default schema.
- Since:
- 2.6.0
-
getDefaultTransactionIsolation
public int getDefaultTransactionIsolation()- Returns:
- Default transaction isolation.
- Since:
- 2.6.0
-
getDisconnectionSqlCodes
SQL_STATE codes considered to signal fatal conditions.Overrides the defaults in
Utils.DISCONNECTION_SQL_CODES(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
-
getMaxConnLifetimeMillis
public long getMaxConnLifetimeMillis()- Returns:
- Maximum connection lifetime in milliseconds.
- Since:
- 2.6.0
-
getMaxOpenPreparedStatements
protected int getMaxOpenPreparedStatements() -
getPool
Returns theObjectPoolin whichConnections are pooled.- Returns:
- the connection pool
-
getPoolStatements
public boolean getPoolStatements()- Returns:
- Whether to pool statements.
- Since:
- Made public in 2.6.0.
-
getValidationQuery
- Returns:
- Validation query.
- Since:
- 2.6.0
-
getValidationQueryTimeoutSeconds
public int getValidationQueryTimeoutSeconds()- Returns:
- Validation query timeout in seconds.
- Since:
- 2.6.0
-
initializeConnection
- Throws:
SQLException
-
isAutoCommitOnReturn
public boolean isAutoCommitOnReturn()- Returns:
- Whether to auto-commit on return.
- Since:
- 2.6.0
-
isEnableAutoCommitOnReturn
Deprecated.- Returns:
- Whether to auto-commit on return.
-
isFastFailValidation
public 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:
-
isRollbackOnReturn
public boolean isRollbackOnReturn()- Returns:
- Whether to rollback on return.
-
makeObject
Description 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 interfacePooledObjectFactory<PoolableConnection>- Returns:
- a
PooledObjectwrapping an instance that can be served by the pool - Throws:
Exception- if there is a problem creating a new instance, this will be propagated to the code requesting an object.
-
passivateObject
Description copied from interface:PooledObjectFactoryUninitializes an instance to be returned to the idle object pool.- Specified by:
passivateObjectin interfacePooledObjectFactory<PoolableConnection>- Parameters:
p- aPooledObjectwrapping the instance to be passivated- Throws:
Exception- if there is a problem passivatingobj, this exception may be swallowed by the pool.- See Also:
-
setAutoCommitOnReturn
public void setAutoCommitOnReturn(boolean autoCommitOnReturn) -
setCacheState
public void setCacheState(boolean cacheState) -
setConnectionInitSql
Sets the SQL statements I use to initialize newly createdConnections. Usingnullturns off connection initialization.- Parameters:
connectionInitSqls- SQL statement to initializeConnections.
-
setDefaultAutoCommit
Sets the default "auto commit" setting for borrowedConnections- Parameters:
defaultAutoCommit- the default "auto commit" setting for borrowedConnections
-
setDefaultCatalog
Sets the default "catalog" setting for borrowedConnections- Parameters:
defaultCatalog- the default "catalog" setting for borrowedConnections
-
setDefaultQueryTimeout
-
setDefaultReadOnly
Sets the default "read only" setting for borrowedConnections- Parameters:
defaultReadOnly- the default "read only" setting for borrowedConnections
-
setDefaultSchema
Sets the default "schema" setting for borrowedConnections- Parameters:
defaultSchema- the default "schema" setting for borrowedConnections- Since:
- 2.5.0
-
setDefaultTransactionIsolation
public void setDefaultTransactionIsolation(int defaultTransactionIsolation) Sets the default "Transaction Isolation" setting for borrowedConnections- Parameters:
defaultTransactionIsolation- the default "Transaction Isolation" setting for returnedConnections
-
setDisconnectionSqlCodes
- Parameters:
disconnectionSqlCodes- The disconnection SQL codes.- Since:
- 2.1
- See Also:
-
setEnableAutoCommitOnReturn
Deprecated.- Parameters:
autoCommitOnReturn- Whether to auto-commit on return.
-
setFastFailValidation
public void setFastFailValidation(boolean fastFailValidation) - Parameters:
fastFailValidation- true means connections created by this factory will fast fail validation- Since:
- 2.1
- See Also:
-
setMaxConnLifetimeMillis
public void setMaxConnLifetimeMillis(long maxConnLifetimeMillis) 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.
-
setMaxOpenPreparedStatements
public void setMaxOpenPreparedStatements(int maxOpenPreparedStatements) Sets the maximum number of open prepared statements.- Parameters:
maxOpenPreparedStatements- The maximum number of open prepared statements.
-
setMaxOpenPrepatedStatements
Deprecated.Deprecated due to typo in method name.- Parameters:
maxOpenPreparedStatements- The maximum number of open prepared statements.
-
setPool
Sets theObjectPoolin which to poolConnections.- Parameters:
pool- theObjectPoolin which to pool thoseConnections
-
setPoolStatements
public void setPoolStatements(boolean poolStatements) -
setRollbackOnReturn
public void setRollbackOnReturn(boolean rollbackOnReturn) -
setValidationQuery
Sets 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 tovalidateConnections.
-
setValidationQueryTimeout
public 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. Use a value less than or equal to 0 for no timeout.- Parameters:
validationQueryTimeoutSeconds- new validation query timeout value in seconds
-
validateConnection
- Throws:
SQLException
-
validateLifetime
- Throws:
Exception
-
validateObject
Description copied from interface:PooledObjectFactoryEnsures that the instance is safe to be returned by the pool.- Specified by:
validateObjectin interfacePooledObjectFactory<PoolableConnection>- Parameters:
p- aPooledObjectwrapping the instance to be validated- Returns:
falseifobjis not valid and should be dropped from the pool,trueotherwise.
-
isAutoCommitOnReturn().