<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi all,<br>
<br>
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.<br>
<br>
Our dsl aims to support filtering cached entities:<br>
* by attributes allowing equality and range filters (less than,
greater than, between) <br>
* some very simple collections tests (contains(value),
containsAll(setOfValues), containsAny(setOfValues)) that can be
applied to attributes that are collections of values<br>
* string 'like' operator similar to SQL<br>
* 'in' filter, to test if the attribute value belongs to a given
fixed set of values<br>
* The filters can be composed of subfilters connected by logical
and/or operators. Operator precedence can be changed using nested
subfilters.<br>
* Negation is also allowed of course<br>
* 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 <br>
<br>
As for type safety, the dsl should not allow the user to build
syntactically invalid queries.<br>
Having a dsl that is also typesafe with regard to the domain model
is desirable, but not a must for this early stage.<br>
<br>
Here is a simple domain model I've used for writing some sample
queries.<br>
<center><img class="moz-attached-image" shrinktofit="yes"
src="cid:part1.00070206.03060301@redhat.com" height="249"
width="348"><br>
<div align="left">
<blockquote>
<pre><div class="line" id="LC18"> // a typesafe version
<span class="n">User</span> <span class="n">$user</span> <span class="o">=</span> <span class="n">$</span><span class="o">(</span><span class="n">User</span><span class="o">.</span><span class="na">class</span><span class="o">);</span></div><div class="line" id="LC19"> <span class="n">Query</span> <span class="n">q0</span> <span class="o">=</span> <span class="n">from</span><span class="o">(</span><span class="n">$user</span><span class="o">)</span></div><div class="line" id="LC20"> <span class="o">.</span><span class="na">having</span><span class="o">(</span><span class="n">$user</span><span class="o">.</span><span class="na">getName</span><span class="o">()).</span><span class="na">eq</span><span class="o">(</span><span class="s">"John"</span><span class="o">)</span></div><div class="line" id="LC21"> &nb!
sp; &
nbsp; <span class="o">.</span><span class="na">and</span><span class="o">()</span></div><div class="line" id="LC22"> <span class="o">.</span><span class="na">having</span><span class="o">(</span><span class="n">$user</span><span class="o">.getAddress</span><span class="o">().getPostCode()).</span><span class="na">eq</span><span class="o">(</span><span class="s">"NW123"</span><span class="o">)</span></div><div class="line" id="LC23"> <span class="o">.</span><span class="na">build</span><span class="o">();
// non typesafe field references
</span></div><div class="line" id="LC26"> <span class="n">Query</span> <span class="n">q1</span> <span class="o">=</span> <span class="n">from</span><span class="o">(</span><span class="n">User</span><span class="o">.</span><span class="na">class</span><span class="o">)</span></div><div class="line" id="LC27"> <span class="o">.</span><span class="na">having</span><span class="o">(</span><span class="s">"name"</span><span class="o">).</span><span class="na">eq</span><span class="o">(</span><span class="s">"John"</span><span class="o">)</span></div><div class="line" id="LC28"> <span class="o">.</span><span class="na">and</span><span class="o">()</span></div><div class="line" id="LC29"> <span class="o">.</span><span class="na">having<!
/span><spa
n class="o">(</span><span class="s">"surname"</span><span class="o">).</span><span class="na">eq</span><span class="o">(</span><span class="s">"Doe"</span><span class="o">)</span></div><div class="line" id="LC30"> <span class="o">.</span><span class="na">build</span><span class="o">();
</span>
<span class="o">More query samples on github here: </span><a class="moz-txt-link-freetext" href="https://github.com/anistor/infinispan/blob/t_3169_m/query/src/main/java/org/infinispan/query/sandbox/sample_domain_model/QuerySamples.java">https://github.com/anistor/infinispan/blob/t_3169_m/query/src/main/java/org/infinispan/query/sandbox/sample_domain_model/QuerySamples.java</a>
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
</div></pre>
</blockquote>
</div>
<br>
</center>
</body>
</html>