On Jun 17, 2013, at 10:31 AM, Thomas Mortagne <thomas.mortagne(a)xwiki.com> wrote:
On Thu, Jun 13, 2013 at 7:03 PM, Vincent Massol
<vincent(a)massol.net> wrote:
On Jun 13, 2013, at 7:01 PM, Vincent Massol <vincent(a)massol.net> wrote:
Hi devs,
Right now the QueryFilter interface allows to modify the query statement and to filter
returned results but doesn't allow to pass dynamic value.
I'm currently implementing a filter that'll return only results for the current
language and thus I need this dynamicity.
Are you ok that I break the QueryFitler API to add a new method:
public interface QueryFilter
{
String filterStatement(String statement, String language);
List filterResults(List results);
// New method
Map<String, String> getParameters();
}
WDYT?
Noe that the only other option I know of is to have a ParametrizedQueryFilter IF and do
an instanceof in HqlQueryExecutor.
Why would you need a if in HqlQueryExecutor ? It just call
filterResults and filterStatement which you did not touched in your
proposal.
This second proposal was to avoid breaking an API (I personally prefer the first
proposal). You need an IF in order to cast to ParametrizedQueryFilter and call the
getParameters()/bindParameters() method.
Note that in the end I didn't need anything since I was able to work around the issue
in my case:
// Note that we cannot have SQL injection here since getCurrentLanguage() will
always return a valid Locale
return insertWhereClause(String.format("(doc.language is null or doc.language
= '' or doc.language = '%s')",
getCurrentLanguage().toString()), statement, language);
So this need is less urgent. We can push it till we get the need again…
Thanks
-Vincent
> It's less clean but would not break the API.
>
> Thanks
> -Vincent