use of org.opennms.netmgt.config.opennmsDataSources.JdbcDataSource in project opennms by OpenNMS.
the class ReportCompiler method initializeSingleInstanceDatabase.
/**
* Initializes a single instance DB connection factory.
* <p>From <code>org.opennms.netmgt.poller.MonitorTester</code></p>
*/
private static void initializeSingleInstanceDatabase() {
try {
final File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.OPENNMS_DATASOURCE_CONFIG_FILE_NAME);
final DataSourceConfiguration dsc = JaxbUtils.unmarshal(DataSourceConfiguration.class, cfgFile);
boolean found = false;
for (JdbcDataSource jds : dsc.getJdbcDataSourceCollection()) {
if (jds.getName().equals("opennms")) {
System.out.printf("Initializing datatabase %s\n", jds.getUrl());
DataSourceFactory.setInstance(new SimpleDataSource(jds));
found = true;
}
}
if (!found) {
System.err.printf("Error: Can't find OpenNMS database configuration.\n");
System.exit(1);
}
} catch (Exception e) {
System.err.printf("Error: Can't initialize OpenNMS database connection factory. %s\n", e.getMessage());
System.exit(1);
}
}
Aggregations