开发者

Is it possible to have a grails app choose between hibernate and mongodb at runtime

开发者 https://www.devze.com 2023-03-11 19:58 出处:网络
I\'m trying to build a Grails App. I want the user who installs this grails app on their tomcat instance be able to choose whether they want to use hibernate with an rdbms or mongodb while deploying t

I'm trying to build a Grails App. I want the user who installs this grails app on their tomcat instance be able to choose whether they want to use hibernate with an rdbms or mongodb while deploying the app.

  1. Is it possib开发者_StackOverflow社区le to have both plugins hibernate and mongodb and pick one based on a config file?

  2. Alternately is it possible to create two builds of the grails app with exactly same code, but different a plugin, so that the user can pick either build?


The second option is your best bet. If both plugins are installed you need to use the mapWith attribute to indicate which to use, and that's a static field in your domain classes.

But if you don't install the Mongo plugin all domain classes will use Hibernate, and if you uninstall the Hibernate plugin and install the Mongo plugin, all domain classes will use Mongo. That would be very easy to script - either run grails war (for Hibernate) or grails uninstall-plugin hibernate, grails install-plugin mongodb, and grails war (for Mongo).

0

精彩评论

暂无评论...
验证码 换一张
取 消