Hi, devs.
I would like to propose new QueryManager which will deprecate our
store.search(* methods
This proposal is based on Vincent ideas at
http://markmail.org/message/mjgg52coupsmfomg
and QueryManager from JCR v2
QueryManager is designed for low-level querying in Java code.
(QueryPlugin for high-level and velocity)
The main idea is support of multiple languages and easy to add new
languages. This is needed for JCRStore.
Here is interfaces:
public interface QueryManager {
Query createQuery(String statement, String language);
Query getNamedQuery(String qname);
String[] getLanguages();
boolean hasLanguage(String language);
}
public interface Query {
enum Language {
HQL,
XPATH,
JCRSQL
}
<T> List<T> execute();
Query bindValue(String var, Object val);
Query setLimit(int limit);
Query setOffset(int offset);
}
Here is abstract usecase:
QueryManager qm = xwiki.getStore().getQueryManager();
Query q = qm.getNamedQuery("SomeNameOfQuery");
if (q==null && qm.hasLanguage(Query.Language.HQL.name())) {
q = qm.createQuery("from XWikiDocument where author=:var",
Language.HQL.name());
} else if (q==null && qm.hasLanguage(Language.XPATH.name())) {
q = qm.createQuery("/*/*[@author=:var]", Language.XPATH.name());
} else
throw new RuntimeException();
List<XWikiDocument> res = q.setLimit(10).setOffset(10)
.bindValue("var", "Some.Author").execute();
notes:
I'm not sure we need getNamedQuery right now. But it can be useful for
move some complicated queries to store level (to some QueryHolders) or
overriding queries.
Queries are detached from store session. So session isn't opened until
Query#execute().
WDYT?
--
Artem Melentyev