Expand my Community achievements bar.

Issue with database connection pool

Avatar

Level 4

I have created multiple data sources through sling:OsgiConfig nodes in the run mode configuration.

11.png

I can also see these configurations in configurations manager screen.

1.png

2.png

I am trying to get database connection using below code:

@Reference

    private DataSourcePool dspService;

....

getConnection(){

     DataSource ds = (DataSource) dspService.getDataSource("abc-xyz");

.....

}

I get an error:

com.day.commons.datasource.poolservice.DataSourceNotFoundException: No data source found with name 'abc-xyz' (after asking 0 providers).

If I open the config manager and save the configurations again, connection works successfully. Why is the behavior shown ?

I tried the following solution.

I created a bundle activator and put the code to programmatically update the configurations

ServiceReference serviceRef = context

.getServiceReference(ConfigurationAdmin.class.getName());

ConfigurationAdmin configAdmin = (ConfigurationAdmin) context

.getService(serviceRef);

String filter = '(' + ConfigurationAdmin.SERVICE_FACTORYPID + '='

+ "com.day.commons.datasource.jdbcpool.JdbcPoolService"

+ ')';

Configuration[] allLoggerConfigs = configAdmin

.listConfigurations(filter);

for (Configuration conf : allLoggerConfigs) {

conf.setBundleLocation(conf.getBundleLocation());

Dictionary prop = conf.getProperties();

log.info("Initializing : " + prop.get("datasource.name"));

conf.update(prop);

But I think the above is not required and should work without the above code. Please help

13 Replies