Newbie: PropertyType.REFERENCE

9 messages Options
Embed this post
Permalink
BOWLER Paul

Newbie: PropertyType.REFERENCE

Reply Threaded More More options
Print post
Permalink
Can anyone demonstrate (in code) how to set one Node to point to another
Node using node.setProperty(xxx, xxx, PropertyType.REFERENCE).

I can't find any examples anywhere on how to do this!

Thanks,

Paul.

P.S. Is there a good JCR book available that I can read?
Daniel Manzke

Re: Newbie: PropertyType.REFERENCE

Reply Threaded More More options
Print post
Permalink
Hi Paul,
here is a snippet.

Node rootNode = session.getRootNode();
Node record = rootNode.getNode(recordPath); //retrieves a node for an
electronical record
Node document = rootNode.getNode(documentPath); //retrieves a node for an
document in another record
*Value value = session.getValueFactory().createValue(document); //creates
the reference value*
*record.setProperty("forge:Referenzen", new Value[]{value}); //setting the
reference property*
session.save();


I don't know if this is the best way. If I remember right, I took the way
out of the TCK-Tests. ;)


Greets,
Daniel

2009/7/1 BOWLER Paul <[hidden email]>

> Can anyone demonstrate (in code) how to set one Node to point to another
> Node using node.setProperty(xxx, xxx, PropertyType.REFERENCE).
>
> I can't find any examples anywhere on how to do this!
>
> Thanks,
>
> Paul.
>
> P.S. Is there a good JCR book available that I can read?
>



--
Mit freundlichen Grüßen

Daniel Manzke
BOWLER Paul

RE: Newbie: PropertyType.REFERENCE

Reply Threaded More More options
Print post
Permalink
Daniel,

Thanks for the reply, but I don't see how this uses the REFERENCE property to point to another node?

Can anyone else enlighten me?

Thanks,

Paul.

-----Original Message-----
From: Daniel Manzke [mailto:[hidden email]]
Sent: 01 July 2009 16:57
To: [hidden email]
Subject: Re: Newbie: PropertyType.REFERENCE

Hi Paul,
here is a snippet.

Node rootNode = session.getRootNode();
Node record = rootNode.getNode(recordPath); //retrieves a node for an
electronical record
Node document = rootNode.getNode(documentPath); //retrieves a node for an
document in another record
*Value value = session.getValueFactory().createValue(document); //creates
the reference value*
*record.setProperty("forge:Referenzen", new Value[]{value}); //setting the
reference property*
session.save();


I don't know if this is the best way. If I remember right, I took the way
out of the TCK-Tests. ;)


Greets,
Daniel

2009/7/1 BOWLER Paul <[hidden email]>

> Can anyone demonstrate (in code) how to set one Node to point to another
> Node using node.setProperty(xxx, xxx, PropertyType.REFERENCE).
>
> I can't find any examples anywhere on how to do this!
>
> Thanks,
>
> Paul.
>
> P.S. Is there a good JCR book available that I can read?
>



--
Mit freundlichen Grüßen

Daniel Manzke
Daniel Manzke

Re: Newbie: PropertyType.REFERENCE

Reply Threaded More More options
Print post
Permalink
Hi Paul,
every node, which is referenceable has a UUID. This ID is used for
references. The created value (by the ValueFactory) should be a String. This
String contains the UUID.

In my example the record node has a property "forge:reference". There you
can place the references.

<propertyDefinition name="forge:Reference" requiredType="Reference"
autoCreated="false" mandatory="false" onParentVersion="COPY"
protected="false" multiple="true"/>

My document node is referenceable. So it has an unique ID.
<supertype>mix:referenceable</supertype>


So take the node which should hold the refernce (in my example the record)
and take the node which you want to reference to and create a Reference
Value with the help of the ValueFactory.

This value has to be set for the "forge:Reference" property.


Enough?! :)


Daniel

2009/7/1 BOWLER Paul <[hidden email]>

