You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by Andrei Dulvac <an...@gmail.com> on 2015/02/11 10:55:01 UTC

Copy a node from oak run console?

Hi devs,

I'm curious of the easiest way to copy a jcr node using the oak run  groovy
console. I know that's easily achievable from the workspace by using the
path and using the jcr Session:   session.getWorkspace().copy("/path/src",
"/path/dst/");
But from the oak run groovy console, all I have to start with is a
org.apache.jackrabbit.oak.console.ConsoleSession. I can't seem to find a
way to get the jcr workspace. Noob question 2: Should ConsoleSession
implement Session?

Thanks,
Andrei

Re: Copy a node from oak run console?

Posted by Chetan Mehrotra <ch...@gmail.com>.
On Wed, Feb 11, 2015 at 8:59 PM, Andrei Dulvac <an...@gmail.com> wrote:
> Not a biggie, but it's odd that doesn't exist on the NodeBuilder or
> something.

NodeBuilder API was meant to model the Tree access and has just the
required set of operations to enable our usecases and was not meant to
model the JCR Node/Property API. So for generic operations its
preferable to stick to JCR api!

Chetan Mehrotra

Re: Copy a node from oak run console?

Posted by Andrei Dulvac <an...@gmail.com>.
Hi,

Thanks all for the responses, it's much clearer now.

You can use NodeBuilder#setChildNode(String, NodeState) to efficiently
> copy a node.
>
That's what I did. But I had to recursively do that for all children nodes
of the source. Which is not a big deal.

>
> Note however, that this method doesn't respect JCR semantics and thus
> can't be used to implement javax.jcr.Workspace#copy(String, String) and
> the like.
>
Got it, thanks!

>
> Michael
>

Re: Copy a node from oak run console?

Posted by Michael Dürig <md...@apache.org>.

On 11.2.15 4:29 , Andrei Dulvac wrote:
> Not a biggie, but it's odd that doesn't exist on the NodeBuilder or
> something.

You can use NodeBuilder#setChildNode(String, NodeState) to efficiently 
copy a node. Under the hood this method uses value sharing to save space 
and time.

Note however, that this method doesn't respect JCR semantics and thus 
can't be used to implement javax.jcr.Workspace#copy(String, String) and 
the like.

Michael

Re: Copy a node from oak run console?

Posted by Andrei Dulvac <an...@gmail.com>.
Hi Chetan,

Just how I thought. But I hoped there would be a way to get a JCR Session.
What I was trying to do is copy a node (NodeState) with all its properties
and children. Using the oak API, I had to roll my own and recursively call
copy. Not a biggie, but it's odd that doesn't exist on the NodeBuilder or
something.

Thanks!
Andrei

On Wed Feb 11 2015 at 12:38:10 PM Chetan Mehrotra <ch...@gmail.com>
wrote:

> oak-run console is only meant to initialize a Oak ContentSession
> (which differs from a JCR Session!) and does not initializes a full
> feldged JCR session. So you cannot perform operations via JCR API. The
> console is mostly meant to perform low level debugging and
> manipulation of data.
>
> What are you trying to achieve? If you can use the std JCR API then
> prefer that but then yes oak-run console cannot be used
>
>
> Chetan Mehrotra
>
>
> On Wed, Feb 11, 2015 at 3:25 PM, Andrei Dulvac <an...@gmail.com>
> wrote:
> > Hi devs,
> >
> > I'm curious of the easiest way to copy a jcr node using the oak run
> groovy
> > console. I know that's easily achievable from the workspace by using the
> > path and using the jcr Session:   session.getWorkspace().copy("/
> path/src",
> > "/path/dst/");
> > But from the oak run groovy console, all I have to start with is a
> > org.apache.jackrabbit.oak.console.ConsoleSession. I can't seem to find a
> > way to get the jcr workspace. Noob question 2: Should ConsoleSession
> > implement Session?
> >
> > Thanks,
> > Andrei
>

Re: Copy a node from oak run console?

Posted by Chetan Mehrotra <ch...@gmail.com>.
oak-run console is only meant to initialize a Oak ContentSession
(which differs from a JCR Session!) and does not initializes a full
feldged JCR session. So you cannot perform operations via JCR API. The
console is mostly meant to perform low level debugging and
manipulation of data.

What are you trying to achieve? If you can use the std JCR API then
prefer that but then yes oak-run console cannot be used


Chetan Mehrotra


On Wed, Feb 11, 2015 at 3:25 PM, Andrei Dulvac <an...@gmail.com> wrote:
> Hi devs,
>
> I'm curious of the easiest way to copy a jcr node using the oak run  groovy
> console. I know that's easily achievable from the workspace by using the
> path and using the jcr Session:   session.getWorkspace().copy("/path/src",
> "/path/dst/");
> But from the oak run groovy console, all I have to start with is a
> org.apache.jackrabbit.oak.console.ConsoleSession. I can't seem to find a
> way to get the jcr workspace. Noob question 2: Should ConsoleSession
> implement Session?
>
> Thanks,
> Andrei