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();
}
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!
0 writebacks [/src/java/jdbi] permanent link