In preparation to 3.2.M2, I am working on polishing our new query APIs. Good 
examples of the new API are a new SelectById query [1] and of course previously 
available SQLSelect. Now started working on SelectQuery, which is a more subtle 
matter as it affects every single Cayenne user. So instead of committing it 
right away, I created a pull request #16 [2] and now would like to hear 
comments before this goes to the main repo.

This changes SelectQuery and tweaks ExpressionFactory and Expression. You get 
the most milage out of it if you statically import ExpressionFactory. A good 
example is the Main file from our tutorials [3]:

// static imports
import static org.apache.cayenne.exp.ExpressionFactory.exp;
import static org.apache.cayenne.exp.ExpressionFactory.or;
...

// a single chain from query to object list
List<Painting> paintings2 = SelectQuery.query(Painting.class, 
qualifier2).select(context);
...

// static use of "exp" (former "Expression.fromString")
// immediate parameter binding
Expression qualifier3 = exp("artist.dateOfBirth < $date", "date", c.getTime());

// static use of 'or' seems cleaner than chaining expressions with 
'exp.orExp(..)'
List<Painting> paintings4 = SelectQuery.query(Painting.class, or(qualifier2, 
qualifier3)).select(context);

Comments?

Andrus

[1] 
https://github.com/apache/cayenne/blob/master/cayenne-server/src/main/java/org/apache/cayenne/query/SelectById.java
[2] https://github.com/apache/cayenne/pull/16
[3] 
https://github.com/andrus/cayenne/blob/9dca05242d393aba5892b6ce33e36fc7e2078bca/tutorials/tutorial/src/main/java/org/apache/cayenne/tutorial/Main.java

Reply via email to