Chariot Training Classes

Training Courses

I run Chariot's training and mentoring services. We provide training in AngularJS, HTML5, Spring, Hibernate, Maven, Scala, and more.

Chariot Education Services

Technology

Chariot Emerging Tech

Learn about upcoming technologies and trends from my colleagues at Chariot Solutions.

Resources

Chariot Conferences

Podcasts

« See you at Philly Emerging Tech | Main | Groovy Samples Episode #1 Available »
Saturday
Mar222008

A few tips for Grails Database Setups...

Here are a few quick tips for setting up the Grails datasources in grails-app/conf/DataSource.groovy:


  • To log all Hibernate queries, use
    loggingSql = true 
    either in the initial dataSource closure, or in a specific connection pool (Development, Test, Production)
  • If you didn't have time to create a database and are just prototyping domain relationships, don't worry about this file yet! Just open up BootStrap.groovy in the same directory, and wire up your domain classes like this:



    class BootStrap {
    def init = { servletContext ->
    def p1 = new Employee(firstName: "Ken",
    lastName:"Rimple",
    likesCoffee:true).save()
    }
    ...
    }

    This example above uses the embedded Hypersonic SQL in-memory database. Each time you spin up the application server, the default entry for the development instance creates the tables, and on the way out, drops them (create-drop). You could choose to switch to MySQL, for example, and use Create on one startup. Then, once you're done, switch to update. This will ensure that the data you've created stays in the database (and you can comment out the original BootStrapping code: don't delete it unless you want to type it in all over again once your database gets screwed up).

  • Keep in mind, anything you put at the initial dataSource closure gets inherited into the specific configurations. So, you might have the same database vendor in all three environments: use the same driver.
  • You can have different environments, and not just three. Change the environment names, and when you start up, pass the -Dgrails.env=production or -Denv=supersecretprobation flag to grails run-app and you'll use those configurations.

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>