Queries, the shortest way
October 10, 2008
Following a recent suggestion by an user Ammentos 1.3.5 introduced a new interesting feature: method chaining into SqlQueryFilter class. This allows a more concise syntax for loading objects, with no need to declare temporary SqlFilters objects.
With previous versions to load a Person object you had to write all this code:
SqlQueryFilter sql = new SqlQueryFilter("name=? and surname=?");
sql.setString("Alan");
sql.setString("Ford");
Person p = Ammentos.loadUnique(sql);
Here’s below the new, single statement syntax:
Person p = Ammentos.loadUnique(Person.class, new SqlQueryFilter("name=? and surname=?")
.setString("Alan").setString("Ford"));
This is possible because now any setXXX() method returns the SqlQueryFilter itself, similarly
to Java’s StringBuffer class.
A simple but nice and, mostly important, KISS idea. Thanks to Florin for his suggestion
Entry Filed under: ammentos, ddpole, development, java, opensource. .
1 Comment Add your own
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed

1.
jdv145 | November 20, 2008 at 8:02 pm
Very nice, i like it