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

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

Introduction

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

Prototype

public synchronized void setMinIdle(int minIdle) 

Source Link

Document

Sets the minimum number of idle connections in the pool.

Usage

From source file:org.ngrinder.infra.config.Database.java

/**
 * Setup the database common features.//from   w  ww .j  a va 2s  .  c  o m
 *
 * @param dataSource datasource
 */
protected void setupCommon(BasicDataSource dataSource) {
    dataSource.setDriverClassName(getJdbcDriverName());
    dataSource.setInitialSize(DB_INITIAL_SIZE);
    dataSource.setMaxActive(DB_MAX_ACTIVE);
    dataSource.setMinIdle(DB_MIN_IDLE);
    dataSource.setMaxWait(DB_MAX_WAIT);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setMaxOpenPreparedStatements(DB_MAX_OPEN_PREPARED_STATEMENTS);
    dataSource.setTestWhileIdle(true);
    dataSource.setTestOnBorrow(true);
    dataSource.setTestOnReturn(true);
    dataSource.setValidationQuery("SELECT 1");
}

From source file:org.pinus4j.cluster.impl.AppDBClusterImpl.java

@Override
public void buildDataSource(DBInfo dbConnInfo) throws LoadConfigException {
    AppDBInfo appDbConnInfo = (AppDBInfo) dbConnInfo;

    LOG.info(dbConnInfo.toString());// www.j a va2 s.  co  m

    try {
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName(enumDb.getDriverClass());
        ds.setUsername(appDbConnInfo.getUsername());
        ds.setPassword(appDbConnInfo.getPassword());
        ds.setUrl(appDbConnInfo.getUrl());

        // ?
        Map<String, Object> dbConnPoolInfo = appDbConnInfo.getConnPoolInfo();
        ds.setValidationQuery("SELECT 1");
        ds.setMaxActive((Integer) dbConnPoolInfo.get(Const.PROP_MAXACTIVE));
        ds.setMinIdle((Integer) dbConnPoolInfo.get(Const.PROP_MINIDLE));
        ds.setMaxIdle((Integer) dbConnPoolInfo.get(Const.PROP_MAXIDLE));
        ds.setInitialSize((Integer) dbConnPoolInfo.get(Const.PROP_INITIALSIZE));
        ds.setRemoveAbandoned((Boolean) dbConnPoolInfo.get(Const.PROP_REMOVEABANDONED));
        ds.setRemoveAbandonedTimeout((Integer) dbConnPoolInfo.get(Const.PROP_REMOVEABANDONEDTIMEOUT));
        ds.setMaxWait((Integer) dbConnPoolInfo.get(Const.PROP_MAXWAIT));
        ds.setTimeBetweenEvictionRunsMillis(
                (Integer) dbConnPoolInfo.get(Const.PROP_TIMEBETWEENEVICTIONRUNSMILLIS));
        ds.setNumTestsPerEvictionRun((Integer) dbConnPoolInfo.get(Const.PROP_NUMTESTSPEREVICTIONRUN));
        ds.setMinEvictableIdleTimeMillis((Integer) dbConnPoolInfo.get(Const.PROP_MINEVICTABLEIDLETIMEMILLIS));

        dbConnInfo.setDatasource(ds);
    } catch (Exception e) {
        throw new LoadConfigException(e);
    }
}

From source file:org.plista.kornakapi.core.storage.MySqlStorage.java

public MySqlStorage(StorageConfiguration storageConf, String label, BasicDataSource dataSource) {

    dataSource.setDriverClassName(storageConf.getJdbcDriverClass());
    dataSource.setUrl(storageConf.getJdbcUrl());
    dataSource.setUsername(storageConf.getUsername());
    dataSource.setPassword(storageConf.getPassword());

    //TODO should be made configurable
    dataSource.setMaxActive(10);//  w w  w.ja v  a 2  s  .  c om
    dataSource.setMinIdle(5);
    dataSource.setInitialSize(5);
    dataSource.setValidationQuery("SELECT 1;");
    dataSource.setTestOnBorrow(false);
    dataSource.setTestOnReturn(false);
    dataSource.setTestWhileIdle(true);
    dataSource.setTimeBetweenEvictionRunsMillis(5000);

    dataModel = new LabeledMySQLJDBCDataModel(dataSource, "taste_preferences", "user_id", "item_id",
            "preference", "timestamp", "taste_candidates", "label", label);
    this.dataSource = dataSource;
    this.timeWindow = storageConf.getTimeWindow();
    if (timeWindow % 6 != 0 || timeWindow == 0) {
        timeWindow = 24;
    }

}

From source file:org.springframework.boot.autoconfigure.jdbc.metadata.CommonsDbcpDataSourcePoolMetadataTests.java

