Search in sources :

Example 1 with XADataSourceMCFFactory

use of org.apache.aries.transaction.jdbc.internal.XADataSourceMCFFactory 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)

Aggregations

CommonDataSource (javax.sql.CommonDataSource)1 DataSource (javax.sql.DataSource)1 XADataSource (javax.sql.XADataSource)1 AbstractMCFFactory (org.apache.aries.transaction.jdbc.internal.AbstractMCFFactory)1 ConnectionManagerFactory (org.apache.aries.transaction.jdbc.internal.ConnectionManagerFactory)1 DataSourceMCFFactory (org.apache.aries.transaction.jdbc.internal.DataSourceMCFFactory)1 XADataSourceMCFFactory (org.apache.aries.transaction.jdbc.internal.XADataSourceMCFFactory)1