Wednesday, April 28, 2010

Spring Roo: Persistence Setup

I've found Spring Roo to be a great way to learn how to setup configuration properly.  As I continue to spend time in configuring my home project, I continue to be amazed at the powerful features that Roo brings to the table. I had written a small application for tracking family chores. I spent about 25 minutes drawing the entities in a napkin, then spent 10 minutes writing a Roo script (file with extension "roo"). Then, I opened a Roo shell and run "script myscript.roo". This created my project, including all the scaffolding for my entities.  I had my project running in minutes. After a while, I detected a problem with my entities relationship and wanted to see the persisted data. Of course, I had the the "IN MEMORY" choice, which brought all sort of problems when trying to see the data within.

If you have used Roo for a few minutes only (as it tends to encourage you, to due to its simplicity), you have probably used the HYPERSONIC_IN_MEMORY database configuration. This is good for a first prototype, however once you start adding data, you want to start using HYPERSONIC_PERSISTENT or simply another available database as described with the --database parameters.  Roo makes this change a very pleasant experience. I chose MYSQL (since it was already installed). What a pleasant surprised that all I had to do was to write the following:

persistence setup --provider HIBERNATE --database MYSQL --userName --password --databaseName

At this point, all appropriate files were updated. Since I was using git for version control, I was able to see the files updated.  Not only was the pom.xml updated, but also the database.properties touched with the new configuration for the jdbc connection. I also noticed that the persistence.xml file was changed from "update" to "create" (I have to change this back to "update" if I want to continue seeing my data after reloads). This was nice as it makes sense to create the schema when it doesn't exist. I opened DbVisualizer and was happily browsing my newly created tables without problems. 

In a few words: Bravo Roo!

No comments: