Question

I would like to iterate over all the available dataSources for the current environment, trying to see if any of them contain a particular domain instance. Each environment has different dataSources.

The best I've hacked up so far is grailsApplication.config.findAll { it.key.contains('dataSource_') }. Is there a better or more legitimate way to do this?

Was it helpful?

Solution

You can also query against the bean names in the application context.

Something like

ctx.beanDefinitionNames.findAll{ it.contains( 'dataSource' ) }

At least that is what the DatasourcesUtils in the Datasources plugin does -

http://plugins.grails.org/grails-datasources/trunk/src/groovy/com/burtbeckwith/grails/plugin/datasources/DatasourcesUtils.groovy

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top