* @throws Exception
* Error occurred when parsing properties to create the
* connection factory
*/
private GenericObjectPool createGenericConnectionFactory(Config config) throws Exception {
GenericObjectPool poolConnection = new GenericObjectPool();
String maxPool = config.getProperty(RDBMS.MAX_POOL_SIZE);
String maxIdle = config.getProperty(RDBMS.MAX_IDLE);
String minPool = config.getProperty(RDBMS.MIN_POOL_SIZE);
String maxWait = config.getProperty(RDBMS.MAX_WAIT);
String testOnReturn = config.getProperty(RDBMS.TEST_ON_RETURN);
String testOnBorrow = config.getProperty(RDBMS.TEST_ON_BORROW);
String testWhileIdle = config.getProperty(RDBMS.TEST_WHILE_IDLE);
String timeBetweenEvictionRunsMillis = config.getProperty(
RDBMS.TIME_BETWEEN_EVICTION_RUNS_MILLS);
String numTestsPerEvictionRun = config.getProperty(RDBMS.NUM_TESTS_PER_EVICTION_RUN);
String minEvictableIdleTimeMillis = config.getProperty(
RDBMS.MIN_EVICTABLE_IDLE_TIME_MILLIS);
int minPoolSize = DBConstants.DEFAULT_DBCP_MIN_POOL_SIZE;
int maxPoolSize = DBConstants.DEFAULT_DBCP_MAX_POOL_SIZE;
try {
if (!DBUtils.isEmptyString(maxPool)) {
maxPoolSize = Integer.valueOf(maxPool).intValue();
poolConnection.setMaxActive(maxPoolSize);
}
if (!DBUtils.isEmptyString(minPool)) {
minPoolSize = Integer.valueOf(minPool).intValue();
poolConnection.setMinIdle(minPoolSize);
}
int maxPoolIdle = poolConnection.getMaxIdle();
if (!DBUtils.isEmptyString(maxIdle)) {
maxPoolIdle = Integer.valueOf(maxIdle).intValue();
poolConnection.setMaxIdle(maxPoolIdle);
}
if (!DBUtils.isEmptyString(maxWait)) {
int maxPoolWait = Integer.valueOf(maxWait).intValue();
poolConnection.setMaxWait(maxPoolWait);
}
if (!DBUtils.isEmptyString(testOnBorrow)) {
poolConnection.setTestOnBorrow(Boolean.parseBoolean(testOnBorrow));
}
if (!DBUtils.isEmptyString(testOnReturn)) {
poolConnection.setTestOnReturn(Boolean.parseBoolean(testOnReturn));
}
if (!DBUtils.isEmptyString(testWhileIdle)) {
poolConnection.setTestWhileIdle(Boolean.parseBoolean(testWhileIdle));
}
if (!DBUtils.isEmptyString(timeBetweenEvictionRunsMillis)) {
long timeBetweenPoolEvictionRunsMillis = Long
.valueOf(timeBetweenEvictionRunsMillis).longValue();
poolConnection.setTimeBetweenEvictionRunsMillis(timeBetweenPoolEvictionRunsMillis);
}
if (!DBUtils.isEmptyString(numTestsPerEvictionRun)) {
int numTestsPerPoolEvictionRun = Integer.valueOf(numTestsPerEvictionRun).intValue();
poolConnection.setNumTestsPerEvictionRun(numTestsPerPoolEvictionRun);
}
if (!DBUtils.isEmptyString(minEvictableIdleTimeMillis)) {
long minPoolEvictableIdleTimeMillis = Long.valueOf(minEvictableIdleTimeMillis)
.longValue();
poolConnection.setMinEvictableIdleTimeMillis(minPoolEvictableIdleTimeMillis);
}
return poolConnection;
} catch (NumberFormatException e) {
log.error("Non-numeric value found for numeric pool configuration property", e);
throw e;