List of usage examples for org.apache.commons.dbcp BasicDataSource setMaxActive
public synchronized void setMaxActive(int maxActive)
From source file:org.midao.jdbc.core.pool.MjdbcPoolBinder.java
/** * Returns new Pooled {@link DataSource} implementation * * In case this function won't work - use {@link #createDataSource(java.util.Properties)} * * @param driverClassName Driver Class name * @param url Database connection url/* w w w. j a va 2 s .co m*/ * @param userName Database user name * @param password Database user password * @param initialSize initial pool size * @param maxActive max connection active * @return new Pooled {@link DataSource} implementation * @throws SQLException */ public static DataSource createDataSource(String driverClassName, String url, String userName, String password, int initialSize, int maxActive) throws SQLException { assertNotNull(driverClassName); assertNotNull(url); assertNotNull(userName); assertNotNull(password); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(driverClassName); ds.setUrl(url); ds.setUsername(userName); ds.setPassword(password); ds.setMaxActive(maxActive); ds.setInitialSize(initialSize); return ds; }
From source file:org.mskcc.cbio.portal.dao.JdbcUtil.java
private static DataSource initDataSource() { DatabaseProperties dbProperties = DatabaseProperties.getInstance(); String host = dbProperties.getDbHost(); String userName = dbProperties.getDbUser(); String password = dbProperties.getDbPassword(); String database = dbProperties.getDbName(); String url = "jdbc:mysql://" + host + "/" + database + "?user=" + userName + "&password=" + password + "&zeroDateTimeBehavior=convertToNull"; // Set up poolable data source BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("com.mysql.jdbc.Driver"); ds.setUsername(userName);/*from w w w . j ava2s. c o m*/ ds.setPassword(password); ds.setUrl(url); // By pooling/reusing PreparedStatements, we get a major performance gain ds.setPoolPreparedStatements(true); ds.setMaxActive(100); activeConnectionCount = new HashMap<String, Integer>(); return ds; }
From source file:org.nebula.service.core.DynamicDataSource.java
public void onChange(String dbUrl) { logger.info("Change target dbUrl to: " + dbUrl); Object oldDataSource = this.datasources.remove(LOOKUP_KEY); if (oldDataSource != null) { try {/*from www . j ava 2s. c o m*/ ((BasicDataSource) oldDataSource).close(); } catch (SQLException e) { //ignore } } BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setMaxActive(jdbcMaxActive); dataSource.setMaxIdle(jdbcMaxIdle); dataSource.setInitialSize(jdbcInitialSize); dataSource.setUrl(dbUrl); dataSource.setUsername(jdbcUsername); dataSource.setPassword(jdbcPassword); dataSource.setTestOnBorrow(true); dataSource.setValidationQuery("SELECT 1"); this.datasources.put(LOOKUP_KEY, dataSource); }
From source file:org.ngrinder.infra.config.Database.java
/** * Setup the database common features.// ww w.ja va 2 s .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.owasp.dependencytrack.config.DatabaseConfiguration.java
@Bean public DataSource dataSource() { BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(driverClassName); basicDataSource.setUsername(username); basicDataSource.setPassword(password); basicDataSource.setUrl(url);// w w w .j a v a2 s. co m basicDataSource.setMaxActive(maxActive); return basicDataSource; }
From source file:org.owasp.dependencytrack.config.JunitDatabaseConfiguration.java
@Bean public DataSource dataSource() { BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName("org.h2.Driver"); basicDataSource.setUsername("sa"); basicDataSource.setPassword(""); basicDataSource.setUrl("jdbc:h2:mem:dtrack"); basicDataSource.setMaxActive(100); return basicDataSource; }
From source file:org.pentaho.platform.engine.services.connection.datasource.dbcp.NonPooledDatasourceService.java
private DataSource convert(IDatasource datasource) { BasicDataSource basicDatasource = new BasicDataSource(); basicDatasource.setDriverClassName(datasource.getDriverClass()); basicDatasource.setMaxActive(datasource.getMaxActConn()); basicDatasource.setMaxIdle(datasource.getIdleConn()); basicDatasource.setMaxWait(datasource.getWait()); basicDatasource.setUrl(datasource.getUrl()); basicDatasource.setUsername(datasource.getUserName()); basicDatasource.setPassword(datasource.getPassword()); basicDatasource.setValidationQuery(datasource.getQuery()); return basicDatasource; }
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());// w w w . j a va 2s .c om 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); dataSource.setMinIdle(5);/*from w ww . ja va 2s . com*/ 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.sbq.batch.configurations.DatabaseConfiguration.java
@Bean(destroyMethod = "close") public DataSource dbcpDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/batch_db"); dataSource.setUsername("root"); dataSource.setPassword(""); dataSource.setMaxActive(20); dataSource.setMaxIdle(20);//from www .j a v a 2 s . c o m dataSource.setMaxWait(10000); dataSource.setInitialSize(5); dataSource.setValidationQuery("SELECT 1"); dataSource.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); return dataSource; }