Search in sources :

Example 11 with XADataSource

use of javax.sql.XADataSource in project aries by apache.

the class JDBCConnectionProviderFactoryImpl method getProviderFor.

@Override
public AbstractJDBCConnectionProvider getProviderFor(XADataSource ds, Map<String, Object> resourceProviderProperties) {
    boolean xaEnabled = toBoolean(resourceProviderProperties, XA_ENLISTMENT_ENABLED, true);
    boolean localEnabled = toBoolean(resourceProviderProperties, LOCAL_ENLISTMENT_ENABLED, true);
    checkEnlistment(xaEnabled, localEnabled, true);
    DataSource unpooled = new XADataSourceMapper(ds);
    return new JDBCConnectionProviderImpl(poolIfNecessary(resourceProviderProperties, unpooled), xaEnabled, localEnabled, getRecoveryId(resourceProviderProperties, xaEnabled));
}
Also used : XADataSourceMapper(org.apache.aries.tx.control.jdbc.xa.connection.impl.XADataSourceMapper) XADataSource(javax.sql.XADataSource) DriverDataSource(org.apache.aries.tx.control.jdbc.common.impl.DriverDataSource) DataSource(javax.sql.DataSource)

Example 12 with XADataSource

use of javax.sql.XADataSource in project aries by apache.

the class JDBCConnectionProviderFactoryImpl method getProviderFor.

@Override
public AbstractJDBCConnectionProvider getProviderFor(XADataSource ds, Map<String, Object> resourceProviderProperties) {
    checkEnlistment(resourceProviderProperties);
    DataSource unpooled;
    if (ds instanceof DataSource) {
        unpooled = (DataSource) ds;
    } else {
        throw new TransactionException("This resource Provider does not support XA transactions, and the supplied XADataSource is not a DataSource");
    }
    return new JDBCConnectionProviderImpl(poolIfNecessary(resourceProviderProperties, unpooled));
}
Also used : TransactionException(org.osgi.service.transaction.control.TransactionException) XADataSource(javax.sql.XADataSource) DriverDataSource(org.apache.aries.tx.control.jdbc.common.impl.DriverDataSource) DataSource(javax.sql.DataSource)

Example 13 with XADataSource

use of javax.sql.XADataSource in project tomee by apache.

the class BoneCPDataSourceCreator method pool.

@Override
public CommonDataSource pool(final String name, final String driver, final Properties properties) {
    final BoneCPDataSource pool = createPool(properties);
    if (pool.getDriverClass() == null) {
        pool.setDriverClass(driver);
    }
    if (pool.getPoolName() == null) {
        pool.setPoolName(name);
    }
    final String xa = String.class.cast(properties.remove("XaDataSource"));
    if (xa != null) {
        final XADataSource xaDs = XADataSourceResource.proxy(Thread.currentThread().getContextClassLoader(), xa);
        pool.setDatasourceBean(new ManagedXADataSource(xaDs, OpenEJB.getTransactionManager(), SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class)));
    }
    return pool;
}
Also used : XADataSource(javax.sql.XADataSource) ManagedXADataSource(org.apache.openejb.resource.jdbc.managed.xa.ManagedXADataSource) ManagedXADataSource(org.apache.openejb.resource.jdbc.managed.xa.ManagedXADataSource) BoneCPDataSource(com.jolbox.bonecp.BoneCPDataSource)

Example 14 with XADataSource

use of javax.sql.XADataSource 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

XADataSource (javax.sql.XADataSource)14 DataSource (javax.sql.DataSource)8 CommonDataSource (javax.sql.CommonDataSource)5 Test (org.junit.Test)4 TransactionManager (javax.transaction.TransactionManager)3 ManagedXADataSource (org.apache.openejb.resource.jdbc.managed.xa.ManagedXADataSource)3 DriverDataSource (org.apache.aries.tx.control.jdbc.common.impl.DriverDataSource)2 ManagedDataSource (org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource)2 BundleContext (org.osgi.framework.BundleContext)2 BoneCPDataSource (com.jolbox.bonecp.BoneCPDataSource)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Hashtable (java.util.Hashtable)1 Properties (java.util.Properties)1 ServletException (javax.servlet.ServletException)1 XAConnection (javax.sql.XAConnection)1 HeuristicMixedException (javax.transaction.HeuristicMixedException)1 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)1 NotSupportedException (javax.transaction.NotSupportedException)1