0

I've seen a few posts about why it's bad to inject logic into your domain classes, and i haven't actually figured out how to inject 'grailsApplication'.

I'm looking to setup Domain Class index TTL values by Grails Environment. I don't want documents living in Mongo past 24 hours on my Integration environment.

Using Grails 2.4.3, and Gorm 3.1.4.

Does anyone have a better pattern for this?

This code wouldn't work, but this is the concept if grailsApplication could be injected

static mapping = {
  version false
  createdOn index:true, indexAttributes:[expireAfterSeconds:grailsApplication.config.DEFAULT_AGEOFF_IN_SECONDS]
}
Kirby
  • 1,980
  • 3
  • 21
  • 33

1 Answers1

0

I ended up with the following.. if a better answer comes along i'll select the better answer.

import grails.util.Environment

...

if(Environment.current.name == 'integration'){
  createdOn index:true, indexAttributes:[expireAfterSeconds:86400]//24 hours
} else {
  createdOn index:true, indexAttributes:[expireAfterSeconds:2592000]//30 days
}
Kirby
  • 1,980
  • 3
  • 21
  • 33