How to get grails datasource createdb property in bootstrap

I want my Bootstrap to depend on the createdb property in the grails DataSource.groovy file. When the setting is "create", new master data must be generated if the parameter is "update", none.

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

+5
source share
3 answers

The easiest way is to simply check the dbCreate value from config, for example:

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...
}
+3
source

dbCreate - "grailsApplication" BootStrap.groovy:

def grailsApplication

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

ApplicationHolder , .

, -.

+9

ataylor . . Grails Grails 2.0?.

, canotto90 , def grailsApplication BootStrap. NPE.

0

All Articles