// set the JMX domain for the C3P0
C3P0CustomManagementCoordinator.setJmxDomainOnce(config.getJmxDomain());
// create a new instance of the c3p0 datasource
ComboPooledDataSource cpds = new ComboPooledDataSource(true);
// set properties
try {
// set required properties
cpds.setDriverClass(config.getDriver());
cpds.setUser(config.getUsername());
cpds.setPassword(config.getPassword());
cpds.setJdbcUrl(config.getUrl());
// set optional properties
cpds.setDataSourceName(config.getName());
cpds.setMinPoolSize(config.getMinPoolSize());
cpds.setMaxPoolSize(config.getMaxPoolSize());
// we'll set the initial pool size to the minimum size
cpds.setInitialPoolSize(config.getMinPoolSize());
// set the validation query
cpds.setPreferredTestQuery(config.getValidationQuery());
// amount of time (in ms) to wait for getConnection() to succeed
cpds.setCheckoutTimeout((int)config.getCheckoutTimeout());
// checkin validation
cpds.setTestConnectionOnCheckin(config.getValidateOnCheckin());
// checkout validation
cpds.setTestConnectionOnCheckout(config.getValidateOnCheckout());
// amount of time to wait to validate connections
// NOTE: in seconds
int seconds = (int)(config.getValidateIdleConnectionTimeout()/1000);
cpds.setIdleConnectionTestPeriod(seconds);
// set idleConnectionTimeout
// NOTE: in seconds
seconds = (int)(config.getIdleConnectionTimeout()/1000);
cpds.setMaxIdleTimeExcessConnections(seconds);
// set activeConnectionTimeout
seconds = (int)(config.getActiveConnectionTimeout()/1000);
cpds.setUnreturnedConnectionTimeout(seconds);
if (config.getDebug()) {
cpds.setDebugUnreturnedConnectionStackTraces(true);
} else {
cpds.setDebugUnreturnedConnectionStackTraces(false);
}
// properties I think aren't valid for c3p0
// defines how many times c3p0 will try to acquire a new Connection from the database before giving up.
cpds.setAcquireRetryAttempts(10);
} catch (PropertyVetoException e) {
throw new SQLConfigurationException("Property was vetoed during configuration", e);
}