jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jukka Zitting" <jukka.zitt...@gmail.com>
Subject Re: Should I use property type: reference or string?
Date Thu, 22 Mar 2007 10:05:05 GMT
Hi,

On 3/22/07, alartin <alartin@gmail.com> wrote:
> Briefly speaking, I have a "question" object, it has a reference(Java
> concept) of a "user" object and a reference of a list of "answer" objects.
> On the other hand, "user" object also has a reference of a list of
> "question" objects and a reference of  a list of "answer" objects: "user" 1
> <--> * "question", "user" 1 <--> * "answer".
> My questions are:
>
> 1. The reference type of property is only for integrity constraint, it is
> much more like primary/foreign key in RDBMS rather than the reference
> concept in Java(OO)?

JCR reference properties are for linking together related nodes in
different parts of the content tree, much like foreign keys link
together otherwise unrelated rows in a relational database. They also
have some Java reference capabilities, for example that you can easily
 and efficiently follow the link for example with Property.getNode().

In general I would use the basic tree structure in JCR for composition
structures, and references for aggregates and other associations. In
your case it seems like the user-question and user-answer
relationships are aggregates rather than compositions.

> 2. If above is true, should I only use reference type of property when I
> need to maintain the integrity, for example: when I delete a user, all his
> questions and answers must be deleted too. Thus, a user node should be
> referenceable and it is the target of a question node's "author" property
> with reference type

JCR maintains referential integrity for reference properties but only
supports cascading deletes on the tree hierarchy. You will receive an
exception if you try to delete a node that still has references
pointing to it.

> 3. If I do not need that, I should use a string type instead of reference
> type: a question node's "author" property is string type and the value is a
> "user"'s name (suppose it is unique)

In your case I would think using a reference property would be more
appropriate. It allows you to easily manage more author metadata and
also gives you some quite efficient reference traversal options, see
below.

> 4. If a node need to maintain a list of reference targets, I can use
> multiple-value property to store the list of targets, but how can I add one
> target dynamically? (I only find setProperty(String name, String[] values)
> method in NodeImp class, no add method), for example what can I do if a user
> node's "answers" property(multi-value and maintains targets) needs to add a
> target(one answer's uuid)?

There is no way to incrementally modify a multi-valued property; you
need to always set the entire value array. In your case I'd actually
rather put the reference on the answer nodes, and use
Node.getReferences() to get all the answers of a user. Jackrabbit
supports very fast backreferencing.

To summarize, I would go for a content model like this:

    [my:user] > mix:referenceable

    [my:question]
    - my:author (REFERENCE) mandatory < my:user
    + * (my:answer)

    [my:answer]
    - my:author (REFERENCE) mandatory < my:user

BR,

Jukka Zitting

Mime
View raw message