Amalegeni, it's simple, it's flexible, it's adaptable ..

Amalegeni is a Java tool for generating boilerplate JDBC code. It's a simple, flexible and adaptable solution to keep your application lean, mean and fast. You, the developer, just writes a concise definition file, containing just enough and no more information to describe your beans (dto's), service interface and implementation java files. Amalegeni writes the rest.
Compile : you only use Amalegeni at compile time, there's no obese code monster piggybacking on your application, there are no heavy jar files to drag into your application's lib folder!
Debug: Reflection isn't used, it's Java code that gets generated: this makes it easy to use your debugger to drill down to the nitty gritty jdbc detail.
Customize : when you are not pleased with the code generated by the standard templates, either adapt them or roll your own ! You can even write templates to create documentation, convert .mlg files to .wsdl files, ...

It's simple, example 1: client/server

Using the Client/Server template, amalegeni generates the boilerplate JDBC java code (javabeans, interface and implementation), from one simple definition file. It's only that definition file that the developer has to focus on.

It really saves you writing a bunch of boilerplate code, and lets you avoid those typical copy & paste errors where snippets of copied code should have been changed but were overlooked. The above diagram shows which files are generated when using the client-server template.

It's simple, example 2: GWT

Another template is used for generating GWT boilerplate code, see following diagram. The shown generated classes will look familiar to you if you are a GWT developer. A cut-and-paste file is also created containing typical call-back code snippets you copy and paste into your entry-point class.

It's flexible.

If you are not pleased with the generated code, and maybe you want to roll the SQLExceptions into your own ApplicationExceptions, or you want to add some caching code in the Service implementation, nothing stops you tweaking the template file. This is a standard StringTemplate file, read more about it over here. If you don't know StringTemplate maybe first get introduced to Terrence Parr's wonderful tool, but don't forget to come back. And if your are completely dissatisfied, then why don't you write your own template from scratch!

It's adaptable.

The conversion from definition file to Java classes is a 3-stage process, and you can command Amalegeni to only execute the steps you desire, like skipping stage 1 (eg. you write your own definition file and parser), and feed your self-produced JSON file it into the second and third stage of the Amalegeni pipeline.

A Simple Example

This is what Amalegeni does: it turns this definition ..

package client;

bean MyBean
{
    int id;
    String name;
}

package server;

service MyService
{
    List<MyBean> getNameList()
    <<
        select id, name
        from   t_name
    >>
}

.. into this Java code :

public class MyServiceImpl extends ServiceBase implements MyService
{

  public List<MyBean> getNameList()
  throws SQLException
  {
        Connection connection = getConnection();
        PreparedStatement pstmt= connection.prepareCall(
            " select id, name"+
            " from   t_name" );
        ResultSet resultSet=pstmt.executeQuery();
        List<MyBean> c = new ArrayList<MyBean>();
        while ( resultSet.next() )
        {
            c.add(resultSetToMyBean( resultSet ) );
        }
        resultSet.close();
        pstmt.close();
        returnConnection(connection);
        return c;
  }
..

The above example uses the client/server template. If we'd apply the GWT template to the same code, then this would be generated.

Remarks:

  • Next to plain SQL also PL-SQL calls are possible, using double square brackets as delimiters. Returning refcursors from a PL/SQL function is supported for Oracle and Postgresql.
  • You can define Java methods that call other service methods, for this use the double curly braces as delimiters.

© Willem Moors, 2009 - 2013