use of org.apache.tomcat.jdbc.pool.DataSourceFactory in project metacat by Netflix.
the class DataSourceManager method createDataSource.
private synchronized void createDataSource(final String name, final Map props) {
if (dataSources.get(name) == null) {
final Properties dataSourceProperties = new Properties();
props.forEach((key, value) -> {
final String prop = String.valueOf(key);
if (prop.startsWith(JDO_PREFIX)) {
dataSourceProperties.put(prop.substring(JDO_PREFIX.length()), value);
}
});
if (!dataSourceProperties.isEmpty()) {
try {
final DataSource dataSource = new DataSourceFactory().createDataSource(dataSourceProperties);
//
// Explicitly registering the datasource with the JMX server bean.
//
((org.apache.tomcat.jdbc.pool.DataSource) dataSource).preRegister(null, new ObjectName(String.format("jdbc.pool:name=%s", name)));
dataSources.put(name, dataSource);
} catch (Exception e) {
throw new RuntimeException(String.format("Failed to load the data source for catalog %s with error [%s]", name, e.getMessage()), e);
}
}
}
}
Aggregations