You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Øyvind Harboe <oy...@zylin.com> on 2008/06/20 10:34:40 UTC

Comparing objects

I'm wondering if I've gotten comparsion of objects right.

Consider a, b both references to CayenneDataObjects.

I want to know if a & b refer to the same row in a database.


1. if (a==b)

safe as long as a & b are in the same DataContext.
a & b can be garbage collected during the lifetime
of DataContext, but the above is still guaranteed to
work.

2. if (a.getObjectId().equals(b.getObject()))

safe regardless of which DataContext the objects
are in.

3. if (a.getObjectId()==b.getObject())

same as 2, except that it is faster.


If any of the above assumptions are false, then I need to
go into the application and fix it.

-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 XScale Cortex
JTAG debugger and flash programmer

Re: Comparing objects

Posted by Øyvind Harboe <oy...@zylin.com>.
On Fri, Jun 20, 2008 at 10:38 AM, Andrus Adamchik
<an...@objectstyle.org> wrote:
> #3 is false. ObjectId *instances* are not unique, and require "equals"
> comparison.

I don't actually think the application walked into this tripwire, but I thought
I'd cover it in my list above.

> #1 & #2 are accurate.

Great!

Thanks!


-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 XScale Cortex
JTAG debugger and flash programmer

Re: Comparing objects

Posted by Andrus Adamchik <an...@objectstyle.org>.
#3 is false. ObjectId *instances* are not unique, and require "equals"  
comparison.

#1 & #2 are accurate.

Andrus


On Jun 20, 2008, at 11:34 AM, Øyvind Harboe wrote:

> I'm wondering if I've gotten comparsion of objects right.
>
> Consider a, b both references to CayenneDataObjects.
>
> I want to know if a & b refer to the same row in a database.
>
>
> 1. if (a==b)
>
> safe as long as a & b are in the same DataContext.
> a & b can be garbage collected during the lifetime
> of DataContext, but the above is still guaranteed to
> work.
>
> 2. if (a.getObjectId().equals(b.getObject()))
>
> safe regardless of which DataContext the objects
> are in.
>
> 3. if (a.getObjectId()==b.getObject())
>
> same as 2, except that it is faster.
>
>
> If any of the above assumptions are false, then I need to
> go into the application and fix it.
>
> -- 
> Øyvind Harboe
> http://www.zylin.com/zy1000.html
> ARM7 ARM9 XScale Cortex
> JTAG debugger and flash programmer
>