jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcel Reutegger <marcel.reuteg...@gmx.net>
Subject Re: jcr:deref() in predicate
Date Fri, 22 Jun 2007 10:27:36 GMT
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 = ...;

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.


View raw message