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);
}
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);
}
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);
}
}
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));
}
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;
}
Aggregations