Example usage for org.apache.commons.dbcp BasicDataSource setMaxActive

List of usage examples for org.apache.commons.dbcp BasicDataSource setMaxActive

Introduction

In this page you can find the example usage for org.apache.commons.dbcp BasicDataSource setMaxActive.

Prototype

public synchronized void setMaxActive(int maxActive) 

Source Link

Document

Sets the maximum number of active connections that can be allocated at the same time.

Usage

From source file:se.unlogic.hierarchy.core.utils.DBCPUtils.java

public static BasicDataSource createConnectionPool(DataSourceDescriptor dataSourceDescriptor) {

    BasicDataSource basicDataSource = new BasicDataSource();

    basicDataSource.setDriverClassName(dataSourceDescriptor.getDriver());
    basicDataSource.setUsername(dataSourceDescriptor.getUsername());
    basicDataSource.setPassword(dataSourceDescriptor.getPassword());
    basicDataSource.setUrl(dataSourceDescriptor.getUrl());
    basicDataSource.setDefaultCatalog(dataSourceDescriptor.getDefaultCatalog());
    basicDataSource.setLogAbandoned(dataSourceDescriptor.logAbandoned());
    basicDataSource.setRemoveAbandoned(dataSourceDescriptor.removeAbandoned());

    if (dataSourceDescriptor.getRemoveTimeout() != null) {
        basicDataSource.setRemoveAbandonedTimeout(dataSourceDescriptor.getRemoveTimeout());
    }// w ww . jav  a 2 s . co  m

    basicDataSource.setTestOnBorrow(dataSourceDescriptor.testOnBorrow());
    basicDataSource.setValidationQuery(dataSourceDescriptor.getValidationQuery());
    basicDataSource.setMaxWait(dataSourceDescriptor.getMaxWait());
    basicDataSource.setMaxActive(dataSourceDescriptor.getMaxActive());
    basicDataSource.setMaxIdle(dataSourceDescriptor.getMaxIdle());
    basicDataSource.setMinIdle(dataSourceDescriptor.getMinIdle());

    return basicDataSource;
}

From source file:sistema.Conexion.java

private void inicializaDataSource() {

    BasicDataSource basicDataSource = new BasicDataSource();

    basicDataSource.setDriverClassName("org.gjt.mm.mysql.Driver");
    basicDataSource.setUsername(login);//from w ww .j  a  v  a2s  .c  om
    basicDataSource.setPassword(pass);
    basicDataSource.setUrl(url);
    basicDataSource.setMaxActive(50);

    dataSource = basicDataSource;

}

From source file:skoa.helpers.ConfiguracionGraficas.java

private void inicializaDataSource() {
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName("com.mysql.jdbc.Driver");
    basicDataSource.setUsername(user);/*from   w w  w.  java  2 s.c  o m*/
    basicDataSource.setPassword(pass);
    basicDataSource.setUrl(url);
    basicDataSource.setMaxActive(4);
    // Opcional. Sentencia SQL que sirve a BasicDataSource para comprobar que la conexion es correcta.
    basicDataSource.setValidationQuery("select 1");
    dataSource = basicDataSource;
}

From source file:test.com.agiletec.ConfigTestUtils.java

private void createDatasource(String dsNameControlKey, SimpleNamingContextBuilder builder,
        Properties testConfig) {/*from  w  w w . j a v  a2  s. c o  m*/
    String beanName = testConfig.getProperty("jdbc." + dsNameControlKey + ".beanName");
    try {
        String className = testConfig.getProperty("jdbc." + dsNameControlKey + ".driverClassName");
        String url = testConfig.getProperty("jdbc." + dsNameControlKey + ".url");
        String username = testConfig.getProperty("jdbc." + dsNameControlKey + ".username");
        String password = testConfig.getProperty("jdbc." + dsNameControlKey + ".password");
        Class.forName(className);
        BasicDataSource ds = new BasicDataSource();
        ds.setUrl(url);
        ds.setUsername(username);
        ds.setPassword(password);
        ds.setMaxActive(8);
        ds.setMaxIdle(4);
        builder.bind("java:comp/env/jdbc/" + beanName, ds);
    } catch (Throwable t) {
        throw new RuntimeException("Error on creation datasource '" + beanName + "'", t);
    }
}

From source file:xbird.util.jdbc.datasource.DbcpDataSourceProvider.java

public DataSource setupDataSource(String connectURI) {
    // creates DataSource
    BasicDataSource ds = new BasicDataSource();

    // for debugging.
    if (Settings.isLoggingEnabled) {
        ds.setAccessToUnderlyingConnectionAllowed(true);
    }/*w  ww .  j a  v  a2s. com*/

    ds.setDriverClassName(DriverClassNameResolver.resolve(Settings.get("xbird.db.kind")));

    // sets up DataSource
    ds.setUrl(connectURI);
    final String dbuser = Settings.get("xbird.db.user");
    final String dbpasswd = Settings.get("xbird.db.passwd");
    if (dbuser != null && dbuser.length() != 0) {
        ds.setUsername(dbuser);
        ds.setPassword(dbpasswd);
    }

    // addtinal settings.
    final String maxactive = Settings.get("xbird.db.pool.maxactive");
    if (maxactive != null)
        ds.setMaxActive(Integer.parseInt(maxactive));

    final String maxidle = Settings.get("xbird.db.pool.maxidle");
    if (maxidle != null)
        ds.setMaxIdle(Integer.parseInt(maxidle));

    final String maxwait = Settings.get("xbird.db.pool.maxwait");
    ds.setMaxWait(maxwait == null ? DEFAULT_MAXWAIT : Integer.parseInt(maxwait));

    ds.setDefaultAutoCommit(true);
    //ds.setDefaultReadOnly(false);

    final String initialsize = Settings.get("xbird.db.pool.initialsize");
    ds.setInitialSize(initialsize == null ? DEFAULT_INITIAL_POLLSIZE : Integer.parseInt(initialsize));

    // sets up for PreparedStatements.
    ds.setPoolPreparedStatements(true);

    final String maxOpenPreparedStatements = Settings.get("xbird.db.pool.statement.cache_size");
    ds.setMaxOpenPreparedStatements(maxOpenPreparedStatements == null ? MAX_OPEN_PREPARED_STATEMENTS
            : Integer.parseInt(maxOpenPreparedStatements));

    return ds;
}