super();
}
public DataSource setupDataSource(String connectURI) {
// creates DataSource
BasicDataSource ds = new BasicDataSource();
// for debugging.
if(Settings.isLoggingEnabled) {
ds.setAccessToUnderlyingConnectionAllowed(true);
}
ds.setDriverClassName(DriverClassNameResolver.resolve(Settings.get("xbird.db.kind")));
// sets up DataSource
ds.setUrl(connectURI);
final String dbuser = Settings.get("xbird.db.user");
final String dbpasswd = Settings.get("xbird.db.passwd");
if(dbuser != null && dbuser.length() != 0) {
ds.setUsername(dbuser);
ds.setPassword(dbpasswd);
}
// addtinal settings.
final String maxactive = Settings.get("xbird.db.pool.maxactive");
if(maxactive != null)
ds.setMaxActive(Integer.parseInt(maxactive));
final String maxidle = Settings.get("xbird.db.pool.maxidle");
if(maxidle != null)
ds.setMaxIdle(Integer.parseInt(maxidle));
final String maxwait = Settings.get("xbird.db.pool.maxwait");
ds.setMaxWait(maxwait == null ? DEFAULT_MAXWAIT : Integer.parseInt(maxwait));
ds.setDefaultAutoCommit(true);
//ds.setDefaultReadOnly(false);
final String initialsize = Settings.get("xbird.db.pool.initialsize");
ds.setInitialSize(initialsize == null ? DEFAULT_INITIAL_POLLSIZE
: Integer.parseInt(initialsize));
// sets up for PreparedStatements.
ds.setPoolPreparedStatements(true);
final String maxOpenPreparedStatements = Settings.get("xbird.db.pool.statement.cache_size");
ds.setMaxOpenPreparedStatements(maxOpenPreparedStatements == null ? MAX_OPEN_PREPARED_STATEMENTS
: Integer.parseInt(maxOpenPreparedStatements));
return ds;
}