PooledConnectionFactoryConfiguration pooledConfiguration;
if (config instanceof PooledConnectionFactoryConfiguration) {
pooledConfiguration = (PooledConnectionFactoryConfiguration) config;
}
else {
throw new CacheLoaderException("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 CacheLoaderException(String.format(
"Error while instatianting JDBC driver: '%s'", pooledConfiguration.driverClass()), e);
}
pooledDataSource.setJdbcUrl(pooledConfiguration.connectionUrl());
pooledDataSource.setUser(pooledConfiguration.username());
pooledDataSource.setPassword(pooledConfiguration.password());