Example usage for org.apache.commons.dbcp.managed XAConnectionFactory getTransactionRegistry

List of usage examples for org.apache.commons.dbcp.managed XAConnectionFactory getTransactionRegistry

Introduction

In this page you can find the example usage for org.apache.commons.dbcp.managed XAConnectionFactory getTransactionRegistry.

Prototype

TransactionRegistry getTransactionRegistry();

Source Link

Document

Gets the TransactionRegistry for this connection factory which contains a the XAResource for every connection created by this factory.

Usage

From source file:org.apache.openejb.resource.jdbc.dbcp.DbcpManagedDataSource.java

@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, username, password);
        setTransactionRegistry(xaConnectionFactory.getTransactionRegistry());
        return xaConnectionFactory;

    }//from  w  w  w  .ja va2 s. c om

    // 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),
            username, password);
    final XAConnectionFactory xaConnectionFactory = new LocalXAConnectionFactory(getTransactionManager(),
            connectionFactory);
    setTransactionRegistry(xaConnectionFactory.getTransactionRegistry());
    return xaConnectionFactory;
}

From source file:org.nuxeo.runtime.datasource.PatchedPoolableManagedConnectionFactory.java

public PatchedPoolableManagedConnectionFactory(XAConnectionFactory connFactory, ObjectPool pool,
        KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, int validationQueryTimeout,
        Collection<?> connectionInitSqls, Boolean defaultReadOnly, boolean defaultAutoCommit,
        int defaultTransactionIsolation, String defaultCatalog, AbandonedConfig config) {
    super(connFactory, pool, stmtPoolFactory, validationQuery, validationQueryTimeout, connectionInitSqls,
            defaultReadOnly, defaultAutoCommit, defaultTransactionIsolation, defaultCatalog, config);
    // PATCH: local copy because private in base class
    tr = connFactory.getTransactionRegistry();
}

From source file:org.ofbiz.tenant.jdbc.TenantJdbcConnectionHandler.java

/**
 * delete database/*from  ww  w. jav a  2 s .c om*/
 * @return
 */
public void deleteDatabase() throws GenericEntityException, SQLException {
    Delegator delegator = tenantDataSource.getDelegator();
    GenericHelperInfo helperInfo = delegator.getGroupHelperInfo(this.getEntityGroupName());
    helperInfo.setTenantId(this.getTenantId());
    Datasource datasource = EntityConfigUtil.getDatasource(helperInfo.getHelperBaseName());
    datasource.inlineJdbc.setJdbcUri(this.getJdbcUri());

    // get pool and shared connection
    DBCPConnectionFactory managedConnectionFactory = (DBCPConnectionFactory) ConnectionFactory
            .getManagedConnectionFactory();
    GenericObjectPool pool = managedConnectionFactory.getGenericObjectPool(helperInfo);
    XAConnectionFactory xacf = managedConnectionFactory.getXAConnectionFactory(helperInfo);

    // return shared connection
    if (UtilValidate.isNotEmpty(xacf)) {
        TransactionRegistry transactionRegistry = xacf.getTransactionRegistry();
        TransactionContext transactionContext = transactionRegistry.getActiveTransactionContext();
        if (UtilValidate.isNotEmpty(transactionContext)) {
            PoolableConnection sharedConnection = (PoolableConnection) transactionContext.getSharedConnection();

            try {
                pool.returnObject(sharedConnection);
                pool.clear();
            } catch (Exception e) {
                Debug.logError(e, module);
            }
        }
    }

    // do delete database
    doDeleteDatabase(helperInfo);

    // remove delegator
    String tenantDelegatorName = delegator.getDelegatorBaseName() + "#" + this.getTenantId();
    DelegatorFactory.removeDelegator(tenantDelegatorName);

    // remove connection
    managedConnectionFactory.removeConnection(helperInfo);
}