Viewing HSQLDB In Grails App

I have been looking over the net for a simple way to visualise the in memory data “hsqldb” of a grails app without moving to a real db to solve it. It turns out that grails has always had a built in visualizer/manager that can easily be started when you run up the dev environment. All you have to do is add these lines to the init function in your bootstrap.groovy file:

import org.codehaus.groovy.grails.commons.GrailsApplication
import grails.util.GrailsUtil
import grails.util.Environment

class BootStrap {

    def fixtureLoader

    def init = { servletContext ->

        String[] databaseManagerOptions = ['--url', 'jdbc:hsqldb:mem:devDB'];
        org.hsqldb.util.DatabaseManagerSwing.main(databaseManagerOptions)

        if (GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) {
            fixtureLoader.load("test_data")
        }

        if (GrailsUtil.environment == GrailsApplication.ENV_TEST) {
            fixtureLoader.load("test_data")
        }
       }

     def destroy = {
     }
}

The difference is only really the import or environment and the two lines for the database manager swing component. After you do this you app will then load up the manager tool every time you run your app in development mode.

One thought on “Viewing HSQLDB In Grails App”

Leave a Reply

Your email address will not be published. Required fields are marked *