org.apache.commons.dbcp2.managed

## Class ManagedDataSource<C extends Connection>

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

- Type Parameters:
    `C` - The kind of `Connection` to manage.
  All Implemented Interfaces:
    Wrapper, CommonDataSource, DataSource

      public class ManagedDataSource<C extends Connection>
      extends PoolingDataSource<C>

  The ManagedDataSource is a PoolingDataSource that creates ManagedConnections.
  Since:
    2.0
  Author:
    Dain Sundstrom

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ManagedDataSource(org.apache.commons.pool2.ObjectPool<C> pool, TransactionRegistry transactionRegistry)` Creates a ManagedDataSource which obtains connections from the specified pool and manages them using the specified transaction registry.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Connection` | `getConnection()` Return a `Connection` from my pool, according to the contract specified by `ObjectPool.borrowObject()`.
    `void` | `setTransactionRegistry(TransactionRegistry transactionRegistry)` Sets the transaction registry from the XAConnectionFactory used to create the pool.

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

      `getConnection, getLoginTimeout, getLogWriter, getParentLogger, getPool, isAccessToUnderlyingConnectionAllowed, isWrapperFor, setAccessToUnderlyingConnectionAllowed, setLoginTimeout, setLogWriter, unwrap`

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

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

- - ### Constructor Detail

    - #### ManagedDataSource

          public ManagedDataSource(org.apache.commons.pool2.ObjectPool<C> pool,
                           TransactionRegistry transactionRegistry)

      Creates a ManagedDataSource which obtains connections from the specified pool and manages them using the specified transaction registry. The TransactionRegistry must be the transaction registry obtained from the XAConnectionFactory used to create the connection pool. If not an error will occure when attempting to use the connection in a global transaction because the XAResource object associated with the connection will be unavailable.
      Parameters:
        `pool` - the connection pool
        `transactionRegistry` - the transaction registry obtained from the XAConnectionFactory used to create the connection pool object factory

  - ### Method Detail

    - #### setTransactionRegistry

          public void setTransactionRegistry(TransactionRegistry transactionRegistry)

      Sets the transaction registry from the XAConnectionFactory used to create the pool. The transaction registry can only be set once using either a connector or this setter method.
      Parameters:
        `transactionRegistry` - the transaction registry acquired from the XAConnectionFactory used to create the pool

    - #### getConnection

          public Connection getConnection()
                                   throws SQLException

      Description copied from class: `PoolingDataSource`
      Return a `Connection` from my pool, according to the contract specified by `ObjectPool.borrowObject()`.
      Specified by:
        `getConnection` in interface `DataSource`
      Overrides:
        `getConnection` in class `PoolingDataSource<C extends Connection>`
      Throws:
        `SQLException`

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