This post originated from an RSS feed registered with Java Buzz
by Brian McCallister.
Original Post: Some JDBI 3 Noodling
Feed Title: Waste of Time
Feed URL: http://kasparov.skife.org/blog/index.rss
Feed Description: A simple waste of time and weblog experiment
I grabbed the most recent build of jdk8 w/ lambdas tonight and started noodling on jdbi 3, which will require Java 8.
Set<Something>things=jdbi.withHandle(h->{h.execute("insert into something (id, name) values (?, ?)",1,"Brian");h.execute("insert into something (id, name) values (?, ?)",2,"Steven");returnh.query("select id, name from something").map(rs->newSomething(rs.getInt(1),rs.getString(2))).into(newHashSet<Something>());});assertThat(things).isEqualTo(ImmutableSet.of(newSomething(1,"Brian"),newSomething(2,"Steven")));
The Stream interface is kind of heavy to implement as it stands right now, and I couldn’t get IDEA 12 and the JDK to agree on valid syntax. Neither one wants to let me omit the <Something> in the .into(new
HashSet<Something>()); line, which the most recent State of the Collections implies I should be able to.
It would be really nice if the lambda syntax sugar would quietly drop return values when it is auto-converting to a Block without the { ... } – I had to make some things accept a Function rather then a Block even though I ignore the return value, this will then bite you when you use something that doesn’t have a return value. Java has side effects, sometimes we call a function which returns a value just for the side effects.
All told, I like the changes so far quite a bit despite my quibbles :-)