You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Gadbury <ga...@googlemail.com> on 2010/02/23 16:58:02 UTC

Query using Path Constraints and Same Name Siblings (SNS)

Hi all,

I am currently building a jcr query using path constraints.  The path is
built up by using someNode.getPath().  As I have same name sibling nodes
(SNS), my query is failing for the first SNS node path as getPath() returns
'node_name' and not 'node_name[1]'.

I have found out (to my horror!) after debugging that the following queries
are not the same :)

/jcr:root/shop/providers/provider/element(*, jpg:account)
/jcr:root/shop/providers/provider[1]/element(*, jpg:account)

The second query is the correct one in this case as I wish to return all
nodes of type jpg:account that are under the first provider (provider[1]).

Is there a way to stop getPath() from omitting the index notation for the
first same name sibling?

Are SNS really that 'dangerous'?

Thanks for your time and kind regards,

James
-- 
View this message in context: http://n4.nabble.com/Query-using-Path-Constraints-and-Same-Name-Siblings-SNS-tp1566095p1566095.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: Query using Path Constraints and Same Name Siblings (SNS)

Posted by Gadbury <ga...@googlemail.com>.
Thanks for the advice Alexander.  I was hoping there may be a simple switch
:)  It seems a bit horrible to append [1] to my path but that might be what
I have to do.  I will also think about switching from SNS nodes :)

Many thanks for your reply.
-- 
View this message in context: http://n4.nabble.com/Query-using-Path-Constraints-and-Same-Name-Siblings-SNS-tp1566095p1566204.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: Query using Path Constraints and Same Name Siblings (SNS)

Posted by Alexander Klimetschek <ak...@day.com>.
On Tue, Feb 23, 2010 at 16:58, Gadbury <ga...@googlemail.com> wrote:
> I have found out (to my horror!) after debugging that the following queries
> are not the same :)
>
> /jcr:root/shop/providers/provider/element(*, jpg:account)
> /jcr:root/shop/providers/provider[1]/element(*, jpg:account)
>
> The second query is the correct one in this case as I wish to return all
> nodes of type jpg:account that are under the first provider (provider[1]).
>
> Is there a way to stop getPath() from omitting the index notation for the
> first same name sibling?

If you need to separate between an SNS node and a normal one, you can
check via Node.getIndex(). This will return 1 for not-SNS nodes, so
you can check for actual existing SNS via
parentNode.getNodes(namePattern). Then you can build the path with the
index manually.

> Are SNS really that 'dangerous'?

Yes ;-)

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com