On 10/5/07, Kaizer <[EMAIL PROTECTED]> wrote:
>
>
> Thanks a lot! I had a look at the test cases and that helped! But i had a
> few
> general queries..
> 1. What are the advantages of using referencing here? One can still
> persist
> "anotherContent" by specifying its attributes in the mapping.xml, so when
> should i consider using referencing?
If you specify "anotherContent" as a bean-descriptor in the main object (in
our case "MyContent"), by default, that means it is a subnode of
"MyContent". there are some situation where you want to point to another
node (which is not a subnode).
Maybe a good exemple is : one article has a list of related articles. here
is the repo structure(with very bad name).
/articles/article1
UUID : 123455
text: "....."
....
/articles/article2
UUID : 6987787
text: "....."
/articles/article3
UUID : 9966565
text: "....."
RelatedArticles : 123455, 6987787
/articles/article4
UUID : 66655656
text: "....."
/articles/article5
UUID : 12890
text: "....."
RelatedArticles : 66655656
In this case, when I update my article, this is not necessary to update the
related article contents. I can only modify the list of the related
articles. In such case, you can use multi value property based on the
REFERENCE type (RelatedArticles). The OCM converter
"RefenceCollectionConverterImpl" is doing this for you.
But there are some alternatives to referencable nodes :-) (see
http://wiki.apache.org/jackrabbit/DavidsModel#head-ed794ec9f4f716b3e53548be6dd91b23e5dd3f3a
).
We should provide some converters to support this kind of proposal. I Think
is should be possible to build a variant of ReferenceCollectionConverterImpl
(and ReferenceBeanConverterImpl) that provide the flexibility defined in
the David's Rule 5.
2. As per the documentation of ReferenceBeanConverterImpl, modifications on
> the referenced bean attributes are ignored. Does this mean that after
> persisting, if "anotherContent" is modified, the reference in "myContent"
> will not reflect the changes?
No with the following code, that's ok :
AnotherContent anotherContent = new AnotherContent();
anotherContent.setMyProp("pop1");
anotherContent.setPath("/anotherContent);
ocm.insert(anotherContent);
ocm.save();
....
MyContent myContent = new MyContent();
myContent.setPath("/mycontent");
myContent.setAnotherContent(anotherContent)
...
ocm.insert(myContent);
ocm.save(); // another content will not be a subnode of mycontent. Only its
uuid is stored as REFERENCE prop inside myContent
MyContent myContent = ocm.getObject("/myContent);
anotherContent = myContent.getAnotherContent();
String prop = anotherContent.getMyProp(); // if proxy = true, the retrieve
of anotherContent is made at that time.
myContent.getAnotherContent()..setMyProp("pop1"); // This update will be
ignored by the ocm
AnotherContent = ocm.getObject("/anotherContent);
anotherContent.setMyProp("pop2");
ocm.update(anotherContent);
ocm.save();
Let me know if it is not clear (sorry it is friday :-) )
br,
Christophe