> Daniel,
>
> Thanks for the reply, but I don't see how this uses the REFERENCE property
> to point to another node?
>
> Can anyone else enlighten me?
>
> Thanks,
>
> Paul.
>
> -----Original Message-----
> From: Daniel Manzke [mailto:[hidden email]]
> Sent: 01 July 2009 16:57
> To: [hidden email]
> Subject: Re: Newbie: PropertyType.REFERENCE
>
> Hi Paul,
> here is a snippet.
>
> Node rootNode = session.getRootNode();
> Node record = rootNode.getNode(recordPath); //retrieves a node for an
> electronical record
> Node document = rootNode.getNode(documentPath); //retrieves a node for an
> document in another record
> *Value value = session.getValueFactory().createValue(document); //creates
> the reference value*
> *record.setProperty("forge:Referenzen", new Value[]{value}); //setting the
> reference property*
> session.save();
>
>
> I don't know if this is the best way. If I remember right, I took the way
> out of the TCK-Tests. ;)
>
>
> Greets,
> Daniel
>
> 2009/7/1 BOWLER Paul <[hidden email]>
>
> > Can anyone demonstrate (in code) how to set one Node to point to another
> > Node using node.setProperty(xxx, xxx, PropertyType.REFERENCE).
> >
> > I can't find any examples anywhere on how to do this!
> >
> > Thanks,
> >
> > Paul.
> >
> > P.S. Is there a good JCR book available that I can read?
> >
>
>
>
> --
> Mit freundlichen Grüßen
>
> Daniel Manzke
>



--
Mit freundlichen Grüßen

Daniel Manzke
Alexander Klimetschek

Re: Newbie: PropertyType.REFERENCE

Reply Threaded More More options
Print post
Permalink
In reply to this post by BOWLER Paul
On Wed, Jul 1, 2009 at 3:23 PM, BOWLER
Paul<[hidden email]> wrote:
> Can anyone demonstrate (in code) how to set one Node to point to another
> Node using node.setProperty(xxx, xxx, PropertyType.REFERENCE).

Node.setProperty(String, Node)

This will make this property point to the node passed as second argument.

See the javadocs:
http://www.day.com/maven/jsr170/javadocs/jcr-1.0/javax/jcr/Node.html#setProperty(java.lang.String,%20javax.jcr.Node)

Regards,
Alex

--
Alexander Klimetschek
[hidden email]
BOWLER Paul

RE: Newbie: PropertyType.REFERENCE

Reply Threaded More More options
Print post
Permalink
In reply to this post by Daniel Manzke
Sorry, but I still don't get it!

I can create a node that is referencable by adding the mix:referenceable attribute. That much is clear.

How can I now create another node elsewhere in my tree that references this node? The documentation is not clear on this.

Thanks,

Paul.

-----Original Message-----
From: Daniel Manzke [mailto:[hidden email]]
Sent: 01 July 2009 17:55
To: [hidden email]
Subject: Re: Newbie: PropertyType.REFERENCE

Hi Paul,
every node, which is referenceable has a UUID. This ID is used for
references. The created value (by the ValueFactory) should be a String. This
String contains the UUID.

In my example the record node has a property "forge:reference". There you
can place the references.

<propertyDefinition name="forge:Reference" requiredType="Reference"
autoCreated="false" mandatory="false" onParentVersion="COPY"
protected="false" multiple="true"/>

My document node is referenceable. So it has an unique ID.
<supertype>mix:referenceable</supertype>


So take the node which should hold the refernce (in my example the record)
and take the node which you want to reference to and create a Reference
Value with the help of the ValueFactory.

This value has to be set for the "forge:Reference" property.


Enough?! :)


Daniel

2009/7/1 BOWLER Paul <[hidden email]>

