Example usage for org.apache.commons.dbcp2.cpdsadapter DriverAdapterCPDS DriverAdapterCPDS

List of usage examples for org.apache.commons.dbcp2.cpdsadapter DriverAdapterCPDS DriverAdapterCPDS

Introduction

In this page you can find the example usage for org.apache.commons.dbcp2.cpdsadapter DriverAdapterCPDS DriverAdapterCPDS.

Prototype

public DriverAdapterCPDS() 

Source Link

Document

Default no-arg constructor for Serialization

Usage

From source file:com.smartmarmot.dbforbix.db.adapter.AbstractDBAdapter.java

private void createConnection() throws SQLException, ClassNotFoundException {
    LOG.info("Creating new connection pool for database " + getName());
    Config cfg = Config.getInstance();//from  w w w  .  j a v a 2s. c  om
    DriverAdapterCPDS cpds = new DriverAdapterCPDS();
    cpds.setDriver(getType().getJDBCDriverClass());
    cpds.setUrl(getURL());
    cpds.setUser(getUser());
    cpds.setPassword(getPassword());
    datasrc = new SharedPoolDataSource();
    datasrc.setConnectionPoolDataSource(cpds);
    datasrc.setLoginTimeout(cfg.getLoginTimeout());
    datasrc.setMaxTotal(getMaxActive());
    datasrc.setDefaultMaxIdle(getMaxIdle());
    datasrc.setDefaultMaxWaitMillis(getMaxWaitMillis());
    datasrc.setValidationQuery(getType().getAliveSQL());
    datasrc.setDefaultTestOnBorrow(true);
    /**
     * wait while connection is initialized
     */
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:org.lightmare.jpa.datasource.dbcp.InitDBCP.java

@Override
public DataSource initializeDataSource() throws IOException {

    String jndiName = Initializer.getJndiName(properties);

    DriverAdapterCPDS dacp = new DriverAdapterCPDS();

    try {/*  w  w w.  ja v  a2s .com*/
        dacp.setDriver(driver);
    } catch (ClassNotFoundException ex) {
        throw new IOException(ex);
    }
    dacp.setUrl(url);
    dacp.setUser(user);
    dacp.setPassword(password);

    SharedPoolDataSource dataSource = new SharedPoolDataSource();
    dataSource.setDataSourceName(jndiName);
    dataSource.setDefaultAutoCommit(Boolean.FALSE);
    dataSource.setDefaultReadOnly(Boolean.FALSE);
    dataSource.setDefaultTransactionIsolation(DEFAULT_TRANSACTION_ISOLATION);
    dataSource.setLoginTimeout(PoolConfig.asInt(properties, PoolConfig.Defaults.MAX_IDLE_TIMEOUT));
    dataSource.setDefaultMaxTotal(PoolConfig.asInt(properties, PoolConfig.Defaults.MAX_POOL_SIZE));
    dataSource.setDefaultMaxIdle(PoolConfig.asInt(properties, PoolConfig.Defaults.MAX_IDLE_TIMEOUT));
    dataSource.setDefaultMaxWaitMillis(PoolConfig.asInt(properties, PoolConfig.Defaults.CHECK_OUT_TIMEOUT));

    return dataSource;
}