The Artima Developer Community
Sponsored Link

Java Buzz Forum
jDBI 2.0 Accidental Feature

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.0 Accidental Feature Posted: Mar 16, 2006 3:29 PM
Reply to this message Reply

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

I got an accidental feature in the upcoming 2.0 jDBI when I implemented forward-only external iteration (via an iterate() method on Query:

    public void testIteratorBehavior2() throws Exception
    {
        h.insert("insert into something (id, name) values (1, 'keith')");
        h.insert("insert into something (id, name) values (2, 'eric')");

        ResultIterator<Something> i = h.createQuery("select * from something order by id")
                .map(Something.class)
                .iterator();

        Something first = i.next();
        assertEquals("keith", first.getName());
        Something second = i.next();
        assertEquals(2, second.getId());
        assertFalse(i.hasNext());

        i.close();
    }

I realized that providing the iterate method provided all that was needed for Iterable, so we also get...

    public void testIterable() throws Exception
    {
        int count = 0;
        h.insert("insert into something (id, name) values (1, 'keith')");
        h.insert("insert into something (id, name) values (2, 'keith')");

        for (Something s : h.createQuery("select * from something").map(Something.class))
        {
            assertEquals("keith", s.getName());
            count++;
        }
        assertEquals(2, count);
    }

Nifty! Looking forward to getting this release out =)

Read: jDBI 2.0 Accidental Feature

Topic: 030506_20481.jpg [Flickr] Previous Topic   Next Topic Topic: [DrunkAndRetired.com Podcast] Episode 41 - GC Elves vs. Bread Elves

Sponsored Links



Google
  Web Artima.com   

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