Class BasicManagedDataSource
- java.lang.Object
-
- org.apache.commons.dbcp2.BasicDataSource
-
- org.apache.commons.dbcp2.managed.BasicManagedDataSource
-
- All Implemented Interfaces:
- AutoCloseable, Wrapper, MBeanRegistration, CommonDataSource, DataSource, BasicDataSourceMXBean
public class BasicManagedDataSource extends BasicDataSource
BasicManagedDataSource is an extension of BasicDataSource which creates ManagedConnections. This data source can create either full two-phase-commit XA connections or one-phase-commit local connections. Both types of connections are committed or rolled back as part of the global transaction (a.k.a. XA transaction or JTA Transaction), but only XA connections can be recovered in the case of a system crash.
BasicManagedDataSource adds the TransactionManager and XADataSource properties. The TransactionManager property is required and is used to enlist connections in global transactions. The XADataSource is optional and if set is the class name of the XADataSource class for a two-phase-commit JDBC driver. If the XADataSource property is set, the driverClassName is ignored and a DataSourceXAConnectionFactory is created. Otherwise, a standard DriverConnectionFactory is created and wrapped with a LocalXAConnectionFactory.
- Since:
- 2.0
- See Also:
BasicDataSource
,ManagedConnection
-
-
Constructor Summary
Constructors Constructor and Description BasicManagedDataSource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description protected ConnectionFactory
createConnectionFactory()
Creates a JDBC connection factory for this datasource.protected DataSource
createDataSourceInstance()
Creates the actual data source instance.protected PoolableConnectionFactory
createPoolableConnectionFactory(ConnectionFactory driverConnectionFactory)
Creates the PoolableConnectionFactory and attaches it to the connection pool.TransactionManager
getTransactionManager()
Gets the required transaction manager property.protected TransactionRegistry
getTransactionRegistry()
Gets the transaction registry.String
getXADataSource()
Gets the optional XADataSource class name.XADataSource
getXaDataSourceInstance()
Gets the XADataSource instance used by the XAConnectionFactory.void
setTransactionManager(TransactionManager transactionManager)
Sets the required transaction manager property.void
setXADataSource(String xaDataSource)
Sets the optional XADataSource class name.void
setXaDataSourceInstance(XADataSource xaDataSourceInstance)
Sets the XADataSource instance used by the XAConnectionFactory.-
Methods inherited from class org.apache.commons.dbcp2.BasicDataSource
addConnectionProperty, close, createConnectionPool, createDataSource, createObjectPool, getAbandonedLogWriter, getAbandonedUsageTracking, getCacheState, getConnection, getConnection, getConnectionInitSqls, getConnectionInitSqlsAsArray, getConnectionPool, getDefaultAutoCommit, getDefaultCatalog, getDefaultQueryTimeout, getDefaultReadOnly, getDefaultTransactionIsolation, getDisconnectionSqlCodes, getDisconnectionSqlCodesAsArray, getDriver, getDriverClassLoader, getDriverClassName, getEnableAutoCommitOnReturn, getEvictionPolicyClassName, getFastFailValidation, getInitialSize, getJmxName, getLifo, getLogAbandoned, getLogExpiredConnections, getLoginTimeout, getLogWriter, getMaxConnLifetimeMillis, getMaxIdle, getMaxOpenPreparedStatements, getMaxTotal, getMaxWaitMillis, getMinEvictableIdleTimeMillis, getMinIdle, getNumActive, getNumIdle, getNumTestsPerEvictionRun, getParentLogger, getPassword, getRegisteredJmxName, getRemoveAbandonedOnBorrow, getRemoveAbandonedOnMaintenance, getRemoveAbandonedTimeout, getRollbackOnReturn, getSoftMinEvictableIdleTimeMillis, getTestOnBorrow, getTestOnCreate, getTestOnReturn, getTestWhileIdle, getTimeBetweenEvictionRunsMillis, getUrl, getUsername, getValidationQuery, getValidationQueryTimeout, invalidateConnection, isAccessToUnderlyingConnectionAllowed, isClosed, isPoolPreparedStatements, isWrapperFor, log, postDeregister, postRegister, preDeregister, preRegister, removeConnectionProperty, setAbandonedLogWriter, setAbandonedUsageTracking, setAccessToUnderlyingConnectionAllowed, setCacheState, setConnectionInitSqls, setConnectionProperties, setDefaultAutoCommit, setDefaultCatalog, setDefaultQueryTimeout, setDefaultReadOnly, setDefaultTransactionIsolation, setDisconnectionSqlCodes, setDriver, setDriverClassLoader, setDriverClassName, setEnableAutoCommitOnReturn, setEvictionPolicyClassName, setFastFailValidation, setInitialSize, setJmxName, setLifo, setLogAbandoned, setLogExpiredConnections, setLoginTimeout, setLogWriter, setMaxConnLifetimeMillis, setMaxIdle, setMaxOpenPreparedStatements, setMaxTotal, setMaxWaitMillis, setMinEvictableIdleTimeMillis, setMinIdle, setNumTestsPerEvictionRun, setPassword, setPoolPreparedStatements, setRemoveAbandonedOnBorrow, setRemoveAbandonedOnMaintenance, setRemoveAbandonedTimeout, setRollbackOnReturn, setSoftMinEvictableIdleTimeMillis, setTestOnBorrow, setTestOnCreate, setTestOnReturn, setTestWhileIdle, setTimeBetweenEvictionRunsMillis, setUrl, setUsername, setValidationQuery, setValidationQueryTimeout, startPoolMaintenance, unwrap, validateConnectionFactory
-
-
-
-
Constructor Detail
-
BasicManagedDataSource
public BasicManagedDataSource()
-
-
Method Detail
-
getXaDataSourceInstance
public XADataSource getXaDataSourceInstance()
Gets the XADataSource instance used by the XAConnectionFactory.- Returns:
- the XADataSource
-
setXaDataSourceInstance
public void setXaDataSourceInstance(XADataSource xaDataSourceInstance)
Sets the XADataSource instance used by the XAConnectionFactory.
Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first time one of the following methods is invoked:
getConnection, setLogwriter, setLoginTimeout, getLoginTimeout, getLogWriter.
- Parameters:
xaDataSourceInstance
- XADataSource instance
-
getTransactionManager
public TransactionManager getTransactionManager()
Gets the required transaction manager property.- Returns:
- the transaction manager used to enlist connections
-
getTransactionRegistry
protected TransactionRegistry getTransactionRegistry()
Gets the transaction registry.- Returns:
- the transaction registry associating XAResources with managed connections
-
setTransactionManager
public void setTransactionManager(TransactionManager transactionManager)
Sets the required transaction manager property.- Parameters:
transactionManager
- the transaction manager used to enlist connections
-
getXADataSource
public String getXADataSource()
Gets the optional XADataSource class name.- Returns:
- the optional XADataSource class name
-
setXADataSource
public void setXADataSource(String xaDataSource)
Sets the optional XADataSource class name.- Parameters:
xaDataSource
- the optional XADataSource class name
-
createConnectionFactory
protected ConnectionFactory createConnectionFactory() throws SQLException
Description copied from class:BasicDataSource
Creates a JDBC connection factory for this datasource. The JDBC driver is loaded using the following algorithm:- If a Driver instance has been specified via
BasicDataSource.setDriver(Driver)
use it - If no Driver instance was specified and
BasicDataSource.driverClassName
is specified that class is loaded using theClassLoader
of this class or, ifBasicDataSource.driverClassLoader
is set,BasicDataSource.driverClassName
is loaded with the specifiedClassLoader
. - If
BasicDataSource.driverClassName
is specified and the previous attempt fails, the class is loaded using the context class loader of the current thread. - If a driver still isn't loaded one is loaded via the
DriverManager
using the specifiedBasicDataSource.url
.
- Overrides:
createConnectionFactory
in classBasicDataSource
- Throws:
SQLException
- If a Driver instance has been specified via
-
createDataSourceInstance
protected DataSource createDataSourceInstance() throws SQLException
Description copied from class:BasicDataSource
Creates the actual data source instance. This method only exists so that subclasses can replace the implementation class.- Overrides:
createDataSourceInstance
in classBasicDataSource
- Throws:
SQLException
- if unable to create a datasource instance
-
createPoolableConnectionFactory
protected PoolableConnectionFactory createPoolableConnectionFactory(ConnectionFactory driverConnectionFactory) throws SQLException
Creates the PoolableConnectionFactory and attaches it to the connection pool.- Overrides:
createPoolableConnectionFactory
in classBasicDataSource
- Parameters:
driverConnectionFactory
- JDBC connection factory created bycreateConnectionFactory()
- Throws:
SQLException
- if an error occurs creating the PoolableConnectionFactory
-
-