Updates to Minion's query API
By searchguy on Mar 20, 2009
I've actually started to convert our AURA project code to use the new Minion
query API, and as a result I decided that having a single
class for all of the relational operators really makes code that uses
the query API look ugly.
I've just checked in a change to the query API that provides
individual classes for the relational operators. These are all simple
specializations of the
Relation class, but it makes the
code using the API a lot prettier. For example, this:
Element query = new And(new Relation("aura-type", Relation.Operator.EQUALS, "artist"), new Relation("aura-name", Relation.Operator.SUBSTRING, artistName));
Element query = new And(new Equals("aura-type", "artist"), new Substring("aura-name", artistName));
Which is a lot neater, in my opinion. Don't ever forget that your API is the user interface for your library!
While debugging some problems yesterday I discovered the need to print out the queries, so while I was in there, I added
toString methods that produce a nice string version of a query expressed using the API. The above query will be converted to the string:
(And (= aura-type artist) (
artistName is "coldplay", obviously!) And yes, that is an s-expression. Lisp programmers represent! (OK, OK, it's not really an s-expression (spaces in the field values will screw things up), but it's close, and the parentheses delineate the expressions nicely.)
The changes to the code have been committed and we should have new javadoc up later on today.