You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Frédéric Esnault <fe...@legisway.com> on 2007/06/26 10:57:55 UTC

getNode without the name

Hi all,

 

I was wondering, is there a way to get a node (with NodeImpl.getNode() or something else), to get a node without knowing its name ?

For example, under the lgw:contracts node, I have plenty of nodes named with their uuid. I want, from the lgw:contracts node, to get the node with index 5.

 

The * being forbidden, and no child axis existing, I don't know if it's possible.

 

Any idea?

 

Frederic Esnault


RE: getNode without the name

Posted by Frédéric Esnault <fe...@legisway.com>.


-----Message d'origine-----
De : Jukka Zitting [mailto:jukka.zitting@gmail.com] 
Envoyé : vendredi 29 juin 2007 13:01
À : users@jackrabbit.apache.org
Objet : Re: getNode without the name


> Note that querying for a node is considerably more expensive than
> accessing the node directly by path or by UUID.

Yes, i know that, but we have to test search extensively. And in most cases, in our application, search are going to be used, and path or uuid won't be available.
I'm not worried about the performances of getting a node with a path or a uuid, I am much more about searches.

> Could you do a similar thing for node paths? List all the paths in
> your repository and pass that list to JMeter.

Actually I thought about this ;) , but it wouldn't be interesting. As I said just above, search is more interesting for me than get by path.

Frédéric Esnault

Re: getNode without the name

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 6/27/07, Frédéric Esnault <fe...@legisway.com> wrote:
> The thing is I'm writing JMeter tests and for a "Get Node Test Plan", I'm generating
> random position, and I want to get the contract (or whatever) node at the position
> defined by this random number.
>
> Something like : /lgw:root/lgw:contracts/child::*[__Random(1, max_contracts, position)]

Note that querying for a node is considerably more expensive than
accessing the node directly by path or by UUID.

> Your idea was good, anyway ;) And to be honest with you, I decided (to test the
> getNodeByUUID() method), to make an xml export of my nodes' uuids, ordered
> by node type. Like this I can pick some uuids in the export and pass them to
> JMeter. But I'd like to be able to test also the getNode "by path" method extensively.

Could you do a similar thing for node paths? List all the paths in
your repository and pass that list to JMeter.

BR,

Jukka Zitting

RE: getNode without the name

Posted by Frédéric Esnault <fe...@legisway.com>.
Hi Jukka, and thanks for your answer !

In fact I cannot use the UUID.

The thing is I'm writing JMeter tests and for a "Get Node Test Plan", I'm generating random position, and I want to get the contract (or whatever) node at the position defined by this random number.

Something like : /lgw:root/lgw:contracts/child::*[__Random(1, max_contracts, position)]

As the name of the contract node is not known (generated with the node uuid), and as the nodes are generated (I made a random data generator), I cannot "hard code" uuids in my JMeter test scenarios.

Your idea was good, anyway ;) And to be honest with you, I decided (to test the getNodeByUUID() method), to make an xml export of my nodes' uuids, ordered by node type. Like this I can pick some uuids in the export and pass them to JMeter. But I'd like to be able to test also the getNode "by path" method extensively.


Frédéric Esnault

-----Message d'origine-----
De : Jukka Zitting [mailto:jukka.zitting@gmail.com] 
Envoyé : mardi 26 juin 2007 21:58
À : users@jackrabbit.apache.org
Objet : Re: getNode without the name

Hi,

On 6/26/07, Frédéric Esnault <fe...@legisway.com> wrote:
> I was wondering, is there a way to get a node (with NodeImpl.getNode() or something
> else), to get a node without knowing its name ?

How about using Session.getNodeByUUID()?

