Jenny the db code generator

This program reads a database and generates java source which provides strongly typed access to the database.

by Paul Wheaton and Marilyn de Queiroz

Why was Jenny created?

In my opinion, there are two major problems with JDBC:

For each table and view in a given database, Jenny will create a java source class file. Each of these classes will provide a collection of general purpose methods for working with the table/view. They will also provide a list of all the column names, the table/view name and an inner class called Row that can be used to manipulate a single row in the table.

Many tables have a primary key that is a non-nullable integer called "tablenameID" or sometimes "ID". If Jenny finds this, she will add extra methods to the generated source for working with the primary key.

Some of my goals:

What does Jenny do?

Each generated class will provide some basic methods such as these:
      Row getRow()
      Row getRow( String column , String searchText )
      DBResults search( String column , String searchText , String[] dataColumns )
      Row[] getRows( String column , String searchText )
      Row[] getAllRows()
      DBResults search( String[] dataColumns )
      void update( String column , String searchText , Map data )
      void delete( String column , String searchText )
      void insert( Map data )
    
If an ID field is found, some methods like these will also be added:
      Row getRow( int id )
      void delete( int id )
    
Every class will have an inner class called Row that can provide strong type checking for every field (column) as well as methods like:
       void update()
       void delete()
       void insert()
    
The strong type checking for Row is provided by getters and setters. Suppose you have a table called Employee. Jenny will generate a class called EmployeeTable that will contain a Row class that might have the following methods:
       int getEmployeeID()
       void setEmployeeID( int employeeID )
       String getLastName()
       void setLastName( String lastName )
    
Here's a sample of a business logic method that uses a Jenny generated class:
       // pass in an employee ID and get back the number of tax exemptions that the employee claims
       private int getEmployeeExemptions( int employeeID )
       {
           return EmployeeTable.getRow( employeeID ).getExemptions();
       }
    
This same code using plain JDBC could be 10 to 40 lines long depending on how it would be implemented. You would need to get a connection, create a statement, build your sql string, execute your statement, wade through the result set, and each of these things need try/catch/finally blocks! Don't forget to close your connection, statement and result set!

How do I use Jenny?

From the command line: From your IDE:

She's still maturing

Note that development of Jenny is on-going and she's currently available as a beta release. Take 'er for a spin, and stop by the JDBC forum in the Big Moose Saloon to participate in her growth.