Grails在运行时改变数据源 [英] Grails changing datasource at runtime

查看:175
本文介绍了Grails在运行时改变数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求实现一个逻辑,为单独的用户分配域(假设他将拥有自己的数据库)意味着所有域将在运行时映射到不同的数据库。 听起来很傻我知道


如何在数据源
用户登录后更改datasouce(持久性配置文件)应该在应用程序启动时加载。



是否有可能?


注意: strong>我想在运行时一次将某个域的数据源更改为另一个数据源。

解决方案

您可以在 DataSource.groovy 文件中映射多个数据源并且您可以创建多个有才华的域类,然后您可以在运行时在这些数据源之间执行任何 CRUD 操作。

参考文献




I was asked to implement a logic for having separate domains for a separate user (assuming he will have his own database) means all the domains will be mapped to different database at runtime. Sounds silly i know

How can i change the datasouce(persistence configuration file) after logIn of user while datasource are supposed to load at startup time of application.

Is it possible somehow?

NOTE: I want to change datasource of some domain to another datasource at runtime one at a time.

解决方案

You can map multiple data sources in your DataSource.groovy file and you can create multi talented domain classes and then you can perform any CRUD operations among these data sources at runtime.

References

这篇关于Grails在运行时改变数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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