> Daniel,
>
> Thanks for the reply, but I don't see how this uses the REFERENCE property
> to point to another node?
>
> Can anyone else enlighten me?
>
> Thanks,
>
> Paul.
>
> -----Original Message-----
> From: Daniel Manzke [mailto:[hidden email]]
> Sent: 01 July 2009 16:57
> To: [hidden email]
> Subject: Re: Newbie: PropertyType.REFERENCE
>
> Hi Paul,
> here is a snippet.
>
> Node rootNode = session.getRootNode();
> Node record = rootNode.getNode(recordPath); //retrieves a node for an
> electronical record
> Node document = rootNode.getNode(documentPath); //retrieves a node for an
> document in another record
> *Value value = session.getValueFactory().createValue(document); //creates
> the reference value*
> *record.setProperty("forge:Referenzen", new Value[]{value}); //setting the
> reference property*
> session.save();
>
>
> I don't know if this is the best way. If I remember right, I took the way
> out of the TCK-Tests. ;)
>
>
> Greets,
> Daniel
>
> 2009/7/1 BOWLER Paul <[hidden email]>
>
> > Can anyone demonstrate (in code) how to set one Node to point to another
> > Node using node.setProperty(xxx, xxx, PropertyType.REFERENCE).
> >
> > I can't find any examples anywhere on how to do this!
> >
> > Thanks,
> >
> > Paul.
> >
> > P.S. Is there a good JCR book available that I can read?
> >
>
>
>
> --
> Mit freundlichen Grüßen
>
> Daniel Manzke
>



--
Mit freundlichen Grüßen

Daniel Manzke
BOWLER Paul

RE: Newbie: PropertyType.REFERENCE

Reply Threaded More More options
Print post
Permalink
In reply to this post by Alexander Klimetschek
Thank Alex, I'll give this a go.

Paul.

-----Original Message-----
From: Alexander Klimetschek [mailto:[hidden email]]
Sent: 01 July 2009 20:29
To: [hidden email]
Subject: Re: Newbie: PropertyType.REFERENCE

On Wed, Jul 1, 2009 at 3:23 PM, BOWLER
Paul<[hidden email]> wrote:
> Can anyone demonstrate (in code) how to set one Node to point to
another
> Node using node.setProperty(xxx, xxx, PropertyType.REFERENCE).

Node.setProperty(String, Node)

This will make this property point to the node passed as second
argument.

See the javadocs:
http://www.day.com/maven/jsr170/javadocs/jcr-1.0/javax/jcr/Node.html#set
Property(java.lang.String,%20javax.jcr.Node)

Regards,
Alex

--
Alexander Klimetschek
[hidden email]
Alexander Klimetschek

Re: Newbie: PropertyType.REFERENCE

Reply Threaded More More options
Print post
Permalink
In reply to this post by BOWLER Paul
On Thu, Jul 2, 2009 at 10:26 AM, BOWLER
Paul<[hidden email]> wrote:
> How can I now create another node elsewhere in my tree that references this node? The documentation is not clear on this.

The JCR 1.0 spec talks about REFERENCE properties in section 4.7.2 [1]
and clearly points to the Node.setProperty(String, Node) method. The
(standard) methods for setting properties are all named setProperty(),
just with different arguments. The javadoc of that method says: "Sets
the specified (REFERENCE)property to refer to the specified Node."

What is that not clear about that?

[1] http://www.day.com/specs/jcr/1.0/4.7.2_Reference,_Path_and_Name_Property_Types.html

Regards,
Alex

--
Alexander Klimetschek
[hidden email]
BOWLER Paul

RE: Newbie: PropertyType.REFERENCE

Reply Threaded More More options
Print post
Permalink
Clearly I am just really stupid then.

P.

-----Original Message-----
From: Alexander Klimetschek [mailto:[hidden email]]
Sent: 02 July 2009 14:02
To: [hidden email]
Subject: Re: Newbie: PropertyType.REFERENCE

On Thu, Jul 2, 2009 at 10:26 AM, BOWLER
Paul<[hidden email]> wrote:
> How can I now create another node elsewhere in my tree that references
this node? The documentation is not clear on this.

The JCR 1.0 spec talks about REFERENCE properties in section 4.7.2 [1]
and clearly points to the Node.setProperty(String, Node) method. The
(standard) methods for setting properties are all named setProperty(),
just with different arguments. The javadoc of that method says: "Sets
the specified (REFERENCE)property to refer to the specified Node."

What is that not clear about that?

[1]
http://www.day.com/specs/jcr/1.0/4.7.2_Reference,_Path_and_Name_Property
_Types.html

Regards,
Alex

--
Alexander Klimetschek
[hidden email]