Java Chatter and Random Nagging

Saturday, November 18, 2006

Adding your development database under source control

I am not too sure whether the technique I am going to present today falls under the category of Source Control best practices. But I have been using this technique for a while now, I kind of like it, and I didn't experience any problems with it.

I like HSQLDB, in fact, I like it a lot !
(For any Marsians, HSQLDB is the leading SQL relational database engine written in Java. It is also the database engine in OpenOffice.)
And since I am using HSQLDB for my petproject, I wanted it to be portable and easily configurable/buildable, just like the petproject itself. And I wanted to be able to start it up and shut it down (I use mainly the standalone server) from within my favorite IDE. So these are the steps it took to meet my requirements :
  1. In Eclipse, create a New Project (of the General type, since you don't need a Java compiler).
  2. Create the following files in this project:
    • lib/hsqldb.jar: the binary jar, downloaded from the HSQLDB website.
    • contains the properties for the ant build file.
    • contains the parameters for starting up the database server.
    • build.xml: the ant build file.
  3. Add the whole project to source control.

The content of each of these files (except for the .jar) :

#Ant properties for starting the hsqlserver hrutil

#Build properties for starting, stopping and communicating with the database


<project name="hsqldb" default="startup">
<property file=""/>
<property file=""/>

<path id="master-classpath">
<fileset dir="lib">
<include name="*.jar"/>

<target name="startup" description="Starts up the standalone hsqldb server.
The server will automatically use the properties from .">
<java classname="org.hsqldb.Server" classpathref="master-classpath" fork="true"/>

<target name="manager" description="Starts up the built-in hsqldb databasemanager.">
<java classname="org.hsqldb.util.DatabaseManager" classpathref="master-classpath" fork="true"/>

<target name="shutdown" description="Shuts down the standalone hsqldb server.">
driver="${db.driver}" classpathref="master-classpath"

<target name="deleteDbFiles" description="Deletes the script files that the hsqldb server has created (Necessary for a clean restart.)">
<fileset dir="">
<include name="${server.database.0}.properties"/>
<include name="${server.database.0}.script"/>

The descriptions in the build.xml should be pretty self-explanatory to use this configuration. Its startup and shutdown targets make it possible to start and stop your hsqldb database server from within Eclipse. And even better, when developing on another computer, simply import the project from source control and you are immediately ready to start the database!!


Post a Comment

<< Home