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 elist 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.
BasicDataSource
,
ManagedConnection
Modifier and Type | Field and Description |
---|---|
private javax.transaction.TransactionManager |
transactionManager
Transaction Manager
|
private TransactionRegistry |
transactionRegistry
Transaction Registry
|
private java.lang.String |
xaDataSource
XA datasource class name
|
private javax.sql.XADataSource |
xaDataSourceInstance
XA datasource instance
|
closed, connectionInitSqls, connectionPool, connectionProperties, dataSource, defaultAutoCommit, defaultCatalog, defaultReadOnly, defaultTransactionIsolation, driverClassLoader, driverClassName, initialSize, logWriter, maxActive, maxIdle, maxOpenPreparedStatements, maxWait, minEvictableIdleTimeMillis, minIdle, numTestsPerEvictionRun, password, poolPreparedStatements, testOnBorrow, testOnReturn, testWhileIdle, timeBetweenEvictionRunsMillis, url, username, validationQuery, validationQueryTimeout
Constructor and Description |
---|
BasicManagedDataSource() |
Modifier and Type | Method and Description |
---|---|
protected ConnectionFactory |
createConnectionFactory()
Creates a JDBC connection factory for this datasource.
|
protected void |
createDataSourceInstance()
Creates the actual data source instance.
|
protected void |
createPoolableConnectionFactory(ConnectionFactory driverConnectionFactory,
org.apache.commons.pool.KeyedObjectPoolFactory statementPoolFactory,
AbandonedConfig abandonedConfig)
Creates the PoolableConnectionFactory and attaches it to the connection pool.
|
javax.transaction.TransactionManager |
getTransactionManager()
Gets the required transaction manager property.
|
protected TransactionRegistry |
getTransactionRegistry()
Gets the transaction registry.
|
java.lang.String |
getXADataSource()
Gets the optional XADataSource class name.
|
javax.sql.XADataSource |
getXaDataSourceInstance()
Gets the XADataSource instance used by the XAConnectionFactory.
|
void |
setTransactionManager(javax.transaction.TransactionManager transactionManager)
Sets the required transaction manager property.
|
void |
setXADataSource(java.lang.String xaDataSource)
Sets the optional XADataSource class name.
|
void |
setXaDataSourceInstance(javax.sql.XADataSource xaDataSourceInstance)
Sets the XADataSource instance used by the XAConnectionFactory.
|
addConnectionProperty, close, createConnectionPool, createDataSource, getConnection, getConnection, getConnectionInitSqls, getDefaultAutoCommit, getDefaultCatalog, getDefaultReadOnly, getDefaultTransactionIsolation, getDriverClassLoader, getDriverClassName, getInitialSize, getLogAbandoned, getLoginTimeout, getLogWriter, getMaxActive, getMaxIdle, getMaxOpenPreparedStatements, getMaxWait, getMinEvictableIdleTimeMillis, getMinIdle, getNumActive, getNumIdle, getNumTestsPerEvictionRun, getParentLogger, getPassword, getRemoveAbandoned, getRemoveAbandonedTimeout, getTestOnBorrow, getTestOnReturn, getTestWhileIdle, getTimeBetweenEvictionRunsMillis, getUrl, getUsername, getValidationQuery, getValidationQueryTimeout, isAccessToUnderlyingConnectionAllowed, isClosed, isPoolPreparedStatements, isWrapperFor, log, removeConnectionProperty, setAccessToUnderlyingConnectionAllowed, setConnectionInitSqls, setConnectionProperties, setDefaultAutoCommit, setDefaultCatalog, setDefaultReadOnly, setDefaultTransactionIsolation, setDriverClassLoader, setDriverClassName, setInitialSize, setLogAbandoned, setLoginTimeout, setLogWriter, setMaxActive, setMaxIdle, setMaxOpenPreparedStatements, setMaxWait, setMinEvictableIdleTimeMillis, setMinIdle, setNumTestsPerEvictionRun, setPassword, setPoolPreparedStatements, setRemoveAbandoned, setRemoveAbandonedTimeout, setTestOnBorrow, setTestOnReturn, setTestWhileIdle, setTimeBetweenEvictionRunsMillis, setUrl, setUsername, setValidationQuery, setValidationQueryTimeout, unwrap, validateConnectionFactory
private TransactionRegistry transactionRegistry
private transient javax.transaction.TransactionManager transactionManager
private java.lang.String xaDataSource
private javax.sql.XADataSource xaDataSourceInstance
public javax.sql.XADataSource getXaDataSourceInstance()
public 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.
xaDataSourceInstance
- XADataSource instancepublic javax.transaction.TransactionManager getTransactionManager()
protected TransactionRegistry getTransactionRegistry()
public void setTransactionManager(javax.transaction.TransactionManager transactionManager)
transactionManager
- the transaction manager used to enlist connectionspublic java.lang.String getXADataSource()
public void setXADataSource(java.lang.String xaDataSource)
xaDataSource
- the optional XADataSource class nameprotected ConnectionFactory createConnectionFactory() throws java.sql.SQLException
BasicDataSource
createConnectionFactory
in class BasicDataSource
java.sql.SQLException
protected void createDataSourceInstance() throws java.sql.SQLException
BasicDataSource
createDataSourceInstance
in class BasicDataSource
java.sql.SQLException
- if unable to create a datasource instanceprotected void createPoolableConnectionFactory(ConnectionFactory driverConnectionFactory, org.apache.commons.pool.KeyedObjectPoolFactory statementPoolFactory, AbandonedConfig abandonedConfig) throws java.sql.SQLException
createPoolableConnectionFactory
in class BasicDataSource
driverConnectionFactory
- JDBC connection factory created by createConnectionFactory()
statementPoolFactory
- statement pool factory (null if statement pooling is turned off)abandonedConfig
- abandoned connection tracking configuration (null if no tracking)java.sql.SQLException
- if an error occurs creating the PoolableConnectionFactory