Class PoolableConnectionFactory

java.lang.Object
org.apache.commons.dbcp2.PoolableConnectionFactory
All Implemented Interfaces:
org.apache.commons.pool2.PooledObjectFactory<PoolableConnection>
Direct Known Subclasses:
PoolableManagedConnectionFactory

public class PoolableConnectionFactory extends Object implements org.apache.commons.pool2.PooledObjectFactory<PoolableConnection>
A PooledObjectFactory that creates PoolableConnections.
Since:
2.0
Version:
$Id: PoolableConnectionFactory.java 1659452 2015-02-13 04:00:39Z psteitz $
Author:
Rodney Waldhoff, Glenn L. Nielsen, James House, Dirk Verbeeck
  • Constructor Details

  • Method Details

    • setValidationQuery

      public void setValidationQuery(String validationQuery)
      Sets the query I use to validate Connections. 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.
    • setValidationQueryTimeout

      public 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. Use a value less than or equal to 0 for no timeout.
      Parameters:
      timeout - new validation query timeout value in seconds
    • setConnectionInitSql

      public void setConnectionInitSql(Collection<String> connectionInitSqls)
      Sets the SQL statements I use to initialize newly created Connections. Using null turns off connection initialization.
      Parameters:
      connectionInitSqls - SQL statement to initialize Connections.
    • setPool

      public void setPool(org.apache.commons.pool2.ObjectPool<PoolableConnection> pool)
      Sets the ObjectPool in which to pool Connections.
      Parameters:
      pool - the ObjectPool in which to pool those Connections
    • getPool

      public org.apache.commons.pool2.ObjectPool<PoolableConnection> getPool()
      Returns the ObjectPool in which Connections are pooled.
      Returns:
      the connection pool
    • setDefaultReadOnly

      public void setDefaultReadOnly(Boolean defaultReadOnly)
      Sets the default "read only" setting for borrowed Connections
      Parameters:
      defaultReadOnly - the default "read only" setting for borrowed Connections
    • setDefaultAutoCommit

      public void setDefaultAutoCommit(Boolean defaultAutoCommit)
      Sets the default "auto commit" setting for borrowed Connections
      Parameters:
      defaultAutoCommit - the default "auto commit" setting for borrowed Connections
    • setDefaultTransactionIsolation

      public void setDefaultTransactionIsolation(int defaultTransactionIsolation)
      Sets the default "Transaction Isolation" setting for borrowed Connections
      Parameters:
      defaultTransactionIsolation - the default "Transaction Isolation" setting for returned Connections
    • setDefaultCatalog

      public void setDefaultCatalog(String defaultCatalog)
      Sets the default "catalog" setting for borrowed Connections
      Parameters:
      defaultCatalog - the default "catalog" setting for borrowed Connections
    • setCacheState

      public void setCacheState(boolean cacheState)
    • setPoolStatements

      public void setPoolStatements(boolean poolStatements)
    • setMaxOpenPrepatedStatements

      public void setMaxOpenPrepatedStatements(int maxOpenPreparedStatements)
    • 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.
    • isEnableAutoCommitOnReturn

      public boolean isEnableAutoCommitOnReturn()
    • setEnableAutoCommitOnReturn

      public void setEnableAutoCommitOnReturn(boolean enableAutoCommitOnReturn)
    • isRollbackOnReturn

      public boolean isRollbackOnReturn()
    • setRollbackOnReturn

      public void setRollbackOnReturn(boolean rollbackOnReturn)
    • getDefaultQueryTimeout

      public Integer getDefaultQueryTimeout()
    • setDefaultQueryTimeout

      public void setDefaultQueryTimeout(Integer defaultQueryTimeout)
    • getDisconnectionSqlCodes

      public Collection<String> getDisconnectionSqlCodes()
      SQL_STATE codes considered to signal fatal conditions.

      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.

      Returns:
      SQL_STATE codes overriding defaults
      Since:
      2.1
    • setDisconnectionSqlCodes

      public void setDisconnectionSqlCodes(Collection<String> disconnectionSqlCodes)
      Parameters:
      disconnectionSqlCodes -
      Since:
      2.1
      See Also:
    • 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
      See Also:
    • setFastFailValidation

      public void setFastFailValidation(boolean fastFailValidation)
      Parameters:
      fastFailValidation - true means connections created by this factory will fast fail validation
      Since:
      2.1
      See Also:
    • makeObject

      public org.apache.commons.pool2.PooledObject<PoolableConnection> makeObject() throws Exception
      Specified by:
      makeObject in interface org.apache.commons.pool2.PooledObjectFactory<PoolableConnection>
      Throws:
      Exception
    • destroyObject

      public void destroyObject(org.apache.commons.pool2.PooledObject<PoolableConnection> p) throws Exception
      Specified by:
      destroyObject in interface org.apache.commons.pool2.PooledObjectFactory<PoolableConnection>
      Throws:
      Exception
    • validateObject

      public boolean validateObject(org.apache.commons.pool2.PooledObject<PoolableConnection> p)
      Specified by:
      validateObject in interface org.apache.commons.pool2.PooledObjectFactory<PoolableConnection>
    • validateConnection

      public void validateConnection(PoolableConnection conn) throws SQLException
      Throws:
      SQLException
    • passivateObject

      public void passivateObject(org.apache.commons.pool2.PooledObject<PoolableConnection> p) throws Exception
      Specified by:
      passivateObject in interface org.apache.commons.pool2.PooledObjectFactory<PoolableConnection>
      Throws:
      Exception
    • activateObject

      public void activateObject(org.apache.commons.pool2.PooledObject<PoolableConnection> p) throws Exception
      Specified by:
      activateObject in interface org.apache.commons.pool2.PooledObjectFactory<PoolableConnection>
      Throws:
      Exception