Question

How to prevent bootstraping of data in grails app. when we configured our DataSource.groovy like this

 development {
    dataSource {
        dbCreate = "update"
        url = "jdbc:mysql://localhost:3306/test"
        pooled = true
        driverClassName = "com.mysql.jdbc.Driver"
        dialect = org.hibernate.dialect.MySQL5InnoDBDialect
        username = "root"
        password = "root"
    }

}

BootStrap.groovy

class BootStrap {
def bootstrapService
def grailsApplication
def init = { servletContext ->
    switch (Environment.getCurrent().name) {
        case "dev":
            bootstrapService.bootstrapDummyData()
            break;
        case "test":
            bootstrapService.bootstrapDummyData()
            break;
    }
}
def destroy = {
}

I want bootstrapService.bootstrapDummyData() not to be called when i configrued my datasource to update mode. i.e. dbCreate = "update"

Was it helpful?

Solution

 class BootStrap {
 def bootstrapService
 def grailsApplication
 def init = { servletContext -> 
 if(grailsApplication.config.dataSource.dbCreate == "create-drop"){
    switch (Environment.getCurrent().name) {
        case "dev":
            bootstrapService.bootstrapDummyData()
            break;
        case "test":
            bootstrapService.bootstrapDummyData()
            break;
     }
   }
}

OTHER TIPS

def init(){

    if(User.list().size()==0)
       objectCreation()
}

def objectCreation(){

def userObject1 = new User()
def userObject2 = new User()


}

the above code for example. if user is created in bootstarp . first check user is already created or not. If not create object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top