Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get grails datasource createdb property in bootstrap

I'd like to make my Bootstrap dependant on the createdb property in the grails DataSource.groovy file. When the setting is 'create', new Master Data should be generated, if the setting is 'update', none.

I've found GrailsDataSource in the Grails API which also has a method getCreateDb, but I don't know how to access it from the Bootstrap for the respective Bootstrap environment.

like image 946
Jörg Brenninkmeyer Avatar asked Jun 28 '10 16:06

Jörg Brenninkmeyer


2 Answers

The up-to-date way to obtain dbCreate property is injecting 'grailsApplication' to BootStrap.groovy:

def grailsApplication

if(grailsApplication.config.dataSource.dbCreate == 'create'){
    ...
}

ApplicationHolder is now deprecated and I couldn't get it to work.

Hope it helps someone.

like image 200
Tomas Romero Avatar answered Nov 15 '22 04:11

Tomas Romero


The easiest way is probably to just check the value of dbCreate from the config, like so:

import org.codehaus.groovy.grails.commons.ApplicationHolder

if (ApplicationHolder.application.config.dataSource.dbCreate == "create") {
    ...do create stuff...
} else if (ApplicationHolder.application.config.dataSource.dbCreate == "update") {
    ...do update stuff...
}
like image 42
ataylor Avatar answered Nov 15 '22 03:11

ataylor