Grails changing datasource at runtime

回眸只為那壹抹淺笑 提交于 2020-01-07 06:14:23

问题


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.


回答1:


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

  • http://www.jellyfishtechnologies.com/configure-multiple-datasources-in-grails/
  • http://www.jellyfishtechnologies.com/querying-on-multiple-datasource-in-grails/
  • http://grails.org/doc/2.2.1/guide/conf.html#multipleDatasources


来源:https://stackoverflow.com/questions/19930204/grails-changing-datasource-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!