Search in sources :

Example 1 with DataSourceFactory

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);
            }
        }
    }
}
Also used : DataSourceFactory(org.apache.tomcat.jdbc.pool.DataSourceFactory) Properties(java.util.Properties) SQLException(java.sql.SQLException) DataSource(javax.sql.DataSource) ObjectName(javax.management.ObjectName)

Aggregations

SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 ObjectName (javax.management.ObjectName)1 DataSource (javax.sql.DataSource)1 DataSourceFactory (org.apache.tomcat.jdbc.pool.DataSourceFactory)1