Hi, Markus.
Markus Lanthaler wrote:
...
if (qm.hasLanguage(Query.HQL)) {
search_user =
qm.createQuery(", BaseObject as obj, StringProperty as prop
where doc.fullName = obj.name and obj.className = 'XWiki.OpenIdIdentifier'
and obj.id=prop.id.id and prop.id.name='identifier' and prop.value =
':identifier'", Query.HQL);
query statement should be full HQL statement (not such as in
store#search* methods), so it should be
"from XWikiDocument as doc, BaseObject as obj, StringProperty as prop
where doc.fullName = obj.name and obj.className =
'XWiki.OpenIdIdentifier'
and obj.id=prop.id.id and prop.id.name='identifier' and prop.value =
:identifier", Query.HQL);"
} else if (qm.hasLanguage(Query.XPATH)) {
search_user =
qm.createQuery("/*/*[obj/XWiki/OpenIdIdentifier/@xp:identifier =
':identifier'] ", Query.XPATH);
} else
throw new RuntimeException();
Query.XPATH parameters should be with braces: ":{identifier}".
(It is difficult to use ":identifier" because of ambiguous with xml
namespaces (ex: "xwiki:document", "xp:property") in XPath language.
There is no xpath parameters in JCR v1 standard, so I implement it by self.)
search_user.bindValue("identifier",
openid_identifier);
List<XWikiDocument> found_users = search_user.setLimit(1).execute();
if (found_users.size() > 0) {
if (log.isDebugEnabled()) {
log.debug("OpenID " + openid_identifier + " already
registered.");
}
return found_users.get(0).getFullName();
}
return null;
}
I recommend you to use named queries. See
http://xwiki.markmail.org/message/tui6w6d5d27tirda
You need to move hql statements to queries.hbm.xml, xpath statements to
JcrQueries.properties, and use queryManager.getNamedQuery(qname).
Don't worry about XPath queries, I'll add them by self after JcrStore
will work fine. So you can write only hql queries.
but all I get is a NullPointerException when
qm.createQuery(..., Query.HQL)
is called. What's wrong with my code?
This should work after Vincent fix.
--
Artem Melentyev