我可以列出所有可用的数据源吗? [英] Can I list all of the dataSources available?

查看:136
本文介绍了我可以列出所有可用的数据源吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想遍历当前环境的所有可用数据源,试图查看它们中是否包含特定的域实例。每个环境都有不同的数据源。



到目前为止我已经破解的最好的版本是 grailsApplication.config.findAll {it.key.contains(' dataSource_')} 。有没有更好或更合理的方法来做到这一点?

解决方案

您也可以在应用程序上下文中针对bean名称进行查询。



类似于

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

>

至少这就是Datasources插件中的DatasourcesUtils所做的事情 -

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


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?

解决方案

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

这篇关于我可以列出所有可用的数据源吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