Search in sources :

Example 1 with XADataSource

use of javax.sql.XADataSource in project spring-boot by spring-projects.

the class AtomikosXADataSourceWrapperTests method wrap.

@Test
public void wrap() throws Exception {
    XADataSource dataSource = mock(XADataSource.class);
    AtomikosXADataSourceWrapper wrapper = new AtomikosXADataSourceWrapper();
    DataSource wrapped = wrapper.wrapDataSource(dataSource);
    assertThat(wrapped).isInstanceOf(AtomikosDataSourceBean.class);
    assertThat(((AtomikosDataSourceBean) wrapped).getXaDataSource()).isSameAs(dataSource);
}
Also used : XADataSource(javax.sql.XADataSource) DataSource(javax.sql.DataSource) XADataSource(javax.sql.XADataSource) Test(org.junit.Test)

Example 2 with XADataSource

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

the class ManagedDataSourceFactory method register.

public void register() throws Exception {
    boolean isXaDataSource = (dataSource instanceof XADataSource);
    Hashtable<String, Object> props = new Hashtable<String, Object>(this.properties);
    props.put("aries.managed", "true");
    if (isXaDataSource) {
        props.put("aries.xa.aware", "true");
    }
    props.put("jmx.objectname", "org.apache.aries.transaction:type=jdbc,name=" + getResourceName());
    props.put(Constants.SERVICE_RANKING, getInt(Constants.SERVICE_RANKING, 0) + 1000);
    ds = new RecoverableDataSource();
    ds.setDataSource(dataSource);
    ds.setExceptionSorter(getString("aries.xa.exceptionSorter", "all"));
    ds.setUsername(getString("aries.xa.username", null));
    ds.setPassword(getString("aries.xa.password", null));
    ds.setTransactionManager(transactionManager);
    ds.setAllConnectionsEquals(getBool("aries.xa.allConnectionsEquals", true));
    ds.setConnectionMaxIdleMinutes(getInt("aries.xa.connectionMadIdleMinutes", 15));
    ds.setConnectionMaxWaitMilliseconds(getInt("aries.xa.connectionMaxWaitMilliseconds", 5000));
    ds.setPartitionStrategy(getString("aries.xa.partitionStrategy", null));
    ds.setPooling(getBool("aries.xa.pooling", true));
    ds.setPoolMaxSize(getInt("aries.xa.poolMaxSize", 10));
    ds.setPoolMinSize(getInt("aries.xa.poolMinSize", 0));
    ds.setValidateOnMatch(getBool("aries.xa.validateOnMatch", true));
    ds.setBackgroundValidation(getBool("aries.xa.backgroundValidation", false));
    ds.setBackgroundValidationMilliseconds(getInt("aries.xa.backgroundValidationMilliseconds", 600000));
    ds.setTransaction(getString("aries.xa.transaction", isXaDataSource ? "xa" : "local"));
    ds.setName(getResourceName());
    ds.start();
    BundleContext context = reference.getBundle().getBundleContext();
    registration = context.registerService(DataSource.class, ds, props);
}
Also used : RecoverableDataSource(org.apache.aries.transaction.jdbc.RecoverableDataSource) XADataSource(javax.sql.XADataSource) Hashtable(java.util.Hashtable) BundleContext(org.osgi.framework.BundleContext) RecoverableDataSource(org.apache.aries.transaction.jdbc.RecoverableDataSource) CommonDataSource(javax.sql.CommonDataSource) DataSource(javax.sql.DataSource) XADataSource(javax.sql.XADataSource)

Example 3 with XADataSource

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

the class RecoverableDataSource method start.

/**
     * @org.apache.xbean.InitMethod
     */
