Hi all,
As per ISPN-3169 "Define a Query API that will be common for library
mode + remote" we set out to define a simple dsl for writing queries
against embedded and remote caches that should be agnostic to the actual
engine that executes the query (lucene in our case now but might be
others later) and yet be easy to be translated into the native query
language of the said engine.
Our dsl aims to support filtering cached entities:
* by attributes allowing equality and range filters (less than,
greater than, between)
* some very simple collections tests (contains(value),
containsAll(setOfValues), containsAny(setOfValues)) that can be applied
to attributes that are collections of values
* string 'like' operator similar to SQL
* 'in' filter, to test if the attribute value belongs to a given
fixed set of values
* The filters can be composed of subfilters connected by logical
and/or operators. Operator precedence can be changed using nested
subfilters.
* Negation is also allowed of course
* besides filtering based on attributes of the root entity it should
also be able to filter on attributes of embedded entities (eg.
person.address.postalCode == "123") at any nesting level
As for type safety, the dsl should not allow the user to build
syntactically invalid queries.
Having a dsl that is also typesafe with regard to the domain model is
desirable, but not a must for this early stage.
Here is a simple domain model I've used for writing some sample queries.
// a typesafe version User $user = $(User.class);
Query q0 = from($user)
.having($user.getName()).eq("John")
.and()
.having($user.getAddress().getPostCode()).eq("NW123")
.build(); // non typesafe field references
Query q1 = from(User.class)
.having("name").eq("John")
.and()
.having("surname").eq("Doe")
.build(); More query samples on github here:
https://github.com/anistor/infinispan/blob/t_3169_m/query/src/main/java/o...
This is just an interface sketch, not an implementation. Your
thoughts and comments regarding this dsl are very welcome! I'll add
all of the above to the wiki too. Cheers