This blog might help you to speed up your bootstrap process, especially when you need to populate records in tables.
Earlier we used populate our database table by reading line by line from a CSV file and creating Domain Class object ad Save. But this was taking a huge time. And in our case, this data (more like a static information) was always same. So we came up with an idea – we took mysqldump for this particular table and saved it to our application’s web-app/data directory. Now the thing was, we just need to execute this “sql” file during bootstrap!
Below is the example how to execute database dump files in bootstrap!
import groovy.sql.Sql import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH String sqlFilePath = ApplicationHolder.application.parentContext.servletContext.getRealPath("/data/table_dump.sql") String sqlString = new File(sqlFilePath).text Sql sql = Sql.newInstance(CH.config.dataSource.url, CH.config.dataSource.username, CH.config.dataSource.password, CH.config.dataSource.driverClassName) sql.execute(sqlString)
Hope this helped!