Class BasicManagedDataSource
- java.lang.Object
- 
- org.apache.tomcat.dbcp.dbcp2.BasicDataSource
- 
- org.apache.tomcat.dbcp.dbcp2.managed.BasicManagedDataSource
 
 
- 
- All Implemented Interfaces:
- java.lang.AutoCloseable,- java.sql.Wrapper,- javax.management.MBeanRegistration,- javax.sql.CommonDataSource,- javax.sql.DataSource,- BasicDataSourceMXBean,- DataSourceMXBean
 
 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 SummaryConstructors Constructor Description BasicManagedDataSource()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ConnectionFactorycreateConnectionFactory()Creates a JDBC connection factory for this data source.protected javax.sql.DataSourcecreateDataSourceInstance()Creates the actual data source instance.protected PoolableConnectionFactorycreatePoolableConnectionFactory(ConnectionFactory driverConnectionFactory)Creates the PoolableConnectionFactory and attaches it to the connection pool.TransactionManagergetTransactionManager()Gets the required transaction manager property.protected TransactionRegistrygetTransactionRegistry()Gets the transaction registry.TransactionSynchronizationRegistrygetTransactionSynchronizationRegistry()Gets the optional TransactionSynchronizationRegistry.java.lang.StringgetXADataSource()Gets the optional XADataSource class name.javax.sql.XADataSourcegetXaDataSourceInstance()Gets the XADataSource instance used by the XAConnectionFactory.voidsetTransactionManager(TransactionManager transactionManager)Sets the required transaction manager property.voidsetTransactionSynchronizationRegistry(TransactionSynchronizationRegistry transactionSynchronizationRegistry)Sets the optional TransactionSynchronizationRegistry property.voidsetXADataSource(java.lang.String xaDataSource)Sets the optional XADataSource class name.voidsetXaDataSourceInstance(javax.sql.XADataSource xaDataSourceInstance)Sets the XADataSource instance used by the XAConnectionFactory.- 
Methods inherited from class org.apache.tomcat.dbcp.dbcp2.BasicDataSourceaddConnectionProperty, close, createConnectionPool, createDataSource, createObjectPool, evict, getAbandonedLogWriter, getAbandonedUsageTracking, getAutoCommitOnReturn, getCacheState, getConnection, getConnection, getConnectionFactoryClassName, getConnectionInitSqls, getConnectionInitSqlsAsArray, getConnectionPool, getDefaultAutoCommit, getDefaultCatalog, getDefaultQueryTimeout, getDefaultQueryTimeoutDuration, getDefaultReadOnly, getDefaultSchema, getDefaultTransactionIsolation, getDisconnectionSqlCodes, getDisconnectionSqlCodesAsArray, getDriver, getDriverClassLoader, getDriverClassName, getDurationBetweenEvictionRuns, getEnableAutoCommitOnReturn, getEvictionPolicyClassName, getFastFailValidation, getInitialSize, getJmxName, getLifo, getLogAbandoned, getLogExpiredConnections, getLoginTimeout, getLogWriter, getMaxConnDuration, getMaxConnLifetimeMillis, getMaxIdle, getMaxOpenPreparedStatements, getMaxTotal, getMaxWaitDuration, getMaxWaitMillis, getMinEvictableIdleDuration, getMinEvictableIdleTimeMillis, getMinIdle, getNumActive, getNumIdle, getNumTestsPerEvictionRun, getParentLogger, getPassword, getRegisteredJmxName, getRemoveAbandonedOnBorrow, getRemoveAbandonedOnMaintenance, getRemoveAbandonedTimeout, getRemoveAbandonedTimeoutDuration, getRollbackOnReturn, getSoftMinEvictableIdleDuration, getSoftMinEvictableIdleTimeMillis, getTestOnBorrow, getTestOnCreate, getTestOnReturn, getTestWhileIdle, getTimeBetweenEvictionRunsMillis, getUrl, getUsername, getValidationQuery, getValidationQueryTimeout, getValidationQueryTimeoutDuration, invalidateConnection, isAccessToUnderlyingConnectionAllowed, isClearStatementPoolOnReturn, isClosed, isPoolPreparedStatements, isWrapperFor, log, log, postDeregister, postRegister, preDeregister, preRegister, removeConnectionProperty, restart, setAbandonedLogWriter, setAbandonedUsageTracking, setAccessToUnderlyingConnectionAllowed, setAutoCommitOnReturn, setCacheState, setClearStatementPoolOnReturn, setConnectionFactoryClassName, setConnectionInitSqls, setConnectionProperties, setDefaultAutoCommit, setDefaultCatalog, setDefaultQueryTimeout, setDefaultQueryTimeout, setDefaultReadOnly, setDefaultSchema, setDefaultTransactionIsolation, setDisconnectionSqlCodes, setDriver, setDriverClassLoader, setDriverClassName, setDurationBetweenEvictionRuns, setEnableAutoCommitOnReturn, setEvictionPolicyClassName, setFastFailValidation, setInitialSize, setJmxName, setLifo, setLogAbandoned, setLogExpiredConnections, setLoginTimeout, setLogWriter, setMaxConn, setMaxConnLifetimeMillis, setMaxIdle, setMaxOpenPreparedStatements, setMaxTotal, setMaxWait, setMaxWaitMillis, setMinEvictableIdle, setMinEvictableIdleTimeMillis, setMinIdle, setNumTestsPerEvictionRun, setPassword, setPoolPreparedStatements, setRegisterConnectionMBean, setRemoveAbandonedOnBorrow, setRemoveAbandonedOnMaintenance, setRemoveAbandonedTimeout, setRemoveAbandonedTimeout, setRollbackOnReturn, setSoftMinEvictableIdle, setSoftMinEvictableIdleTimeMillis, setTestOnBorrow, setTestOnCreate, setTestOnReturn, setTestWhileIdle, setTimeBetweenEvictionRunsMillis, setUrl, setUsername, setValidationQuery, setValidationQueryTimeout, setValidationQueryTimeout, start, startPoolMaintenance, unwrap, validateConnectionFactory
 
