Brian's Waste of Time

Tue, 26 Apr 2005

jDBI 1.3.0 Released

Released a minor API change version of jDBI last night. Significant features include:

  1. Global named parameters which may be set on either a DBI or Handle intance. Handles inherit named params from their parent DBI, but names set on the Handle do not percolate back up. This added two methods to public interfaces, so lead to the 1.3.X instead of 1.2.X. Feature request from John Wilson, aka tug.
  2. Exceptions thrown within the Spring integration system are wrapped in Spring's DataAccessException hierarchy. Thomas Risberg did the heavy lifting for this one (and noticed they needed to do it!). This support will improve with minor releases as I refactor to make things play better with the exception translator.

Global params are easy to show examples of:

public void testParamOnBareFirst() throws Exception
{
    handle.getGlobalParameters().put("name", "Robert");
    handle.execute("insert into something (id, name) values (:id, :name)", 
                   new Something(1, "Robert"));

    Map robbie = handle.first("select * from something where name = :name");
    assertNotNull(robbie);
    assertEquals(new Integer("1"), robbie.get("id"));
}

public void testOnDBI() throws Exception
{
    handle.close();
    DBI dbi = new DBI(Tools.CONN_STRING);
    dbi.getGlobalParameters().put("name", "Robert");
    handle = dbi.open();

    handle.execute("insert into something (id, name) values (:id, :name)", 
                   Args.with("id", new Integer(1)));
    Map robbie = handle.first("select * from something where name = :name");
    assertNotNull(robbie);
    assertEquals(new Integer("1"), robbie.get("id"));
}

So have fun with it!

0 writebacks [/src/java/jdbi] permanent link