You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "kazim_ssuet@yahoo.com" <ka...@yahoo.com> on 2011/02/10 19:18:55 UTC

copying content from one resource node to another

Hi,

We have a scenario that requires copying documents from one entity to
another.
I understand that by setting the "DataStore" in configuration you can have
only one copy of the document pointed by multiple resource nodes.

But I would like to avoid reading data from one resource node and setting it
to a new one since this requires extra time and memory. Is there a way that
I can set the content hash of the existing document on new resource node and
not read contents while copying?

Basically I would like to avoid this peice of code:

Property contentProperty = fromNode.getProperty(JcrConstants.JCR_DATA);
Binary contentBinary = contentProperty.getBinary();
byte content[]=new byte[(int)contentBinary.getSize()];
contentBinary.getStream().read(content);

Instead I would like to somehow get pointer to existing content and set it
to new resource node, Since there might be 100s of document being transfered
from one entity to another, which would be costly in terms of time and
memory to do it this way.

Second question, if I use references (not recommended according to David's
model http://wiki.apache.org/jackrabbit/DavidsModel) does removing original
node make the references invalid? or you can't remove original node if
references to that node exist?

Thanks
KS.

-- 
View this message in context: http://jackrabbit.510166.n4.nabble.com/copying-content-from-one-resource-node-to-another-tp3299707p3299707.html
Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.

Re: copying content from one resource node to another

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 11.02.11 19:41, "kazim_ssuet@yahoo.com" <ka...@yahoo.com> wrote:
>Jukka Zitting-6 wrote:
>> 
>> No, with the data store it shouldn't. It's a bug if it does.
>> 
>
>so Binary object is basically a handle to the data.

Yes, and AFAIK that's the reason why it was introduced in JCR 2.0 afaik.
In JCR 1.0 you could only get or set an InputStream for binary properties,
which - even if data hasn't been read yet - already points to some open
I/O operation. With Binary you have a more general reference to the binary
object, that can be used independently from the underlying implementation.

Regards,
Alex

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





Re: copying content from one resource node to another

Posted by "kazim_ssuet@yahoo.com" <ka...@yahoo.com>.

Jukka Zitting-6 wrote:
> 
> No, with the data store it shouldn't. It's a bug if it does.
> 

so Binary object is basically a handle to the data.

-- 
View this message in context: http://jackrabbit.510166.n4.nabble.com/copying-content-from-one-resource-node-to-another-tp3299707p3301767.html
Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.

Re: copying content from one resource node to another

Posted by Jukka Zitting <jz...@adobe.com>.
Hi,

On 02/11/2011 06:41 PM, kazim_ssuet@yahoo.com wrote:
> I suppose contentProperty.getBinary() will also read whole contents,
> right?

No, with the data store it shouldn't. It's a bug if it does.

-- 
Jukka Zitting

Re: copying content from one resource node to another

Posted by "kazim_ssuet@yahoo.com" <ka...@yahoo.com>.

Alexander Klimetschek-2 wrote:
> 
> Why don't you simply use setProperty("jcr:data", binary)?
> 

I suppose contentProperty.getBinary() will also read whole contents, right?
So only option I am left with is to use REFERENCE?

-- 
View this message in context: http://jackrabbit.510166.n4.nabble.com/copying-content-from-one-resource-node-to-another-tp3299707p3301682.html
Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.

Re: copying content from one resource node to another

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 10.02.11 19:18, "kazim_ssuet@yahoo.com" <ka...@yahoo.com> wrote:
>But I would like to avoid reading data from one resource node and setting
>it
>to a new one since this requires extra time and memory. Is there a way
>that
>I can set the content hash of the existing document on new resource node
>and
>not read contents while copying?

Do you mean copying from one node to another inside the repository? For
that you can use Workspace.copy:

http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Workspace.html#c
opy(java.lang.String,%20java.lang.String)

>Basically I would like to avoid this peice of code:
>
>Property contentProperty = fromNode.getProperty(JcrConstants.JCR_DATA);
>Binary contentBinary = contentProperty.getBinary();
>byte content[]=new byte[(int)contentBinary.getSize()];
>contentBinary.getStream().read(content);
>
>Instead I would like to somehow get pointer to existing content and set it
>to new resource node, Since there might be 100s of document being
>transfered
>from one entity to another, which would be costly in terms of time and
>memory to do it this way.

Why don't you simply use setProperty("jcr:data", binary)?

http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#setPro
perty(java.lang.String,%20javax.jcr.Binary)

>or you can't remove original node if references to that node exist?

Exactly. REFERENCE properties are hard-references, always enforced.

Regards,
Alex

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