You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Daniele Dellafiore <il...@gmail.com> on 2008/01/24 21:58:55 UTC

referenceable like external key?

I have used jackrabbit for some time and now I want to clarify many
doubt about how to handle some problems and how to architect the
repository.

Basically I am today wondering about referencing a node from another
node. mix:referenceable seems to be useful but I do not understand,
other than assigning the UUID, how can be useful. The UUID can be use
as "external key" on another node?
Let's clarify. I am confused and I accept some advice about some books
becouse all the few articles on the net do not help me in architecting
even a simple (but not demo) application.

I begin the discussion here, anyway.

My app stores Pictures. I also have the concept of Author and Artwork.
Relationship are simple:
Author has many Artwork
Artwork has many Pictures.

In a relational, there are external keys. Here I can simply put all
the pictures in a path like

//picasso/guernica/pic1.jpg

then the node picasso will contain properties like date of birth and
death and so on, no need to have anything else.

Then I want to introduce some label, or tag, to give a free
classification to pictures, authors and artwork.
I can add a property to every node with a String that contains the
tag, in a comma separated format, for example.

Now, When I have to search all the pictures with a certain tag, I have
to make a query on that properties. I can also create a new hierarchy,
like

//tags/pictures/pic1.jpg

now, how can I connect that pic1.jpg, that is the node name, with the
actual node in the picasso/guernica/ tree?
I can write in  //tags/pictures/pic1.jpg node the UUID of the
//picasso/guernica/pic1.jpg node? this is external key. Is this a good
way? I do not think so...

Thanks.

-- 
Daniele Dellafiore
http://blog.ildella.net/

Re: referenceable like external key?

Posted by Daniele Dellafiore <il...@gmail.com>.
Thanks for help. Here is the complete code to get the reference node work:

      Node pictures = rootNode.addNode("pictures");
      Node leonardo = pictures.addNode("leonardo");
      leonardo.addMixin("mix:versionable");
      rootNode.save();

      Node classicTag = riootNode.addNode("tags").addNode("classic");
      Node leonardoTagged = classicTag.addNode("leonardo");
      leonardoTagged.setProperty("author_reference",
leonardo.getUUID(), PropertyType.REFERENCE);
      rootNode.save()

      assertEquals(leonardo,
leonardoTagged.getProperty("author_reference").getNode());

On Jan 25, 2008 12:13 AM, Brian Thompson <el...@gmail.com> wrote:
> On Jan 24, 2008 2:58 PM, Daniele Dellafiore <il...@gmail.com> wrote:
>
> > I have used jackrabbit for some time and now I want to clarify many
> > doubt about how to handle some problems and how to architect the
> > repository.
> >
> > Basically I am today wondering about referencing a node from another
> > node. mix:referenceable seems to be useful but I do not understand,
> > other than assigning the UUID, how can be useful. The UUID can be use
> > as "external key" on another node?
>
>
>
> mix:referenceable nodes can be set as properties of type Reference on other
> nodes.
>
>
>
>
> >
> > Let's clarify. I am confused and I accept some advice about some books
> > becouse all the few articles on the net do not help me in architecting
> > even a simple (but not demo) application.
> >
> > I begin the discussion here, anyway.
> >
> > My app stores Pictures. I also have the concept of Author and Artwork.
> > Relationship are simple:
> > Author has many Artwork
> > Artwork has many Pictures.
> >
> > In a relational, there are external keys. Here I can simply put all
> > the pictures in a path like
> >
> > //picasso/guernica/pic1.jpg
> >
> > then the node picasso will contain properties like date of birth and
> > death and so on, no need to have anything else.
> >
> > Then I want to introduce some label, or tag, to give a free
> > classification to pictures, authors and artwork.
> > I can add a property to every node with a String that contains the
> > tag, in a comma separated format, for example.
> >
> > Now, When I have to search all the pictures with a certain tag, I have
> > to make a query on that properties. I can also create a new hierarchy,
> > like
> >
> > //tags/pictures/pic1.jpg
> >
> > now, how can I connect that pic1.jpg, that is the node name, with the
> > actual node in the picasso/guernica/ tree?
> > I can write in  //tags/pictures/pic1.jpg node the UUID of the
> > //picasso/guernica/pic1.jpg node? this is external key. Is this a good
> > way? I do not think so...
>
>
>
> pic1.jpg here would be a very simple node, containing only one property (of
> type Reference) whose value would be the UUID of pic1.jpg under the
> picasso/guernica/ tree.  To use this, you'd do something like:
>
> Node fakePic = root.getNode("//tags/pictures/pic1.jpg");
> Node realPic = fakePic.getProperty("imgReference").getNode();
>
> and then realPic would be the node from the /picasso/guernica/ tree.
>
>
>
> >
> >
> > Thanks.
> >
> > --
> > Daniele Dellafiore
> > http://blog.ildella.net/
> >
>
>
> Hope this helps,
>
> -Brian
>



-- 
Daniele Dellafiore
http://blog.ildella.net/

Re: referenceable like external key?

Posted by Brian Thompson <el...@gmail.com>.
On Jan 24, 2008 2:58 PM, Daniele Dellafiore <il...@gmail.com> wrote:

> I have used jackrabbit for some time and now I want to clarify many
> doubt about how to handle some problems and how to architect the
> repository.
>
> Basically I am today wondering about referencing a node from another
> node. mix:referenceable seems to be useful but I do not understand,
> other than assigning the UUID, how can be useful. The UUID can be use
> as "external key" on another node?



mix:referenceable nodes can be set as properties of type Reference on other
nodes.



>
> Let's clarify. I am confused and I accept some advice about some books
> becouse all the few articles on the net do not help me in architecting
> even a simple (but not demo) application.
>
> I begin the discussion here, anyway.
>
> My app stores Pictures. I also have the concept of Author and Artwork.
> Relationship are simple:
> Author has many Artwork
> Artwork has many Pictures.
>
> In a relational, there are external keys. Here I can simply put all
> the pictures in a path like
>
> //picasso/guernica/pic1.jpg
>
> then the node picasso will contain properties like date of birth and
> death and so on, no need to have anything else.
>
> Then I want to introduce some label, or tag, to give a free
> classification to pictures, authors and artwork.
> I can add a property to every node with a String that contains the
> tag, in a comma separated format, for example.
>
> Now, When I have to search all the pictures with a certain tag, I have
> to make a query on that properties. I can also create a new hierarchy,
> like
>
> //tags/pictures/pic1.jpg
>
> now, how can I connect that pic1.jpg, that is the node name, with the
> actual node in the picasso/guernica/ tree?
> I can write in  //tags/pictures/pic1.jpg node the UUID of the
> //picasso/guernica/pic1.jpg node? this is external key. Is this a good
> way? I do not think so...



pic1.jpg here would be a very simple node, containing only one property (of
type Reference) whose value would be the UUID of pic1.jpg under the
picasso/guernica/ tree.  To use this, you'd do something like:

Node fakePic = root.getNode("//tags/pictures/pic1.jpg");
Node realPic = fakePic.getProperty("imgReference").getNode();

and then realPic would be the node from the /picasso/guernica/ tree.



>
>
> Thanks.
>
> --
> Daniele Dellafiore
> http://blog.ildella.net/
>


Hope this helps,

-Brian