如何在Grails中使用注入的dataSource执行操作? [英] How to use injected dataSource in Grails to perform operations?

查看:140
本文介绍了如何在Grails中使用注入的dataSource执行操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有办法在grails中对.createCriteria(),.list()和.find()之类的特定操作使用注入的数据源?

Is there a way to use an injected datasource in grails for specific operations such as .createCriteria() , .list(), and .find()?

我尝试了以下操作:

def dataSource_test //Injected dataSource

DomainClass.dataSource_test.createCriteria() //returns no property for domain class
DomainClass.createCriteria(dataSource_test) //returns no matching method for argument

我知道可以通过以下方式进行操作:

I know it is possible to do the following way:

DomainClass.test.createCriteria()

但是,这种方式给我带来了更多问题,链接在这里:在Grails中使用多个数据源时验证使用了错误的数据源?

This way however gives me more issues, linked here: Validation using wrong datasource when using multiple datasources in Grails?

推荐答案

是否有一种方法可以针对特定的目标使用grails中的注入数据源 .createCriteria(),.list()和.find()之类的操作?

Is there a way to use an injected datasource in grails for specific operations such as .createCriteria() , .list(), and .find()?

不.我们支持多个数据源,并提供一种机制来表达您希望将特定查询与之关联的数据源,但这并不是您要的内容.我们没有为您提供将GORM方法与注入到工件中的数据源相关联的方法.

No. We support multiple datasources and provide a mechanism for expressing which datasource you want a particular query to be associate with, but that isn't what you are asking about. We do not provide a way for you to associate GORM methods with a data source that you have injected into an artifact.

这篇关于如何在Grails中使用注入的dataSource执行操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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