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
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