You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Nicolas Betheuil <Ni...@europe.adp.com> on 2010/11/23 16:46:43 UTC

xpath query of subnode

Hi,

I have the following structure for my default schéma
/aRootNode/subNode/onePath/myInterestingNode/conditions[2]/@someHelpffulAttributes
/aRootNode/subNode/otherVeryDifferentPath/myOtherInterestingNode/ (without condition)

In the first i have two conditions with some attributes
On the second my node have no conditions.

I have a Profile in memory that have some properties that should match with conditions. The target is to list interestingNodes on the Profile if conditions are matching. If no condition, that's mean that's everybody could see this.

I begin with SQL2 like i work with last release of jackrabbit but when dealing with differents paths make subqueries and join (that's all i have found) i try xpath. I have read that's deprecated by the spec but it's always there and working so I try.
I success to make an xpath that match when my profile have or not same conditions.
But i donc succeed to make an xpath that match node without conditions.

One of my case make this query
/aRootNode/subNode/*[(conditions/@property!='propName') or (conditions/@property='propName' and conditions/@operator='eq' and conditions/@expectedValue=true) or (count(conditions)=0)]
But the count(conditions)=0 doesn't work. Worse, ever it's in an or condition, all is false and nothing is returned.

I try with not(conditions), length(conditions)=0 or trying to understand what's go on count(conditions)>0 to find all nodes with conditions as children but nothing match.

Do you have an idea ?
Thank's to have read me to the end

RE: xpath query of subnode

Posted by Nicolas Betheuil <Ni...@europe.adp.com>.
Only to complete and tell when i'm gone, i think i will follow your work arround. 

I try to make the request in SQL2 and it's works pretty well when the repo is loaded in local, in the same JVM (TranscientRepository).
Here is the query

select * from [nt:unstructured] as a
right outer join [nt:unstructured] as c on isdescendantnode(a, c)
where localname(c) = 'conditions'

When I try to make the same test with a remote repo with davex, the query fails. When i remove the join the query don't fail.
I try to select only a.* elements on a.title (one of my attributes) but it's same.

javax.jcr.RepositoryException: More than one selector. Use getPath(String) instead. 

[1] http://jackrabbit.510166.n4.nabble.com/Performance-of-SQL-2-versus-XPATH-td1590422.html
[2] https://issues.apache.org/jira/browse/JCR-2535

-----Message d'origine-----
De : Alexander Klimetschek [mailto:aklimets@adobe.com] 
Envoyé : mercredi 24 novembre 2010 17:51
À : users@jackrabbit.apache.org
Objet : Re: xpath query of subnode

On 24.11.10 16:56, "Nicolas Betheuil" <Ni...@europe.adp.com>
wrote:

>Thank's for your quick answer but it's seems doesn't work. I speak about
>the not function of course. The other part (/aRootNode/subNode//*) is
>working expect that the root of a repo is always jcr:root and the
>rootNode is of course under this node. That was a mistake in my first
>post but like it's something i understand i want to make it available to
>everyone.

Might be that not() doesn't work properly with nodes and/or same-name
siblings. I thought it would do.

As a workaround, you could set a property like "hasConditions" or
"noConditions" on your target nodes and query for them: "@hasConditions =
false".

Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel





Re: xpath query of subnode

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 24.11.10 16:56, "Nicolas Betheuil" <Ni...@europe.adp.com>
wrote:

>Thank's for your quick answer but it's seems doesn't work. I speak about
>the not function of course. The other part (/aRootNode/subNode//*) is
>working expect that the root of a repo is always jcr:root and the
>rootNode is of course under this node. That was a mistake in my first
>post but like it's something i understand i want to make it available to
>everyone.

Might be that not() doesn't work properly with nodes and/or same-name
siblings. I thought it would do.

As a workaround, you could set a property like "hasConditions" or
"noConditions" on your target nodes and query for them: "@hasConditions =
false".

Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel





RE: xpath query of subnode

Posted by Nicolas Betheuil <Ni...@europe.adp.com>.
Thank's for your quick answer but it's seems doesn't work. I speak about the not function of course. The other part (/aRootNode/subNode//*) is working expect that the root of a repo is always jcr:root and the rootNode is of course under this node. That was a mistake in my first post but like it's something i understand i want to make it available to everyone.

I thought of prepare an extract what I want to do in a small archive and make it available to anyone that would like to look after it. Do you think it could be interesting ? I should open instead a jira ?

Thanks
Nicolas

-----Message d'origine-----
De : Alexander Klimetschek [mailto:aklimets@adobe.com] 
Envoyé : mardi 23 novembre 2010 17:08
À : users@jackrabbit.apache.org
Objet : Re: xpath query of subnode

On 23.11.10 16:46, "Nicolas Betheuil" <Ni...@europe.adp.com>
wrote:
>I have the following structure for my default schéma
>/aRootNode/subNode/onePath/myInterestingNode/conditions[2]/@someHelpffulAt
>tributes
>/aRootNode/subNode/otherVeryDifferentPath/myOtherInterestingNode/
>(without condition)
>
>One of my case make this query
>/aRootNode/subNode/*

You want to do /aRootNode/subNode//* as you have intermediate steps such
as "onePath" or "otherVeryDifferentPath" in your example.

>[(conditions/@property!='propName') or (conditions/@property='propName'
>and conditions/@operator='eq' and conditions/@expectedValue=true) or
>(count(conditions)=0)]
>But the count(conditions)=0 doesn't work. Worse, ever it's in an or
>condition, all is false and nothing is returned.

count() is not supported in JCR xpath, which only implements a subset of
Xpath 1.0. For more see the spec starting at section 6.6:
http://www.day.com/specs/jcr/1.0/index.html

But not(conditions) should do the trick.


Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel





Re: xpath query of subnode

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 23.11.10 16:46, "Nicolas Betheuil" <Ni...@europe.adp.com>
wrote:
>I have the following structure for my default schéma
>/aRootNode/subNode/onePath/myInterestingNode/conditions[2]/@someHelpffulAt
>tributes
>/aRootNode/subNode/otherVeryDifferentPath/myOtherInterestingNode/
>(without condition)
>
>One of my case make this query
>/aRootNode/subNode/*

You want to do /aRootNode/subNode//* as you have intermediate steps such
as "onePath" or "otherVeryDifferentPath" in your example.

>[(conditions/@property!='propName') or (conditions/@property='propName'
>and conditions/@operator='eq' and conditions/@expectedValue=true) or
>(count(conditions)=0)]
>But the count(conditions)=0 doesn't work. Worse, ever it's in an or
>condition, all is false and nothing is returned.

count() is not supported in JCR xpath, which only implements a subset of
Xpath 1.0. For more see the spec starting at section 6.6:
http://www.day.com/specs/jcr/1.0/index.html

But not(conditions) should do the trick.


Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel