Remove simpledb mapWith by meta programming in dev

2019-09-11 05:37发布

问题:

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.