Summary
Anders Norås released the initial version of Quaere, a DSL for language-integrated queries in Java. Quaere provides language extensions to filter, enumerate and create projections over collections and other queryable sources.
Advertisement
At the JavaZone conference earlier this week, Anders Norås released the initial version of his language-integrated query tool, Quaere. The key benefit of this tool is that it allows querying of Java collections and other queryable data sources based on arbitrary query criteria:
Quaere is an internal domain specific language that adds a querying syntax reminiscent of SQL to Java applications. The language is modeled [on] Microsoft’s Language Integrated Query (LINQ) project, which adds similar capabilities to a range of Microsoft .NET languages. The Quaere project allows users to use an internal DSL to filter, enumerate and create projections over a number of collections and other queryable resources using a common, expressive syntax.
The Quaere DSL is very flexible and it lets you perform a wide range of queries against any data structure that is an array, or implements the java.lang.Iterable or the org.quaere.Queryable interface.
In a blog post announcing Quaere, Norås compared several features of Quaere to Microsoft's LINQ project that provides language-integrated querying for .NET:
Quaere supports the same conversion operators as LINQ, the only difference is that some of the operators have different names to match the Java conventions better. For instance, if you’d like your query result to be a List you can do this:
String[] words = {"cherry", "apple", "blueberry"};
List sortedWords =
asList(
from("w").in(words).orderByDescending("w.length()").select("w")
);
What do you think of Quaere, and of language-integrated querying, in general?
I was at the talk, getting the full presentation, and I must say I am really impressed. Quaere looks very promising indeed, and it will be even better when closures becomes path of java. It is currently based on fluent interfaces (rather than embedded language, like LINQ), but the difference is basically only that you separate the words with dots instead of spaces.