org.apache.commons.dbcp2

## Class PoolableConnection

- java.lang.Object
- - org.apache.commons.dbcp2.AbandonedTrace
  - - org.apache.commons.dbcp2.DelegatingConnection<Connection>
    - - org.apache.commons.dbcp2.PoolableConnection

- All Implemented Interfaces:
    AutoCloseable, Connection, Wrapper, PoolableConnectionMXBean, org.apache.commons.pool2.TrackedUse
  Direct Known Subclasses:
    PoolableManagedConnection

      public class PoolableConnection
      extends DelegatingConnection<Connection>
      implements PoolableConnectionMXBean

  A delegating connection that, rather than closing the underlying connection, returns itself to an `ObjectPool` when closed.
  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

- - ### Field Summary

    - ### Fields inherited from interface java.sql.Connection

      `TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PoolableConnection(Connection conn, org.apache.commons.pool2.ObjectPool<PoolableConnection> pool, ObjectName jmxName)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Returns me to my pool.
    `String` | `getToString()` Expose the `DelegatingConnection.toString()` method via a bean getter so it can be read as a property via JMX.
    `boolean` | `isClosed()`
    `protected void` | `passivate()`
    `void` | `reallyClose()` Actually close my underlying `Connection`.
    `void` | `validate(String sql, int timeout)`

    - ### Methods inherited from class org.apache.commons.dbcp2.DelegatingConnection

      `abort, activate, checkOpen, clearCachedState, clearWarnings, closeInternal, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getAutoCommit, getCacheState, getCatalog, getClientInfo, getClientInfo, getDefaultQueryTimeout, getDelegate, getDelegateInternal, getHoldability, getInnermostDelegate, getInnermostDelegateInternal, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, handleException, innermostDelegateEquals, isClosedInternal, isReadOnly, isValid, isWrapperFor, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCacheState, setCatalog, setClientInfo, setClientInfo, setClosedInternal, setDefaultQueryTimeout, setDelegate, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMap, toString, unwrap`

    - ### Methods inherited from class org.apache.commons.dbcp2.AbandonedTrace

      `addTrace, clearTrace, getLastUsed, getTrace, removeTrace, setLastUsed, setLastUsed`

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

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

    - ### Methods inherited from interface org.apache.commons.dbcp2.PoolableConnectionMXBean

      `clearCachedState, clearWarnings, getAutoCommit, getCacheState, getCatalog, getHoldability, getSchema, getTransactionIsolation, isReadOnly, setAutoCommit, setCacheState, setCatalog, setHoldability, setReadOnly, setSchema, setTransactionIsolation`

- - ### Constructor Detail

    - #### PoolableConnection

          public PoolableConnection(Connection conn,
                            org.apache.commons.pool2.ObjectPool<PoolableConnection> pool,
                            ObjectName jmxName)

      Parameters:
        `conn` - my underlying connection
        `pool` - the pool to which I should return when closed

  - ### Method Detail

    - #### passivate

          protected void passivate()
                            throws SQLException

      Overrides:
        `passivate` in class `DelegatingConnection<Connection>`
      Throws:
        `SQLException`

    - #### isClosed

          public boolean isClosed()
                           throws SQLException

      This method should not be used by a client to determine whether or not a connection should be return to the connection pool (by calling `close()`). Clients should always attempt to return a connection to the pool once it is no longer required.

      Specified by:
        `isClosed` in interface `Connection`
      Specified by:
        `isClosed` in interface `PoolableConnectionMXBean`
      Overrides:
        `isClosed` in class `DelegatingConnection<Connection>`
      Throws:
        `SQLException`

    - #### close

          public void close()
                     throws SQLException

      Returns me to my pool.
      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in interface `Connection`
      Specified by:
        `close` in interface `PoolableConnectionMXBean`
      Overrides:
        `close` in class `DelegatingConnection<Connection>`
      Throws:
        `SQLException`

    - #### reallyClose

          public void reallyClose()
                           throws SQLException

      Actually close my underlying `Connection`.
      Specified by:
        `reallyClose` in interface `PoolableConnectionMXBean`
      Throws:
        `SQLException`

    - #### getToString

          public String getToString()

      Expose the `DelegatingConnection.toString()` method via a bean getter so it can be read as a property via JMX.
      Specified by:
        `getToString` in interface `PoolableConnectionMXBean`

    - #### validate

          public void validate(String sql,
                      int timeout)
                        throws SQLException

      Throws:
        `SQLException`

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