It sounds like you already know something about the node (otherwise
you wouldn't be able to identify it), so you're done if you can make
that "something" be the UUID of the node.

BR,

Jukka Zitting

Re: getNode without the name

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 6/26/07, Frédéric Esnault <fe...@legisway.com> wrote:
> I was wondering, is there a way to get a node (with NodeImpl.getNode() or something
> else), to get a node without knowing its name ?

How about using Session.getNodeByUUID()?

It sounds like you already know something about the node (otherwise
you wouldn't be able to identify it), so you're done if you can make
that "something" be the UUID of the node.

BR,

Jukka Zitting

Re: getNode without the name

Posted by Bertrand Delacretaz <bd...@apache.org>.
On 6/26/07, Frédéric Esnault <fe...@legisway.com> wrote:

> ...Something like /foo/bar/jcr:child(5) for example,
> if jcr:chile(x) was a path util retrieving the xth child of the parent node (here the bar node).

I don't think this is possible using paths (as opposed to
queries)...and if it was the repository would probably do the same
thing that I suggested (getNodes() + skip/iterate) behind the scenes.

-Bertrand

RE: getNode without the name

Posted by Frédéric Esnault <fe...@legisway.com>.
Hi Bertrand,

Thanks for your answer. In fact this is not what I need. I know about the getNodes() method, but I was thinking to get a node with a path, not by making a "hack" with java code. Something like /foo/bar/jcr:child(5) for example, if jcr:chile(x) was a path util retrieving the xth child of the parent node (here the bar node).

Frédéric Esnault


-----Message d'origine-----
De : bdelacretaz@gmail.com [mailto:bdelacretaz@gmail.com] De la part de Bertrand Delacretaz
Envoyé : mardi 26 juin 2007 11:18
À : users@jackrabbit.apache.org
Objet : Re: getNode without the name

On 6/26/07, Frédéric Esnault <fe...@legisway.com> wrote:

> ...For example, under the lgw:contracts node, I have plenty of nodes named with their
> uuid. I want, from the lgw:contracts node, to get the node with index 5.

Not sure what you mean by index, but Node.getNodes() returns a
NodeIterator, and with NodeIterator.skip(int n) you can move to a
specific child. Isn't that what you need?

-Bertrand

Re: getNode without the name

Posted by Bertrand Delacretaz <bd...@apache.org>.
On 6/26/07, Frédéric Esnault <fe...@legisway.com> wrote:

> ...For example, under the lgw:contracts node, I have plenty of nodes named with their
> uuid. I want, from the lgw:contracts node, to get the node with index 5.

Not sure what you mean by index, but Node.getNodes() returns a
NodeIterator, and with NodeIterator.skip(int n) you can move to a
specific child. Isn't that what you need?

-Bertrand

Re: getNode without the name

Posted by Jukka Zitting <ju...@gmail.com>.
On 6/27/07, Frédéric Esnault <fe...@legisway.com> wrote:
> Hi Mark, thanks for the answer !
>
> You're right, I'm looking for something like what you wrote :
>
> /lgw:root/lgw:contracts/descendant::*[2]

See JCR-392, I think support for [n] is still an open issue.

BR,

Jukka Zitting

Re: getNode without the name

Posted by Mark Waschkowski <mw...@gmail.com>.
As well, you can test xpath's easily here:
 http://b-cage.net/code/web/xpath-evaluator.html

MW

On 6/26/07, Mark Waschkowski <mw...@gmail.com> wrote:
>
> I believe you may be looking for this:
>
> /node/node/descendant::*[2]
>
> As well, you can see more examples here (a resource I've found useful in
> the past):
>
>   http://www.zvon.org/xxl/XPathTutorial/General/examples.html
>
> Best,
>
> Mark
>
> On 6/26/07, Frédéric Esnault < fesn@legisway.com> wrote:
> >
> > Hi all,
> >
> >
> >
> > I was wondering, is there a way to get a node (with NodeImpl.getNode()
> > or something else), to get a node without knowing its name ?
> >
> > For example, under the lgw:contracts node, I have plenty of nodes named
> > with their uuid. I want, from the lgw:contracts node, to get the node with
> > index 5.
> >
> >
> >
> > The * being forbidden, and no child axis existing, I don't know if it's
> > possible.
> >
> >
> >
> > Any idea?
> >
> >
> >
> > Frederic Esnault
> >
> >
>
>
> --
> Best,
>
> Mark Waschkowski




-- 
Best,

Mark Waschkowski

RE: getNode without the name

Posted by Frédéric Esnault <fe...@legisway.com>.
Hi Mark, thanks for the answer !

You're right, I'm looking for something like what you wrote : 

/lgw:root/lgw:contracts/descendant::*[2]

But I get the same error as I get with * alone or with child::* 

javax.jcr.RepositoryException: failed to resolve path lgw:root/lgw:contracts/descendant::*[2] relative to /: Invalid name: descendant::*

And I used zvon.org a long time ago also, more for xsl at this time, but it was definitely one of my bookmarks ;)

Frédéric Esnault
 
-----Message d'origine-----
De : Mark Waschkowski [mailto:mwaschkowski@gmail.com] 
Envoyé : mardi 26 juin 2007 20:41
À : users@jackrabbit.apache.org
Objet : Re: getNode without the name

I believe you may be looking for this:

/node/node/descendant::*[2]

As well, you can see more examples here (a resource I've found useful in the
past):

  http://www.zvon.org/xxl/XPathTutorial/General/examples.html

Best,


Re: getNode without the name

Posted by Mark Waschkowski <mw...@gmail.com>.
I believe you may be looking for this:

/node/node/descendant::*[2]

As well, you can see more examples here (a resource I've found useful in the
past):

  http://www.zvon.org/xxl/XPathTutorial/General/examples.html

Best,

Mark

On 6/26/07, Frédéric Esnault <fe...@legisway.com> wrote:
>
> Hi all,
>
>
>
> I was wondering, is there a way to get a node (with NodeImpl.getNode() or
> something else), to get a node without knowing its name ?
>
> For example, under the lgw:contracts node, I have plenty of nodes named
> with their uuid. I want, from the lgw:contracts node, to get the node with
> index 5.
>
>
>
> The * being forbidden, and no child axis existing, I don't know if it's
> possible.
>
>
>
> Any idea?
>
>
>
> Frederic Esnault
>
>


-- 
Best,

Mark Waschkowski