The Artima Developer Community
Sponsored Link

Java Buzz Forum
Oracle's DML Returning and jDBI 2.0pre7

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brian McCallister

Posts: 1282
Nickname: frums
Registered: Sep, 2003

Brian McCallister is JustaProgrammer who thinks too much.
Oracle's DML Returning and jDBI 2.0pre7 Posted: Nov 28, 2006 11:40 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Brian McCallister.
Original Post: Oracle's DML Returning and jDBI 2.0pre7
Feed Title: Waste of Time
Feed URL: http://kasparov.skife.org/blog/index.rss
Feed Description: A simple waste of time and weblog experiment
Latest Java Buzz Posts
Latest Java Buzz Posts by Brian McCallister
Latest Posts From Waste of Time

Advertisement

So I broke down and have started adding some database-specific functionality to jDBI. The first bit is a statement customizer which does the downcasts and whatnot to make it convenient to use oracle's dml returning stuff (like "insert into something (id, name) values (something_id_seq.nextval, ?) returning id into ?").

public void testFoo() throws Exception
{
    Handle h = dbi.open();

    OracleReturning<Integer> or = new OracleReturning<Integer>(new ResultSetMapper<Integer>() {
        public Integer map(int index, ResultSet r) throws SQLException
        {
            return r.getInt(1);
        }
    });

    or.registerReturnParam(1, OracleTypes.INTEGER);

    h.createStatement("insert into something (id, name) values (17, 'Brian') returning id into ?")
            .addStatementCustomizer(or)
            .execute();
    List<Integer> ids = or.getReturnedResults();

    assertEquals(1, ids.size());
    assertEquals(Integer.valueOf(17), ids.get(0));
    h.close();
}

This allows for a nice API, without client code downcasts as well, to make use of results returned from DML against Oracle. When I get a chance I'll add one for Postgres as well :-) The code to do it is pretty straightforward. The nice part was that it required no changes to the core of jDBI 2.0 to do this :-)

Pushed 2.0pre7 as well ;-) Have fun!!

Read: Oracle's DML Returning and jDBI 2.0pre7

Topic: What is the Presentation Model pattern? Previous Topic   Next Topic Topic: JGoodies Binding API: The Basics

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use