*/
public SqlDao(final Properties properties) {
super(properties);
// Attempt to create the DataSource.
ComboPooledDataSource comboPooledDataSource =
new ComboPooledDataSource();
// Set the properties from the properties file (the ones that begin
// with "c3p0").
comboPooledDataSource.setProperties(properties);
// Attempt to load the driver to be used to connect to the database.
if(properties.containsKey(KEY_PROPERTY_DATABASE_DRIVER)) {
try {
comboPooledDataSource
.setDriverClass(
properties.getProperty(KEY_PROPERTY_DATABASE_DRIVER));
}
catch(PropertyVetoException e) {
LOGGER.log(Level.SEVERE, "The driver was rejected.", e);
throw new IllegalStateException("The driver was rejected.", e);
}
}
// Otherwise, we may error out.
else {
LOGGER
.log(
Level.SEVERE,
"For SQL database connections, a driver must be " +
"specified.");
}
// If the JDBC URL was given, use that.
if(properties.containsKey(KEY_PROPERTY_DATABASE_JDBC_URL)) {
comboPooledDataSource
.setJdbcUrl(
properties.getProperty(KEY_PROPERTY_DATABASE_JDBC_URL));
}
// Otherwise, ask the specific implementation for a default URL.
else {
comboPooledDataSource.setJdbcUrl(getJdbcUrl());
}
// Set the username and password.
comboPooledDataSource.setUser(getDatabaseUsername());
comboPooledDataSource.setPassword(getDatabasePassword());
// Save the data source.
dataSource = comboPooledDataSource;
// Create the JDBC template from the data source.