You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Frédéric Esnault <fe...@legisway.com> on 2007/06/22 10:00:56 UTC
jcr:deref() in predicate
Hi all !
I'm facing a strange situation. I'm wondering if I'm doing something wrong or if it's a jackrabbit problem.
I tried this search : /jcr:root/lgw:root/lgw:contracts/element(*, lgw:contractType)[jcr:deref(@lgw:internalContractor, 'lgw:contractorType')/@lgw:companyName = 'Lycos']
(I use element() because I'm testing not same name siblings performances).
The problem is that this query raises an exception :
InvalidQueryException: Unsupported location for jcr:deref()at
org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.createFunction(XPathQueryBuilder.java:887) at org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder.visit(XPathQueryBuilder.java:459) at org.apache.jackrabbit.core.query.xpath.SimpleNode.jjtAccept(SimpleNode.java:80)
...
In fact the error is raised in createFunction when testing the JCR_DEREF function. It fails because it accepts either a
QueryNode.TYPE_LOCATION or a QueryNode.TYPE_PATH queryNode type, or raises the InvalidQueryException.
The problem is that my queryNode, which is a RelationQueryNode, has a type set to 0, and 0 is not a valid type (I checked the constants defined in
QueryNode abstract class). I saw the contructor in RelationQueryNode with no type creation, but what's the meaning of this?
Is it forbidden to put a jcr:deref in a predicate, knowing that we can use child nodes and properties?
Frederic Esnault
Re: jcr:deref() in predicate
Posted by Marcel Reutegger <ma...@gmx.net>.
Frédéric Esnault wrote:
> Thanks for the answer, but my question was : is there another way only using
> XPath? I should have been clearer, sorry.
no, there is not. jcr:deref() can only be used to dereference a property along
the path. e.g.
foo/bar/jcr:deref(@myRef, '*')/bla
regards
marcel
RE: jcr:deref() in predicate
Posted by Frédéric Esnault <fe...@legisway.com>.
Thanks for the answer, but my question was : is there another way only using XPath? I should have been clearer, sorry.
Frédéric Esnault
-----Message d'origine-----
De : Marcel Reutegger [mailto:marcel.reutegger@gmx.net]
Envoyé : vendredi 22 juin 2007 12:28
À : dev@jackrabbit.apache.org
Objet : Re: jcr:deref() in predicate
Frédéric Esnault wrote:
> Thansk I will because if we don't have, how can we do this query.
>
> I want all contracts having as an internal contractor the company Lycos.
> Knowing that contractors are references in the contract type.
>
> I did /jcr:root/lgw:root/lgw:contracts/element(*, lgw:contractType)[jcr:deref(@lgw:internalContractor, 'lgw:contractorType')/@lgw:companyName = 'Lycos']
>
> Is there antoher way to make this query?
yes, there is. only search for the company node:
lgw:root//element(*, lgw:company)[@lgw:companyName = 'Lycos']
then use the API to get the references to the lycos company node:
Node lycosCompany = ...;
for (PropertyIterator it = lycosCompany.getReferences(); it.hasNext(); ) {
Property p = it.nextProperty();
if (p.getName().equals("lgw:internalContractor")) {
Node contractType = p.getParent();
// do something with this node
}
}
or even better, if there were no same name siblings you could directly address
the lycos company by path:
Node rootNode = ...;
rootNode.getNode("lgw:root/companies/Lycos");
that way you don't even have to execute a query.
in contrast to databases you don't necessarily have to use joins to get to your
content along references. the JCR API provides methods to do that much quicker
than a query.
regards
marcel
Re: jcr:deref() in predicate
Posted by Marcel Reutegger <ma...@gmx.net>.
Frédéric Esnault wrote:
> Thansk I will because if we don't have, how can we do this query.
>
> I want all contracts having as an internal contractor the company Lycos.
> Knowing that contractors are references in the contract type.
>
> I did /jcr:root/lgw:root/lgw:contracts/element(*, lgw:contractType)[jcr:deref(@lgw:internalContractor, 'lgw:contractorType')/@lgw:companyName = 'Lycos']
>
> Is there antoher way to make this query?
yes, there is. only search for the company node:
lgw:root//element(*, lgw:company)[@lgw:companyName = 'Lycos']
then use the API to get the references to the lycos company node:
Node lycosCompany = ...;
for (PropertyIterator it = lycosCompany.getReferences(); it.hasNext(); ) {
Property p = it.nextProperty();
if (p.getName().equals("lgw:internalContractor")) {
Node contractType = p.getParent();
// do something with this node
}
}
or even better, if there were no same name siblings you could directly address
the lycos company by path:
Node rootNode = ...;
rootNode.getNode("lgw:root/companies/Lycos");
that way you don't even have to execute a query.
in contrast to databases you don't necessarily have to use joins to get to your
content along references. the JCR API provides methods to do that much quicker
than a query.
regards
marcel
RE: jcr:deref() in predicate
Posted by Frédéric Esnault <fe...@legisway.com>.
Thansk I will because if we don't have, how can we do this query.
I want all contracts having as an internal contractor the company Lycos.
Knowing that contractors are references in the contract type.
I did /jcr:root/lgw:root/lgw:contracts/element(*, lgw:contractType)[jcr:deref(@lgw:internalContractor, 'lgw:contractorType')/@lgw:companyName = 'Lycos']
Is there antoher way to make this query?
Frédéric Esnault - Ingénieur R&D
Legisway
60 boulevard de la mission Marchand
92400 Courbevoie La Défense
-----Message d'origine-----
De : Marcel Reutegger [mailto:marcel.reutegger@gmx.net]
Envoyé : vendredi 22 juin 2007 11:25
À : dev@jackrabbit.apache.org
Objet : Re: jcr:deref() in predicate
Frédéric Esnault wrote:
> Is it forbidden to put a jcr:deref in a predicate, knowing that we can use
> child nodes and properties?
jackrabbit does not support the jcr:deref function in a predicate.
please file a jira issue if you wish to see this enhancement in jackrabbit.
regards
marcel
Re: jcr:deref() in predicate
Posted by Marcel Reutegger <ma...@gmx.net>.
Frédéric Esnault wrote:
> Is it forbidden to put a jcr:deref in a predicate, knowing that we can use
> child nodes and properties?
jackrabbit does not support the jcr:deref function in a predicate.
please file a jira issue if you wish to see this enhancement in jackrabbit.
regards
marcel