cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Lamb <al...@mac.com>
Subject Re: Behavior of "remove(object)" on ToManyList
Date Thu, 24 May 2007 11:27:03 GMT
Thanks a lot. It is indeed the correct way to handle the problem.

Alex
 
On Thursday, May 24, 2007, at 11:52AM, "Andrus Adamchik" <andrus@objectstyle.org> wrote:
>Hi Alex,
>
>Well, actually one of Cayenne responsibilities is maintaining  
>consistent object graph. To-many lists are a part of that object  
>graph. So if you want to remove an object from the list for  
>presentation reasons, but keep the relationship intact, the only  
>right way is to clone the list and remove items from the clone. I.e.:
>
>List centers = new ArrayList(getSelectedCountry().getCenters());
>
>Andrus
>
>
>On May 24, 2007, at 12:36 PM, Alexander Lamb wrote:
>
>> Thanks Andrus, however, I am not doing relationship management in  
>> that case.
>> Actually, I do NOT want to remove the center from the selected  
>> country.
>>
>> What I am doing is taking the centers and removing some items to  
>> present to the user the centers which are not already present in  
>> another relationship.
>>
>> In other words: "remove from the centers of the country the ones  
>> which are already used for a registry". Then present the list to  
>> the user so he can select a center he may want to add for a  
>> registry (or let him create a new center).
>>
>> So it is more like if I made a temporary copy of a list of objects  
>> to work with.
>>
>> And, yes, for consistency it would seem better to first fire a list  
>> fault before. But there was maybe some historical reason not to do  
>> it (I looked in the code and there is some testing of the status of  
>> the list and object that I didn't really understand).
>>
>> On Thursday, May 24, 2007, at 11:20AM, "Andrus Adamchik"  
>> <andrus@objectstyle.org> wrote:
>>> I suggest using "getSelectedCountry().removeFromCenters(..)" for
>>> consistent behavior. As for the remove, maybe we should fire a list
>>> fault for consistency, but this hasn't been a big deal as
>>> relationship management is better done via special methods.
>>>
>>> Andrus
>>>
>>>
>>> On May 24, 2007, at 10:54 AM, Alexander Lamb wrote:
>>>> Hello list,
>>>>
>>>> I am fetching a "List" of objects (a too many relationship).
>>>>
>>>> Then in a loop, I am removing some objects:
>>>>
>>>> 	  List<RegistryCenter> rcs = getRegistry().getRegistryCenters();
>>>> 	  List centers = getSelectedCountry().getCenters();
>>>> 	  for(RegistryCenter rc:rcs)
>>>> 	    {
>>>> 		centers.remove(rc.getCenter());
>>>> 	    }
>>>>
>>>>
>>>> Now, this doesn't always work. Actually, it fails if "centers" is a
>>>> fault (I checked in the Cayenne code).
>>>>
>>>> If I simply do a "size()" of "contains" on the list before my loop
>>>> for example. My list will fire and my loop will function correctly,
>>>> removing objects when present in the list.
>>>>
>>>> So there is a workaround, but I was wondering why the "remove
>>>> (object)" in  ToManyList.java behaved differently than for example
>>>> "remove(index)" which will correctly fire the fault.
>>>>
>>>> In other words, "remove(object)" is the only function which does
>>>> not systématically fire the fault.
>>>>
>>>> Why?
>>>>
>>>> Thanks,
>>>>
>>>> Alex
>>>>
>>>>
>>>
>>>
>>>
>>
>
>
>

Mime
View raw message