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 ofConnectionto manage.
- All Implemented Interfaces:
AutoCloseable, Wrapper, CommonDataSource, DataSource
The ManagedDataSource is a PoolingDataSource that creates ManagedConnections.
- Since:
- 2.0
- Version:
- $Id: ManagedDataSource.java 1650024 2015-01-07 09:49:58Z tn $
- Author:
- Dain Sundstrom
-
Constructor Summary
ConstructorsConstructorDescriptionManagedDataSource(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
Modifier and TypeMethodDescriptionReturn aConnectionfrom my pool, according to the contract specified byObjectPool.borrowObject().voidsetTransactionRegistry(TransactionRegistry transactionRegistry) Sets the transaction registry from the XAConnectionFactory used to create the pool.Methods inherited from class PoolingDataSource
close, getConnection, getLoginTimeout, getLogWriter, getParentLogger, isAccessToUnderlyingConnectionAllowed, isWrapperFor, setAccessToUnderlyingConnectionAllowed, setLoginTimeout, setLogWriter, unwrapMethods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CommonDataSource
createShardingKeyBuilderMethods inherited from interface DataSource
createConnectionBuilder
-
Constructor Details
-
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 occur 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 pooltransactionRegistry- the transaction registry obtained from the XAConnectionFactory used to create the connection pool object factory
-
-
Method Details
-
setTransactionRegistry
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
Description copied from class:PoolingDataSourceReturn aConnectionfrom my pool, according to the contract specified byObjectPool.borrowObject().- Specified by:
getConnectionin interfaceDataSource- Overrides:
getConnectionin classPoolingDataSource<C extends Connection>- Throws:
SQLException
-