Thursday, 16 August 2012

BobSleigh - New SourceForge Project

I recently posted about my gripes with CRUD based generation tools which come with MyBatis / Hibernate etc.  These source code / entity generators are quite powerful but fall down somewhat with providing the ability to control precisely how the source looks.  In response to this I've decided to create my first SourceForge project (since JOGRE) called "BobSleigh" (Schema Lookup & Entity Item Generator).  It is being implemented with the following goals: -
  1. Simplicity - it must be simple to use i.e. no programming required for most scenarios - uses the FreeMarker template engine to generate the code.
  2. Power - must be powerful i.e. have full control over how and where the source is generated.
  3. Familiarity - uses XML and "borrows" concepts from ANT such as @basedir, and
  4. TDD - more of a side note but so far this project has been my first 100% test driven developed project.  Cobertura is being used as to ensure code coverage.
A release should be out fairly soon but in the mean time you can download a working prototype using SVN from SourceForge.

The following is the README file provided with the project.

                             B O B - S L E I G H

What is it?

BobSleigh - Schema Lookup & Entity Item Generator. 

BobSliegh is a Java based utility which can examine a user specified database connection and produce a simple mapped model of the database schema. This model can then be transformed into one or more files e.g. database acccess objects,

MyBatis SQL map files, Hibernate Java source etc. The utility uses the powerful FreeMarker template engine which ensures the user has totally control over the output of the generated source files. The configuration file also borrows concepts from ANT such as specifying the project "basedir" and user defined  properties.


Simplicity and Power!

Why use another CRUD type generation application when utilities such as MyBatis Generator exist for MyBatis or Jboss Hibernate Tools? 

When starting with a library such as MyBatis, Hiberate for the first time users run the included generation tools they are usually dismayed with the lack of control they have over the output / formatting / etc.

These tools are also product dependent e.g. MyBatis Generator will only create MyBatis artifacts.

BobSliegh takes a different approach and makes it very simple for a user to create totally customised CRUD based entity items.  A target database is parsed into a simple in-memory model which can be transformed using the very powerful FreeMarker engine either on a per table basis or on the whole database.
For example, there may exist a database with a single table called PRODUCT_ITEM which contains 3 fields "PRODUCT_ID", "DESCRIPTION" and "NAME".

After a database schema parse you could have the following very simple object tree: - = "PRODUCT_ITEM";
    table.jname = "ProductItem";

    tables.columns ("PRODUCT_ID", "DESCRIPTION", "NAME")
    e.g. a column object will contain = "PRODUCT_ID";     
        column.jname = "ProductId";
        column.type = "INTEGER"
        column.jtype = "int";
        column.nullable = false;
        ... etc

    tables.pkeys (list of primary key column objects)

This model can be used in a FreeMarker style template as follows: -


This will create the following POJO [ ]

    package org.project.test;

    public class ProductItem {

        private int productId;
        private String description;
        private String name;

        public ProductItem () {}

        public void setProductId (int productId) {
            this.productId = productId;
        public int getProductId () {
            return this.productId;
        public void setDescription (String description) {
            this.description = description;
        public String getDescription () {
            return this.description;
        public void setName (String name) {
   = name;
        public String getName () {
In the previous simple example the POJO's don't contain comments and only have a single blank constructor.  However, it is fairly easy for the user to update the template if the user wants a complex constructor, comments, etc and with all the power of FreeMarker.

The Latest Version

Details of the latest version can be found on the BobSleigh SourceForge Project web site .


Documentation is available.


This software is licensed under the terms you may find in the file named "LICENSE" in this directory.

Enjoy !!!
Author:   Bob Marks

Tuesday, 14 August 2012

Nice little post about getting SVN (with SSH) working with Subsclipe (Eclipse plugin) - basically requires pure java enabled.

Wednesday, 1 August 2012

Using a template engine to create DAOs, SQL maps

I am a fan of iBatis / MyBatis but no one likes creating these CRUD based artifacts by hand for each table in their database!  Tools exist which code generate the CRUD stuff for you such as iBator, which I personally don't like, as you have no control over what the actual generator content looks like.

Something which could be quite nice would be to have code which parses a database schema, creates a small in memory model and using a template engine such as FreeMarker / Velocity etc generates your application DAO source files etc.  I did a quick search on google and it seems I'm not the only one who has done this ...

This could be programmed fairly quickly from scratch, a better solution may be to extend the existing iBator code generator...