private CommonsDbcpDataSourcePoolMetadata createDataSourceMetadata(int minSize, int maxSize) {
    BasicDataSource dataSource = createDataSource();
    dataSource.setMinIdle(minSize);
    dataSource.setMaxActive(maxSize);/*  www.ja  va 2  s.  c  o  m*/
    return new CommonsDbcpDataSourcePoolMetadata(dataSource);
}

From source file:org.tdmx.lib.control.datasource.DynamicDataSource.java

private synchronized void createDataSource(DatabaseConnectionInfo dci) throws SQLException {
    // race condition avoidance
    if (connectionDataSourceMap.get(dci) != null) {
        return;/*from w w  w  .  ja va 2  s . c  o m*/
    }
    BasicDataSource bds = new BasicDataSource();
    bds.setUrl(dci.getUrl());
    bds.setDriverClassName(dci.getDriverClassname());
    bds.setUsername(dci.getUsername());
    bds.setPassword(dci.getPassword());
    bds.setMaxActive(100);
    bds.setMinIdle(0);
    bds.setInitialSize(1);
    bds.setMinEvictableIdleTimeMillis(60000);
    bds.setLogWriter(logWriter);
    connectionDataSourceMap.put(dci, bds);
}

From source file:org.wso2.carbon.registry.core.jdbc.utils.RegistryDataSource.java

public RegistryDataSource(DataBaseConfiguration config) {

    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setUrl(config.getDbUrl());
    basicDataSource.setDriverClassName(config.getDriverName());
    basicDataSource.setUsername(config.getUserName());
    basicDataSource.setPassword(config.getResolvedPassword());

    if (config.getMaxActive() != null) {
        basicDataSource.setMaxActive(Integer.parseInt(config.getMaxActive()));
    } else {/* w  w  w  .  ja v  a2  s .  co m*/
        basicDataSource.setMaxActive(DEFAULT_MAX_ACTIVE);
    }

    if (config.getMaxWait() != null) {
        basicDataSource.setMaxWait(Integer.parseInt(config.getMaxWait()));
    } else {
        basicDataSource.setMaxWait(DEFAULT_MAX_WAIT);
    }

    if (config.getMaxIdle() != null) {
        basicDataSource.setMaxIdle(Integer.parseInt(config.getMaxIdle()));
    }

    if (config.getMinIdle() != null) {
        basicDataSource.setMinIdle(Integer.parseInt(config.getMinIdle()));
    } else {
        basicDataSource.setMinIdle(DEFAULT_MIN_IDLE);
    }

    this.dataSource = basicDataSource;
}

From source file:org.wso2.carbon.registry.core.test.performance.BasicPerformanceTest.java

public void setUp() {
    //String connURL = "jdbc:log4jdbc:derby:target/REG1_DB";
    //String connURL = "jdbc:derby:target/REG1_DB";
    String connURL = "jdbc:mysql://localhost:3306/registry1";
    BasicDataSource ds = new BasicDataSource();
    //ds.setUrl(connURL + ";");
    //ds.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUrl(connURL);//from w  ww . j  a  v  a2  s .  com
    ds.setUsername("root");
    ds.setPassword("password");

    //        ds.setMaxWait(1000*60*2);

    ds.setMaxActive(150);
    ds.setMaxIdle(1000 * 60 * 2);
    ds.setMinIdle(5);
    //ds.setDriverClassName("net.sf.log4jdbc.DriverSpy");

    //DerbyDatabaseCreator creator = new DerbyDatabaseCreator(ds);
    DatabaseCreator creator = new DatabaseCreator(ds);
    try {
        creator.createRegistryDatabase();
    } catch (Exception e) {
        fail("Failed to create database. Caused by: " + e.getMessage());
    }
    //String fileName = "target/db/registry";
    //File file = new File(fileName);

    //if (! file.exists()) {
    //creator.createDefaultDatabaseTables();
    //}

    //        UserRealm realm = new DefaultRealm();
    //        DefaultRealmConfig config = (DefaultRealmConfig) realm.getBootstrapRealmConfiguration();
    //        config.setConnectionURL(connURL);
    //        realm.init(config);
    //        UserRealm registryRealm = new UserRealm(realm);
    //
    //        InputStream configStream =
    //            Thread.currentThread().getContextClassLoader().getResourceAsStream("registry.xml");
    //        RegistryContext regContext = new RegistryContext(configStream, registryRealm);
    //        embeddedRegistryService = new EmbeddedRegistryService(regContext);
    //        adminRegistry = embeddedRegistryService.getUserRegistry(
    //            RegistryConstants.ADMIN_USER, RegistryConstants.ADMIN_PASSWORD);
    System.out.println("~~~~~setup method done~~~~~");
}

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());
    }/*from   w w w  . j  a v a  2s. c  o  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;
}