private ComboPooledDataSource pooledDataSource;
@Override
public void start(ConnectionFactoryConfiguration config, ClassLoader classLoader) throws PersistenceException {
logFileOverride(classLoader);
PooledConnectionFactoryConfiguration pooledConfiguration;
if (config instanceof PooledConnectionFactoryConfiguration) {
pooledConfiguration = (PooledConnectionFactoryConfiguration) config;
}
else {
throw new PersistenceException("ConnectionFactoryConfiguration passed in must be an instance of " +
"PooledConnectionFactoryConfiguration");
}
pooledDataSource = new ComboPooledDataSource();
pooledDataSource.setProperties(new Properties());
try {
/* Since c3p0 does not throw an exception when it fails to load a driver we attempt to do so here
* Also, c3p0 does not allow specifying a custom classloader, so use c3p0's
*/
Class.forName(pooledConfiguration.driverClass(), true, ComboPooledDataSource.class.getClassLoader());
pooledDataSource.setDriverClass(pooledConfiguration.driverClass()); //loads the jdbc driver
} catch (Exception e) {
log.errorInstantiatingJdbcDriver(pooledConfiguration.driverClass(), e);
throw new PersistenceException(String.format(
"Error while instatianting JDBC driver: '%s'", pooledConfiguration.driverClass()), e);
}
pooledDataSource.setJdbcUrl(pooledConfiguration.connectionUrl());
pooledDataSource.setUser(pooledConfiguration.username());
pooledDataSource.setPassword(pooledConfiguration.password());
if (log.isTraceEnabled()) {
log.tracef("Started connection factory with config: %s", config);
}
}