public void start() throws Exception {
    AbstractMCFFactory mcf;
    if (("xa".equals(transaction) || "local".equals(transaction)) && transactionManager == null) {
        throw new IllegalArgumentException("xa or local transactions specified, but no TransactionManager set");
    }
    if ("xa".equals(transaction) && !(dataSource instanceof XADataSource)) {
        throw new IllegalArgumentException("xa transactions specified, but DataSource does not implement javax.sql.XADataSource");
    }
    if ("xa".equals(transaction) || (transactionManager != null && dataSource instanceof XADataSource)) {
        mcf = new XADataSourceMCFFactory();
        if (transaction == null) {
            transaction = "xa";
        }
    } else if (dataSource instanceof DataSource) {
        mcf = new DataSourceMCFFactory();
        if (transaction == null) {
            transaction = transactionManager != null ? "local" : "none";
        }
    } else {
        throw new IllegalArgumentException("dataSource must be of type javax.sql.DataSource/XADataSource");
    }
    mcf.setDataSource(dataSource);
    mcf.setExceptionSorterAsString(exceptionSorter);
    mcf.setUserName(username);
    mcf.setPassword(password);
    mcf.init();
    cm = new ConnectionManagerFactory();
    cm.setManagedConnectionFactory(mcf.getConnectionFactory());
    cm.setTransactionManager(transactionManager);
    cm.setAllConnectionsEqual(allConnectionsEquals);
    cm.setConnectionMaxIdleMinutes(connectionMaxIdleMinutes);
    cm.setConnectionMaxWaitMilliseconds(connectionMaxWaitMilliseconds);
    cm.setPartitionStrategy(partitionStrategy);
    cm.setPooling(pooling);
    cm.setPoolMaxSize(poolMaxSize);
    cm.setPoolMinSize(poolMinSize);
    cm.setValidateOnMatch(validateOnMatch);
    cm.setBackgroundValidation(backgroundValidation);
    cm.setBackgroundValidationMilliseconds(backgroundValidationMilliseconds);
    cm.setTransaction(transaction);
    cm.setName(name);
    cm.init();
    delegate = (DataSource) mcf.getConnectionFactory().createConnectionFactory(cm.getConnectionManager());
    if (dataSource instanceof XADataSource) {
        Recovery.recover(name, (XADataSource) dataSource, transactionManager);
    }
}
Also used : XADataSourceMCFFactory(org.apache.aries.transaction.jdbc.internal.XADataSourceMCFFactory) XADataSource(javax.sql.XADataSource) XADataSourceMCFFactory(org.apache.aries.transaction.jdbc.internal.XADataSourceMCFFactory) DataSourceMCFFactory(org.apache.aries.transaction.jdbc.internal.DataSourceMCFFactory) ConnectionManagerFactory(org.apache.aries.transaction.jdbc.internal.ConnectionManagerFactory) AbstractMCFFactory(org.apache.aries.transaction.jdbc.internal.AbstractMCFFactory) XADataSource(javax.sql.XADataSource) CommonDataSource(javax.sql.CommonDataSource) DataSource(javax.sql.DataSource)

Example 4 with XADataSource

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

the class PoolDataSourceCreator method poolManagedWithRecovery.

@Override
public DataSource poolManagedWithRecovery(final String name, final XAResourceWrapper xaResourceWrapper, final String driver, final Properties properties) {
    final TransactionManager transactionManager = new TransactionManagerWrapper(OpenEJB.getTransactionManager(), name, xaResourceWrapper);
    final CommonDataSource ds = pool(name, driver, properties);
    if (ds instanceof XADataSource) {
        return new ManagedXADataSource(ds, transactionManager, SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
    }
    return new ManagedDataSource(DataSource.class.cast(ds), transactionManager, SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
}
Also used : XADataSource(javax.sql.XADataSource) ManagedXADataSource(org.apache.openejb.resource.jdbc.managed.xa.ManagedXADataSource) TransactionManager(javax.transaction.TransactionManager) TransactionManagerWrapper(org.apache.openejb.resource.TransactionManagerWrapper) ManagedXADataSource(org.apache.openejb.resource.jdbc.managed.xa.ManagedXADataSource) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) CommonDataSource(javax.sql.CommonDataSource) ManagedDataSource(org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource) ManagedDataSource(org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource) XADataSource(javax.sql.XADataSource) CommonDataSource(javax.sql.CommonDataSource) DataSource(javax.sql.DataSource) ManagedXADataSource(org.apache.openejb.resource.jdbc.managed.xa.ManagedXADataSource)

Example 5 with XADataSource

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

the class JTADataSourceWrapperFactory method create.

public CommonDataSource create() {
    final TransactionManager transactionManager = OpenEJB.getTransactionManager();
    CommonDataSource cds = findDelegate();
    if (cds instanceof XADataSource) {
        cds = new ManagedXADataSource(cds, transactionManager, SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
    } else {
        cds = new ManagedDataSource(DataSource.class.cast(cds), transactionManager, SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
    }
    if (logSql) {
        cds = DataSourceFactory.makeItLogging(cds, logPackages);
    }
    return cds;
}
Also used : XADataSource(javax.sql.XADataSource) ManagedXADataSource(org.apache.openejb.resource.jdbc.managed.xa.ManagedXADataSource) TransactionManager(javax.transaction.TransactionManager) ManagedXADataSource(org.apache.openejb.resource.jdbc.managed.xa.ManagedXADataSource) CommonDataSource(javax.sql.CommonDataSource) ManagedDataSource(org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource)

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