Remove simpledb mapWith by meta programming in dev mode

≡放荡痞女 提交于 2019-12-25 02:43:24

问题


I am using simpleDB GORM with my grails application, though simpledb is great its a huge drag while in development mode, every click takes few seconds resulting in not so rapid development.

From what I understand simpleDB comes into action only if domain class has following two lines in code

String id
static mapWith = "simpledb"

So, my question is, is it possible to remove/hide these two declaration on the fly from domain classes depending on some kind of flag?

Same question asked differently,

Is there a way in Groovy, most probably meta programming, by which I can

  • Remove a variable declaration from a class(Domain class actually)
  • Remove static mapWith declaration from a class(Domain class again)
  • Finally, is there a way to iterate through all my domain class and perform first two operations in bootstrap.

回答1:


If you remove mapWith = "simpledb" it will be mapped with Hibernate, and it is probably not a very good idea to develop on Hibernate GORM in dev and SimpleDB GORM in prod mode - the biggest problem is that your application would behave very differently because SimpleDB is based on eventually consistency, and it means you would get nasty surprises when in production compared to good old consistent world of relational DB...

Thank you for using simpledb plugin!

Roman.




回答2:


I'm not familiar with simpleDB but I'm assuming that if your mapWith looked like:

static mapWith = ""

That simpleDB would not be used.

So you could add this to your Config.groovy:

environments {
    production {
        mapWith = "simpleDB"
    }
    development {
        mapWith = ""
    }
    test {
        mapWith = ""
    }
}

Then you could access the Config value from:

import org.codehaus.groovy.grails.commons.*

static mapWith = ConfigurationHolder.config.mapWith

So then when you create a Production war you'll get "simpleDB" otherwise you'll get an empty string. Here is a link to see how to use the Config.groovy: http://grails.org/doc/latest/guide/conf.html#config

If I'm way off on how simpleDB works I apologize.




回答3:


Haven't tried it, but I came across this link which claims:

SimpleDB/dev provides a local SimpleDB server, so you can develop offline, without even currently having a SimpleDB account.



来源:https://stackoverflow.com/questions/8799361/remove-simpledb-mapwith-by-meta-programming-in-dev-mode

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