Search in sources :

Example 1 with XADataSourceMapper

use of org.apache.aries.tx.control.jdbc.xa.connection.impl.XADataSourceMapper in project aries by apache.

the class JDBCConnectionProviderFactoryImpl method getProviderFor.

@Override
public AbstractJDBCConnectionProvider getProviderFor(DataSource ds, Map<String, Object> resourceProviderProperties) {
    boolean xaEnabled = toBoolean(resourceProviderProperties, XA_ENLISTMENT_ENABLED, true);
    boolean localEnabled = toBoolean(resourceProviderProperties, LOCAL_ENLISTMENT_ENABLED, true);
    try {
        checkEnlistment(xaEnabled, localEnabled, ds.isWrapperFor(XADataSource.class));
        DataSource toUse = poolIfNecessary(resourceProviderProperties, xaEnabled ? new XADataSourceMapper(ds.unwrap(XADataSource.class)) : ds);
        return new JDBCConnectionProviderImpl(toUse, xaEnabled, localEnabled, getRecoveryId(resourceProviderProperties, xaEnabled));
    } catch (SQLException sqle) {
        throw new TransactionException("Unable to create the JDBC resource provider", sqle);
    }
}
Also used : XADataSource(javax.sql.XADataSource) TransactionException(org.osgi.service.transaction.control.TransactionException) SQLException(java.sql.SQLException) 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 2 with XADataSourceMapper

use of org.apache.aries.tx.control.jdbc.xa.connection.impl.XADataSourceMapper in project aries by apache.

the class JDBCConnectionProviderFactoryImpl method getProviderFor.

@Override
public JDBCConnectionProviderImpl getProviderFor(DataSourceFactory dsf, Properties jdbcProperties, Map<String, Object> resourceProviderProperties) {
    boolean xaEnabled = toBoolean(resourceProviderProperties, XA_ENLISTMENT_ENABLED, true);
    boolean localEnabled = toBoolean(resourceProviderProperties, LOCAL_ENLISTMENT_ENABLED, true);
    boolean useDriver = toBoolean(resourceProviderProperties, USE_DRIVER, false);
    checkEnlistment(xaEnabled, localEnabled, !useDriver);
    DataSource unpooled;
    try {
        if (useDriver) {
            unpooled = new DriverDataSource(dsf.createDriver(null), jdbcProperties.getProperty(JDBC_URL), jdbcProperties);
        } else if (xaEnabled) {
            unpooled = new XADataSourceMapper(dsf.createXADataSource(jdbcProperties));
        } else {
            unpooled = dsf.createDataSource(jdbcProperties);
        }
    } catch (SQLException sqle) {
        throw new TransactionException("Unable to create the JDBC resource provider", sqle);
    }
    DataSource toUse = poolIfNecessary(resourceProviderProperties, unpooled);
    return new JDBCConnectionProviderImpl(toUse, xaEnabled, localEnabled, getRecoveryId(resourceProviderProperties, xaEnabled));
}
Also used : TransactionException(org.osgi.service.transaction.control.TransactionException) DriverDataSource(org.apache.aries.tx.control.jdbc.common.impl.DriverDataSource) SQLException(java.sql.SQLException) 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 3 with XADataSourceMapper

use of org.apache.aries.tx.control.jdbc.xa.connection.impl.XADataSourceMapper in project aries by apache.

the class XAJPADataSourceSetup method decorateJPAProperties.

@Override
protected Map<String, Object> decorateJPAProperties(DataSourceFactory dsf, Map<String, Object> providerProperties, Properties jdbcProperties, Map<String, Object> jpaProperties) throws Exception {
    DataSource unpooled;
    try {
        if (toBoolean(providerProperties, USE_DRIVER, false)) {
            throw new TransactionException("The Database must use an XA connection");
        } else {
            unpooled = new XADataSourceMapper(dsf.createXADataSource(jdbcProperties));
        }
    } catch (SQLException sqle) {
        throw new TransactionException("Unable to create the JDBC resource provider", sqle);
    }
    DataSource toUse = poolIfNecessary(providerProperties, unpooled);
    jpaProperties.put("javax.persistence.jtaDataSource", toUse);
    return jpaProperties;
}
Also used : TransactionException(org.osgi.service.transaction.control.TransactionException) SQLException(java.sql.SQLException) XADataSourceMapper(org.apache.aries.tx.control.jdbc.xa.connection.impl.XADataSourceMapper) HikariDataSource(com.zaxxer.hikari.HikariDataSource) DataSource(javax.sql.DataSource)

Example 4 with XADataSourceMapper

use of org.apache.aries.tx.control.jdbc.xa.connection.impl.XADataSourceMapper 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)

Aggregations

DataSource (javax.sql.DataSource)4 XADataSourceMapper (org.apache.aries.tx.control.jdbc.xa.connection.impl.XADataSourceMapper)4 SQLException (java.sql.SQLException)3 XADataSource (javax.sql.XADataSource)3 DriverDataSource (org.apache.aries.tx.control.jdbc.common.impl.DriverDataSource)3 TransactionException (org.osgi.service.transaction.control.TransactionException)3 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1