* @param config the database configuration.
*
* @return the built data source.
*/
public static DataSource buildDataSource(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 {
basicDataSource.setMaxActive(DatabaseConstants.DEFAULT_MAX_ACTIVE);
}
if (config.getMaxWait() != null) {
basicDataSource.setMaxWait(Integer.parseInt(config.getMaxWait()));
} else {
basicDataSource.setMaxWait(DatabaseConstants.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(DatabaseConstants.DEFAULT_MIN_IDLE);
}
if (config.getValidationQuery() != null) {
basicDataSource.setValidationQuery(config.getValidationQuery());
}
return basicDataSource;
}