Search in sources :

Example 1 with ConnectionFactory

use of org.apache.commons.dbcp2.ConnectionFactory in project zeppelin by apache.

the class JDBCInterpreter method createConnectionPool.

private void createConnectionPool(String url, String user, String propertyKey, Properties properties) throws SQLException, ClassNotFoundException {
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, properties);
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
    ObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory);
    poolableConnectionFactory.setPool(connectionPool);
    Class.forName(properties.getProperty(DRIVER_KEY));
    PoolingDriver driver = new PoolingDriver();
    driver.registerPool(propertyKey + user, connectionPool);
    getJDBCConfiguration(user).saveDBDriverPool(propertyKey, driver);
}
Also used : ConnectionFactory(org.apache.commons.dbcp2.ConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) PoolingDriver(org.apache.commons.dbcp2.PoolingDriver) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) ObjectPool(org.apache.commons.pool2.ObjectPool) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory)

Example 2 with ConnectionFactory

use of org.apache.commons.dbcp2.ConnectionFactory in project tomee by apache.

the class DbcpManagedDataSource method createConnectionFactory.

@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, getUsername(), getPassword());
        setTransactionRegistry(xaConnectionFactory.getTransactionRegistry());
        return xaConnectionFactory;
    }
    // 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), getUsername(), getPassword());
    final XAConnectionFactory xaConnectionFactory = new LocalXAConnectionFactory(getTransactionManager(), connectionFactory);
    setTransactionRegistry(xaConnectionFactory.getTransactionRegistry());
    return xaConnectionFactory;
}
Also used : XADataSource(javax.sql.XADataSource) ConnectionFactory(org.apache.commons.dbcp2.ConnectionFactory) DataSourceConnectionFactory(org.apache.commons.dbcp2.DataSourceConnectionFactory) DataSourceXAConnectionFactory(org.apache.commons.dbcp2.managed.DataSourceXAConnectionFactory) LocalXAConnectionFactory(org.apache.commons.dbcp2.managed.LocalXAConnectionFactory) XAConnectionFactory(org.apache.commons.dbcp2.managed.XAConnectionFactory) DataSourceConnectionFactory(org.apache.commons.dbcp2.DataSourceConnectionFactory) DataSourceXAConnectionFactory(org.apache.commons.dbcp2.managed.DataSourceXAConnectionFactory) DataSourceXAConnectionFactory(org.apache.commons.dbcp2.managed.DataSourceXAConnectionFactory) LocalXAConnectionFactory(org.apache.commons.dbcp2.managed.LocalXAConnectionFactory) XAConnectionFactory(org.apache.commons.dbcp2.managed.XAConnectionFactory) LocalXAConnectionFactory(org.apache.commons.dbcp2.managed.LocalXAConnectionFactory) CommonDataSource(javax.sql.CommonDataSource) DataSource(javax.sql.DataSource) XADataSource(javax.sql.XADataSource)

Aggregations

ConnectionFactory (org.apache.commons.dbcp2.ConnectionFactory)2 CommonDataSource (javax.sql.CommonDataSource)1 DataSource (javax.sql.DataSource)1 XADataSource (javax.sql.XADataSource)1 DataSourceConnectionFactory (org.apache.commons.dbcp2.DataSourceConnectionFactory)1 DriverManagerConnectionFactory (org.apache.commons.dbcp2.DriverManagerConnectionFactory)1 PoolableConnectionFactory (org.apache.commons.dbcp2.PoolableConnectionFactory)1 PoolingDriver (org.apache.commons.dbcp2.PoolingDriver)1 DataSourceXAConnectionFactory (org.apache.commons.dbcp2.managed.DataSourceXAConnectionFactory)1 LocalXAConnectionFactory (org.apache.commons.dbcp2.managed.LocalXAConnectionFactory)1 XAConnectionFactory (org.apache.commons.dbcp2.managed.XAConnectionFactory)1 ObjectPool (org.apache.commons.pool2.ObjectPool)1 GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)1