invoke List.contains with elements in memory vs in database
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > Apache Server configuration support > Apache JDO Project > invoke List.contains with elements in memory vs in database




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    invoke List.contains with elements in memory vs in database  


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-24-05 12:45 PM

I got a user question on the behavior of contains, but not sure whether
the current JPOX behavior is correct.

####################
I recently ran into a problem where calling org.jpox.sco.List.contains()
gave me different results under (what I thought were) the same runtime
conditions. After stepping through the code, I now understand why I am
getting different results. I illustrate the issue below.

Basically, I have a collection (List) of persistent objects. At some
point in my code, I want to determine if that collection already
contains a particular object based on equality (Object.equals()), so I
invoke contains():

if (myList.contains(anObject)) {


The interesting bit here is that anObject is not persistent. In fact,
it's not even enhanced. It is a POJO that happens to implement the same
interface used by the persistent objects stored in the collection.

Assume that there is indeed an object in the collection for which
objectInCollection.equals(anObject) is true. Thus, I would expect
List.contains() to return true, as well.

In the case where the above code does return true, I see that useCache
and isCacheLoaded are both true, so the delegate is used to implement
the method. Since this delegate is simply an ArrayList, I get the
behavior I expect.

When isCacheLoaded is not true, the method delegates to backingStore. As
part of the backingStore.contains() call, the method
org.jpox.store.rdbms.scostore.AbstractCollectionStore.validateElementFor
Reading() method is called (moved to ElementContainerStore in HEAD).
This method returns false if the element is not persistent AND not
detached. Since the parameter I originally passed is neither persistent
nor detached, contains() always returns false in this state.

Am I just asking for trouble by passing an object not of the PC type to
the contains() method of a persistent collection?

I worked around the issue by explicitly iterating over the elements of
the collection and invoking equals() on each one until I find a match.
This feels like a hack to me because I know in three months someone else
will come along and make the same mistake because they are thinking in
terms of java.util.List.contains(), not JDO.
####################

Thanks,

Erik Bengtson








[ Post a follow-up to this message ]



    Re: invoke List.contains with elements in memory vs in database  
Craig L Russell


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-28-05 07:45 AM






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:16 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register