- 
 
- 
- 
- 
Method Detail- 
createConnectionFactoryprotected ConnectionFactory createConnectionFactory() throws java.sql.SQLException Description copied from class:BasicDataSourceCreates a JDBC connection factory for this data source. 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 {code driverClassName} is specified that class is loaded using the
 ClassLoaderof this class or, if {code driverClassLoader} is set, {code driverClassName} is loaded with the specifiedClassLoader.
- If {code 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 DriverManagerusing the specified {code connectionString}.
 This method exists so subclasses can replace the implementation class. - Overrides:
- createConnectionFactoryin class- BasicDataSource
- Returns:
- A new connection factory.
- Throws:
- java.sql.SQLException- If the connection factory cannot be created
 
- If a Driver instance has been specified via 
 - 
createDataSourceInstanceprotected javax.sql.DataSource createDataSourceInstance() throws java.sql.SQLExceptionDescription copied from class:BasicDataSourceCreates the actual data source instance. This method only exists so that subclasses can replace the implementation class.- Overrides:
- createDataSourceInstancein class- BasicDataSource
- Returns:
- A new DataSource instance
- Throws:
- java.sql.SQLException- if unable to create a datasource instance
 
 - 
createPoolableConnectionFactoryprotected PoolableConnectionFactory createPoolableConnectionFactory(ConnectionFactory driverConnectionFactory) throws java.sql.SQLException Creates the PoolableConnectionFactory and attaches it to the connection pool.- Overrides:
- createPoolableConnectionFactoryin class- BasicDataSource
- Parameters:
- driverConnectionFactory- JDBC connection factory created by- createConnectionFactory()
- Returns:
- A new PoolableConnectionFactory configured with the current configuration of this BasicDataSource
- Throws:
- java.sql.SQLException- if an error occurs creating the PoolableConnectionFactory
 
 - 
getTransactionManagerpublic TransactionManager getTransactionManager() Gets the required transaction manager property.- Returns:
- the transaction manager used to enlist connections
 
 - 
getTransactionRegistryprotected TransactionRegistry getTransactionRegistry() Gets the transaction registry.- Returns:
- the transaction registry associating XAResources with managed connections
 
 - 
getTransactionSynchronizationRegistrypublic TransactionSynchronizationRegistry getTransactionSynchronizationRegistry() Gets the optional TransactionSynchronizationRegistry.- Returns:
- the TSR that can be used to register synchronizations.
- Since:
- 2.6.0
 
 - 
getXADataSourcepublic java.lang.String getXADataSource() Gets the optional XADataSource class name.- Returns:
- the optional XADataSource class name
 
 - 
getXaDataSourceInstancepublic javax.sql.XADataSource getXaDataSourceInstance() Gets the XADataSource instance used by the XAConnectionFactory.- Returns:
- the XADataSource
 
 - 
setTransactionManagerpublic void setTransactionManager(TransactionManager transactionManager) Sets the required transaction manager property.- Parameters:
- transactionManager- the transaction manager used to enlist connections
 
 - 
setTransactionSynchronizationRegistrypublic void setTransactionSynchronizationRegistry(TransactionSynchronizationRegistry transactionSynchronizationRegistry) Sets the optional TransactionSynchronizationRegistry property.- Parameters:
- transactionSynchronizationRegistry- the TSR used to register synchronizations
- Since:
- 2.6.0
 
 - 
setXADataSourcepublic void setXADataSource(java.lang.String xaDataSource) Sets the optional XADataSource class name.- Parameters:
- xaDataSource- the optional XADataSource class name
 
 - 
setXaDataSourceInstancepublic void setXaDataSourceInstance(javax.sql.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
 
 
- 
 
-