Package org.apache.commons.dbcp2

# Class PoolingDataSource<C extends Connection>

java.lang.Object
org.apache.commons.dbcp2.PoolingDataSource<C>

Type Parameters:
  `C` - The connection type

All Implemented Interfaces:
  `AutoCloseable`, `Wrapper`, `CommonDataSource`, `DataSource`

Direct Known Subclasses:
  `ManagedDataSource`

public class PoolingDataSource<C extends Connection> extends Object implements DataSource, AutoCloseable
A simple `DataSource` implementation that obtains `Connection`s from the specified `ObjectPool`.

Since:
  2.0

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PoolingDataSource(ObjectPool<C> pool)`
  Constructs a new instance backed by the given connection pool.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  Closes and free all `Connection`s from the pool.
  `Connection`
  `getConnection()`
  Returns a `Connection` from my pool, according to the contract specified by `ObjectPool.borrowObject()`.
  `Connection`
  `getConnection(String userName, String password)`
  Throws `UnsupportedOperationException`
  `int`
  `getLoginTimeout()`
  Throws `UnsupportedOperationException`.
  `PrintWriter`
  `getLogWriter()`
  Returns my log writer.
  `Logger`
  `getParentLogger()`
  `protected ObjectPool<C>`
  `getPool()`
  Gets the backing object pool.
  `boolean`
  `isAccessToUnderlyingConnectionAllowed()`
  Returns the value of the accessToUnderlyingConnectionAllowed property.
  `boolean`
  `isWrapperFor(Class<?> iface)`
  `void`
  `setAccessToUnderlyingConnectionAllowed(boolean allow)`
  Sets the value of the accessToUnderlyingConnectionAllowed property.
  `void`
  `setLoginTimeout(int seconds)`
  Throws `UnsupportedOperationException`.
  `void`
  `setLogWriter(PrintWriter out)`
  Sets my log writer.
  `<T> T`
  `unwrap(Class<T> iface)`

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

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

- ## Constructor Details

  - ### PoolingDataSource

    public PoolingDataSource(ObjectPool<C> pool)
    Constructs a new instance backed by the given connection pool.
    Parameters:
      `pool` - the given connection pool.

- ## Method Details

  - ### close

    public void close() throws SQLException
    Closes and free all `Connection`s from the pool.
    Specified by:
      `close` in interface `AutoCloseable`
    Throws:
      `SQLException`
    Since:
      2.1

  - ### getConnection

    public Connection getConnection() throws SQLException
    Returns a `Connection` from my pool, according to the contract specified by `ObjectPool.borrowObject()`.
    Specified by:
      `getConnection` in interface `DataSource`
    Throws:
      `SQLException`

  - ### getConnection

    public Connection getConnection(String userName, String password) throws SQLException
    Throws `UnsupportedOperationException`
    Specified by:
      `getConnection` in interface `DataSource`
    Throws:
      `UnsupportedOperationException` - always thrown
      `SQLException`

  - ### getLoginTimeout

    public int getLoginTimeout()
    Throws `UnsupportedOperationException`.
    Specified by:
      `getLoginTimeout` in interface `CommonDataSource`
    Throws:
      `UnsupportedOperationException` - As this implementation does not support this feature.

  - ### getLogWriter

    public PrintWriter getLogWriter()
    Returns my log writer.
    Specified by:
      `getLogWriter` in interface `CommonDataSource`
    Returns:
      my log writer
    See Also:
      - `CommonDataSource.getLogWriter()`

  - ### getParentLogger

    public Logger getParentLogger() throws SQLFeatureNotSupportedException
    Specified by:
      `getParentLogger` in interface `CommonDataSource`
    Throws:
      `SQLFeatureNotSupportedException`

  - ### getPool

    protected ObjectPool<C> getPool()
    Gets the backing object pool.
    Returns:
      the backing object pool.

  - ### isAccessToUnderlyingConnectionAllowed

    public boolean isAccessToUnderlyingConnectionAllowed()
    Returns the value of the accessToUnderlyingConnectionAllowed property.
    Returns:
      true if access to the underlying `Connection` is allowed, false otherwise.

  - ### isWrapperFor

    public boolean isWrapperFor(Class<?> iface) throws SQLException
    Specified by:
      `isWrapperFor` in interface `Wrapper`
    Throws:
      `SQLException`

  - ### setAccessToUnderlyingConnectionAllowed

    public void setAccessToUnderlyingConnectionAllowed(boolean allow)
    Sets the value of the accessToUnderlyingConnectionAllowed property. It controls if the PoolGuard allows access to the underlying connection. (Default: false)
    Parameters:
      `allow` - Access to the underlying connection is granted when true.

  - ### setLoginTimeout

    public void setLoginTimeout(int seconds)
    Throws `UnsupportedOperationException`.
    Specified by:
      `setLoginTimeout` in interface `CommonDataSource`
    Throws:
      `UnsupportedOperationException` - As this implementation does not support this feature.

  - ### setLogWriter

    public void setLogWriter(PrintWriter out)
    Sets my log writer.
    Specified by:
      `setLogWriter` in interface `CommonDataSource`
    See Also:
      - `CommonDataSource.setLogWriter(java.io.PrintWriter)`

  - ### unwrap

    public <T> T unwrap(Class<T> iface) throws SQLException
    Specified by:
      `unwrap` in interface `Wrapper`
    Throws:
      `SQLException`