The Artima Developer Community
Sponsored Link

Java Buzz Forum
jDBI 2.0pre1

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.
jDBI 2.0pre1 Posted: May 6, 2006 2:03 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Brian McCallister.
Original Post: jDBI 2.0pre1
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

Pushed jDBI 2.0pre1 last night. This is very much an ongoing development branch -- not many docs, not all the sugary features of 1.X (Spring TX integration, the magic configuration detection, etc), but it has some major features that just aren't doable under the 1.X design, like much more explicit control over things when you need it, while still providing the higher level functions when you don't -- and the ability to mix them pretty willy-nilly.

Rather than C&P lots of code here, I'll reference the test cases to demonstrate stuff =)

  • More Sophisticated Named Parameter Binding

        public void testInsert() throws Exception
        {
            Handle h = openHandle();
            UpdateStatement insert = h.createStatement("insert into something (id, name) values (:id, :name)");
            insert.bind("id", 1);
            insert.bind("name", "Brian");
            int count = insert.execute();
            assertEquals(1, count);
        }
    
        public void testDemo() throws Exception
        {
            Handle h = DBI.open(Tools.getDataSource());
            h.createStatement("insert into something (id, name) values (:id, :name)")
                    .bind("id", 1)
                    .bind("name", "Brian")
                    .execute();
            h.insert("insert into something (id, name) values (?, ?)", 2, "Eric");
            h.insert("insert into something (id, name) values (?, ?)", 3, "Erin");
    
            List<Something> r = h.createQuery("select id, name from something " +
                                              "where name like :name " +
                                              "order by id")
                    .bind("name", "Eri%")
                    .map(Something.class)
                    .list();
    
            assertEquals(2, r.size());
            assertEquals(2, r.get(0).getId());
            assertEquals(3, r.get(1).getId());
    
            h.close();
        }
    
  • Generics Based Mapping

        public void testIteratorBehavior3() throws Exception {
            h.insert("insert into something (id, name) values (?, ?)", 1, "keith");
            h.insert("insert into something (id, name) values (?, ?)", 2, "keith");
    
            int count = 0 ;
            for (Something s : h.createQuery("select * from something order by id").map(Something.class))
            {
                count++;
                assertEquals("keith", s.getName());
            }
            assertEquals(2, count);
        }
        

  • Much more powerful statement rewriting capabilites. The rules (and rewriter) from 1.X is the default, but you can add additional macro capabilities pretty easily, say something like: select {org.skife.jdbi.Something} from something which will look up writeable javabeans properties on Something and put this in by name. That is not to say jDBI does strong o/r m, but that it is trivial to add ActiveRecord style auto-mapping (not its querying stuff, or tight integration with the stack, am not tring to bring down the wrath of the railzors (which I probably count as, so, umh, hmm)) in a typed manner (and without the dreaded select * from something).

  • The 2.0 branch (trunk really) keeps all the easy to use batching, prepared batching, scripting, externalized statements, etc. Just adds better hooks into the innards, and makes more fine grained stuff easier, which is awfully important to be able to drill into. Once again, jDBI is not a JDBC abstraction library, it is a JDBC convenience library -- optimized for people, not driver writers!

Anyway, have fun! and let us know if things break, could be better, are bass ackwards, or whatnot!

Read: jDBI 2.0pre1

Topic: JSF productivity Previous Topic   Next Topic Topic: WIPI J2ME strangeness

Sponsored Links



Google
  Web Artima.com   

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