org.apache.commons.dbcp2

## 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 `PoolableConnection`s.
  Since:
    2.0
  Version:
    $Revision: 1572242 $ $Date: 2014-02-26 20:34:39 +0000 (Wed, 26 Feb 2014) $
  Author:
    Rodney Waldhoff, Glenn L. Nielsen, James House, Dirk Verbeeck

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `PoolableConnectionFactory(ConnectionFactory connFactory, ObjectName dataSourceJmxName)` Create a new `PoolableConnectionFactory`.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `activateObject(org.apache.commons.pool2.PooledObject<PoolableConnection> p)`
    `void` | `destroyObject(org.apache.commons.pool2.PooledObject<PoolableConnection> p)`
    `protected boolean` | `getCacheState()`
    `protected ConnectionFactory` | `getConnectionFactory()`
    `Integer` | `getDefaultQueryTimeout()`
    `protected int` | `getMaxOpenPreparedStatements()`
    `org.apache.commons.pool2.ObjectPool<PoolableConnection>` | `getPool()` Returns the `ObjectPool` in which `Connection`s are pooled.
    `protected boolean` | `getPoolStatements()`
    `protected void` | `initializeConnection(Connection conn)`
    `boolean` | `isEnableAutoCommitOnReturn()`
    `boolean` | `isRollbackOnReturn()`
    `org.apache.commons.pool2.PooledObject<PoolableConnection>` | `makeObject()`
    `void` | `passivateObject(org.apache.commons.pool2.PooledObject<PoolableConnection> p)`
    `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 defaultQueryTimeout)`
    `void` | `setDefaultReadOnly(Boolean defaultReadOnly)` Sets the default "read only" setting for borrowed `Connection`s
    `void` | `setDefaultTransactionIsolation(int defaultTransactionIsolation)` Sets the default "Transaction Isolation" setting for borrowed `Connection`s
    `void` | `setEnableAutoCommitOnReturn(boolean enableAutoCommitOnReturn)`
    `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` | `setMaxOpenPrepatedStatements(int maxOpenPreparedStatements)`
    `void` | `setPool(org.apache.commons.pool2.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 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.
    `void` | `validateConnection(PoolableConnection conn)`
    `boolean` | `validateObject(org.apache.commons.pool2.PooledObject<PoolableConnection> p)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### PoolableConnectionFactory

          public PoolableConnectionFactory(ConnectionFactory connFactory,
                                   ObjectName dataSourceJmxName)

      Create a new `PoolableConnectionFactory`.
      Parameters:
        `connFactory` - the `ConnectionFactory` from which to obtain base `Connection`s

  - ### Method Detail

    - #### setValidationQuery

          public void setValidationQuery(String validationQuery)

      Sets the query I use to `validate` `Connection`s. 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` `Connection`s.

    - #### 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 `Connection`s. Using `null` turns off connection initialization.
      Parameters:
        `connectionInitSqls` - SQL statement to initialize `Connection`s.

    - #### setPool

          public void setPool(org.apache.commons.pool2.ObjectPool<PoolableConnection> pool)

      Sets the `ObjectPool` in which to pool `Connection`s.
      Parameters:
        `pool` - the `ObjectPool` in which to pool those `Connection`s

    - #### getPool

          public org.apache.commons.pool2.ObjectPool<PoolableConnection> getPool()

      Returns the `ObjectPool` in which `Connection`s are pooled.
      Returns:
        the connection pool

    - #### setDefaultReadOnly

          public void setDefaultReadOnly(Boolean defaultReadOnly)

      Sets the default "read only" setting for borrowed `Connection`s
      Parameters:
        `defaultReadOnly` - the default "read only" setting for borrowed `Connection`s

    - #### setDefaultAutoCommit

          public void setDefaultAutoCommit(Boolean defaultAutoCommit)

      Sets the default "auto commit" setting for borrowed `Connection`s
      Parameters:
        `defaultAutoCommit` - the default "auto commit" setting for borrowed `Connection`s

    - #### setDefaultTransactionIsolation

          public void setDefaultTransactionIsolation(int defaultTransactionIsolation)

      Sets the default "Transaction Isolation" setting for borrowed `Connection`s
      Parameters:
        `defaultTransactionIsolation` - the default "Transaction Isolation" setting for returned `Connection`s

    - #### setDefaultCatalog

          public void setDefaultCatalog(String defaultCatalog)

      Sets the default "catalog" setting for borrowed `Connection`s
      Parameters:
        `defaultCatalog` - the default "catalog" setting for borrowed `Connection`s

    - #### 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)

    - #### makeObject

          public org.apache.commons.pool2.PooledObject<PoolableConnection> makeObject()
                                                                               throws Exception

      Specified by:
        `makeObject` in interface `org.apache.commons.pool2.PooledObjectFactory<PoolableConnection>`
      Throws:
        `Exception`

    - #### initializeConnection

          protected void initializeConnection(Connection conn)
                                       throws SQLException

      Throws:
        `SQLException`

    - #### 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`

    - #### getConnectionFactory

          protected ConnectionFactory getConnectionFactory()

    - #### getPoolStatements

          protected boolean getPoolStatements()

    - #### getMaxOpenPreparedStatements

          protected int getMaxOpenPreparedStatements()

    - #### getCacheState

          protected boolean getCacheState()

Copyright © 2001–2014 The Apache Software Foundation. All rights reserved.