List of usage examples for org.apache.commons.dbcp2 BasicDataSource setValidationQueryTimeout
public void setValidationQueryTimeout(int timeout)
From source file:com.github.akiraly.db4j.pool.DbcpUtils.java
public static BasicDataSource newDefaultDS() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDefaultAutoCommit(false); dataSource.setDefaultQueryTimeout(1); dataSource.setValidationQueryTimeout(1); dataSource.setMaxWaitMillis(5000);// w ww.ja v a2s .co m dataSource.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); dataSource.setInitialSize(4); dataSource.setMinIdle(4); dataSource.setMaxIdle(8); dataSource.setMaxTotal(16); dataSource.setPoolPreparedStatements(true); dataSource.setMaxOpenPreparedStatements(128); return dataSource; }
From source file:de.micromata.genome.util.runtime.LocalSettingsEnv.java
/** * Parses the ds./*from w w w .j a v a 2 s. com*/ */ protected void parseDs() { // db.ds.rogerdb.name=RogersOracle // db.ds.rogerdb.drivername=oracle.jdbc.driver.OracleDriver // db.ds.rogerdb.url=jdbc:oracle:thin:@localhost:1521:rogdb // db.ds.rogerdb.username=genome // db.ds.rogerdb.password=genome List<String> dse = localSettings.getKeysPrefixWithInfix("db.ds", "name"); for (String dsn : dse) { String key = dsn + ".name"; String name = localSettings.get(key); if (StringUtils.isBlank(name) == true) { log.error("Name in local-settings is not defined with key: " + key); continue; } key = dsn + ".drivername"; String driverName = localSettings.get(key); if (StringUtils.isBlank(name) == true) { log.error("drivername in local-settings is not defined with key: " + key); continue; } key = dsn + ".url"; String url = localSettings.get(key); if (StringUtils.isBlank(name) == true) { log.error("url in local-settings is not defined with key: " + key); continue; } key = dsn + ".username"; String userName = localSettings.get(key); key = dsn + ".password"; String password = localSettings.get(key); BasicDataSource bd = dataSourceSuplier.get(); bd.setDriverClassName(driverName); bd.setUrl(url); bd.setUsername(userName); bd.setPassword(password); bd.setMaxTotal(localSettings.getIntValue(dsn + ".maxActive", GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL_PER_KEY)); bd.setMaxIdle(localSettings.getIntValue(dsn + ".maxIdle", GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE_PER_KEY)); bd.setMinIdle(localSettings.getIntValue(dsn + ".minIdle", GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE_PER_KEY)); bd.setMaxWaitMillis(localSettings.getLongValue(dsn + ".maxWait", GenericKeyedObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS)); bd.setInitialSize(localSettings.getIntValue(dsn + ".intialSize", 0)); bd.setDefaultCatalog(localSettings.get(dsn + ".defaultCatalog", null)); bd.setDefaultAutoCommit(localSettings.getBooleanValue(dsn + ".defaultAutoCommit", true)); bd.setValidationQuery(localSettings.get(dsn + ".validationQuery", null)); bd.setValidationQueryTimeout(localSettings.getIntValue(dsn + ".validationQueryTimeout", -1)); dataSources.put(name, bd); } }
From source file:org.ofbiz.core.entity.transaction.DBCPConnectionFactory.java
private static void initConnectionPoolSettings(final BasicDataSource dataSource, final ConnectionPoolInfo poolInfo) { if (poolInfo == null) { return;//from w ww . ja va 2 s . c o m } dataSource.setMaxTotal(poolInfo.getMaxSize()); dataSource.setMinIdle(poolInfo.getMinSize()); dataSource.setMaxIdle(poolInfo.getMaxIdle()); dataSource.setMaxWaitMillis(poolInfo.getMaxWait()); dataSource.setDefaultCatalog(poolInfo.getDefaultCatalog()); if (poolInfo.getInitialSize() != null) { dataSource.setInitialSize(poolInfo.getInitialSize()); } if (isNotEmpty(poolInfo.getValidationQuery())) { // testOnBorrow defaults to true when this is set, but can still be forced to false dataSource.setTestOnBorrow(poolInfo.getTestOnBorrow() == null || poolInfo.getTestOnBorrow()); if (poolInfo.getTestOnReturn() != null) { dataSource.setTestOnReturn(poolInfo.getTestOnReturn()); } if (poolInfo.getTestWhileIdle() != null) { dataSource.setTestWhileIdle(poolInfo.getTestWhileIdle()); } dataSource.setValidationQuery(poolInfo.getValidationQuery()); if (poolInfo.getValidationQueryTimeout() != null) { dataSource.setValidationQueryTimeout(poolInfo.getValidationQueryTimeout()); } } if (poolInfo.getPoolPreparedStatements() != null) { dataSource.setPoolPreparedStatements(poolInfo.getPoolPreparedStatements()); if (dataSource.isPoolPreparedStatements() && poolInfo.getMaxOpenPreparedStatements() != null) { dataSource.setMaxOpenPreparedStatements(poolInfo.getMaxOpenPreparedStatements()); } } if (poolInfo.getRemoveAbandonedOnBorrow() != null) { dataSource.setRemoveAbandonedOnBorrow(poolInfo.getRemoveAbandonedOnBorrow()); } if (poolInfo.getRemoveAbandonedOnMaintanance() != null) { dataSource.setRemoveAbandonedOnMaintenance(poolInfo.getRemoveAbandonedOnMaintanance()); } if (poolInfo.getRemoveAbandonedTimeout() != null) { dataSource.setRemoveAbandonedTimeout(poolInfo.getRemoveAbandonedTimeout()); } if (poolInfo.getMinEvictableTimeMillis() != null) { dataSource.setMinEvictableIdleTimeMillis(poolInfo.getMinEvictableTimeMillis()); } if (poolInfo.getNumTestsPerEvictionRun() != null) { dataSource.setNumTestsPerEvictionRun(poolInfo.getNumTestsPerEvictionRun()); } if (poolInfo.getTimeBetweenEvictionRunsMillis() != null) { dataSource.setTimeBetweenEvictionRunsMillis(poolInfo.getTimeBetweenEvictionRunsMillis()); } }