Search in sources :

Example 1 with XAConnectionFactory

use of org.apache.commons.dbcp2.managed.XAConnectionFactory in project tomee by apache.

the class DbcpManagedDataSource method createConnectionFactory.

@Override
protected ConnectionFactory createConnectionFactory() throws SQLException {
    if (ds instanceof XADataSource) {
        // Create the XAConectionFactory using the XA data source
        final XADataSource xaDataSourceInstance = (XADataSource) ds;
        final XAConnectionFactory xaConnectionFactory = new DataSourceXAConnectionFactory(getTransactionManager(), xaDataSourceInstance, getUsername(), getPassword());
        setTransactionRegistry(xaConnectionFactory.getTransactionRegistry());
        return xaConnectionFactory;
    }
    // If xa data source is not specified a DriverConnectionFactory is created and wrapped with a LocalXAConnectionFactory
    final ConnectionFactory connectionFactory = new DataSourceConnectionFactory(DataSource.class.cast(ds), getUsername(), getPassword());
    final XAConnectionFactory xaConnectionFactory = new LocalXAConnectionFactory(getTransactionManager(), connectionFactory);
    setTransactionRegistry(xaConnectionFactory.getTransactionRegistry());
    return xaConnectionFactory;
}
Also used : XADataSource(javax.sql.XADataSource) ConnectionFactory(org.apache.commons.dbcp2.ConnectionFactory) DataSourceConnectionFactory(org.apache.commons.dbcp2.DataSourceConnectionFactory) DataSourceXAConnectionFactory(org.apache.commons.dbcp2.managed.DataSourceXAConnectionFactory) LocalXAConnectionFactory(org.apache.commons.dbcp2.managed.LocalXAConnectionFactory) XAConnectionFactory(org.apache.commons.dbcp2.managed.XAConnectionFactory) DataSourceConnectionFactory(org.apache.commons.dbcp2.DataSourceConnectionFactory) DataSourceXAConnectionFactory(org.apache.commons.dbcp2.managed.DataSourceXAConnectionFactory) DataSourceXAConnectionFactory(org.apache.commons.dbcp2.managed.DataSourceXAConnectionFactory) LocalXAConnectionFactory(org.apache.commons.dbcp2.managed.LocalXAConnectionFactory) XAConnectionFactory(org.apache.commons.dbcp2.managed.XAConnectionFactory) LocalXAConnectionFactory(org.apache.commons.dbcp2.managed.LocalXAConnectionFactory) CommonDataSource(javax.sql.CommonDataSource) DataSource(javax.sql.DataSource) XADataSource(javax.sql.XADataSource)

Aggregations

CommonDataSource (javax.sql.CommonDataSource)1 DataSource (javax.sql.DataSource)1 XADataSource (javax.sql.XADataSource)1 ConnectionFactory (org.apache.commons.dbcp2.ConnectionFactory)1 DataSourceConnectionFactory (org.apache.commons.dbcp2.DataSourceConnectionFactory)1 DataSourceXAConnectionFactory (org.apache.commons.dbcp2.managed.DataSourceXAConnectionFactory)1 LocalXAConnectionFactory (org.apache.commons.dbcp2.managed.LocalXAConnectionFactory)1 XAConnectionFactory (org.apache.commons.dbcp2.managed.XAConnectionFactory)1