cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Menard" <kmen...@servprise.com>
Subject RE: Duplicates in to-many relationships
Date Wed, 20 Jun 2007 12:13:32 GMT
 

> -----Original Message-----
> From: Alexander Lamb (dev) [mailto:alamb@mac.com] 
> Sent: Wednesday, June 20, 2007 3:24 AM
> To: user@cayenne.apache.org
> Subject: Re: Duplicates in to-many relationships
> 
> Well, although it works, I still have a small problem.
> 
> When you do a "setAnObject" even if it does "magically" 
> handle the "addTo", it does so without calling the public 
> "addToMyList" function.
> 
> This means I can't add some logic to the addTo function (I 
> need to perform some calculation each time a new object is 
> added to the list.
> 
> So either I find some sort of "objectWasAddedToRelationship" 
> delegate message, or I will need to trigger the calculation 
> also from the "setAnObject" side.


I think you'll find that overriding addToManyTarget() will take care of
most (all?) cases for you, rather than override the public methods on
each of your individual CDOs.  For example, I have:

public class EnhancedCayenneDataObject extends CayenneDataObject
{
    @Override
    public void addToManyTarget(final String relName, final DataObject
value, final boolean setReverse)
    {
        final List list = (List) readProperty(relName);
        
        if (false == list.contains(value))
        {
            super.addToManyTarget(relName, value, setReverse);
        }
    }
}


> To answer directly your question, I do need sometimes a 
> sorted list but I usually don't touch the to-many relation. I 
> simply create a new function which sorts the to-many list. In 
> order to boost performance, I do keep an ArrayList variable 
> which is calculated once and only reset when the to-many list 
> changes. Another reason to need to be able to access the 
> addToMyList when I can reset my calculated sorted list.

I wasn't talking about sorted, but rather ordered.  List provides
ordered semantics, while Set does not.  Set, however, does not allow
duplicates, while List does.  Both ordered and unique are desired
properties.  The DB will not allow duplicates and will provide an
ordering, so it'd be helpful if the data model matched that, IMO.

-- 
Kevin

Mime
View raw message