Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » two instance but same identity : problem with Map.contains
two instance but same identity : problem with Map.contains [message #757461] Fri, 18 November 2011 14:26 Go to next message
jonathan Missing name is currently offline jonathan Missing nameFriend
Messages: 12
Registered: August 2010
Junior Member
Hi all,

i have 2 models A and B; A contain one object called "o" for example and B refers this object.
When i load model A then model B, i have in memory two instances of the same object "o" (ie identity); This two instances can be called "o1" and "o2".

The problem is the following :
If i put "o1" in a list and i call list.contains(o2), it return false (normal, it is 2 different instances). But for me, "o1" and "o2" have the same identity so i would like the list returns true.

How can i resolve this? can i overload equals methods? or there a special list which take account the "identity" of emf objects?

Thanks in advance.

[Updated on: Fri, 18 November 2011 14:42]

Report message to a moderator

Re: two instance but same identity : problem with Map.contains [message #757974 is a reply to message #757461] Fri, 18 November 2011 17:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Jonathan,

Comments below.

On 18/11/2011 3:26 PM, jonathan wrote:
> Hi all,
>
> i have 2 models A and B; A contain one object called "o" for example
> and B refers this object. When i load model A then model B, i have in
> memory two instances of the same object "o" (ie identity);
Why?
> This two instances can be called "o1" and "o2".
>
> The problem is the following :
> If i put "o1" in a list and i call list.contains(o2), it return false
> (normal, it is 2 different instances). But for me, "o1" and "o2" have
> the same identity so i would like the list returns true.
No.
>
> How can i resolve this?
Don't load two different instances.
> can i overhead equals methods?
No.
> or there a special list which take account the "identity" of emf objects?
No.
>
> Thanks in advance.
If you load then using a single resource set you should end up with only
one instance, not two.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: two instance but same identity : problem with Map.contains [message #758154 is a reply to message #757974] Tue, 22 November 2011 07:47 Go to previous messageGo to next message
jonathan Missing name is currently offline jonathan Missing nameFriend
Messages: 12
Registered: August 2010
Junior Member
Hello Ed,

I will test your method by sharing only one resource set for all parts of my program.
For the moment, i found a workaround by using EcoreUtil.getURI. Even if i have two instances, the URI of the both are the same.
Re: two instance but same identity : problem with Map.contains [message #760226 is a reply to message #758154] Thu, 01 December 2011 16:10 Go to previous messageGo to next message
jonathan Missing name is currently offline jonathan Missing nameFriend
Messages: 12
Registered: August 2010
Junior Member
Hello,

I tried your method in an other situation but without success :

I have one Model with two objects and a bi directional relation between both.
objects. And i succeed to split an instance of this model in two resources like following :

file 1 : object A href="file 2#//object B"
file 2 : object B href="file 1#//object A"

However, when i try to load this two resources even i use the same resource set, i obtain duplicate object in memory : object B referenced by A when i load file 1 is not the same that object B when i load file 2.

I don't know why.

[Updated on: Thu, 01 December 2011 17:01]

Report message to a moderator

Re: two instance but same identity : problem with Map.contains [message #760334 is a reply to message #760226] Thu, 01 December 2011 22:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Jonathan,

How many resources do you end up with in your resource set?


On 01/12/2011 5:11 PM, jonathan wrote:
> Hello,
>
> I tried your method in an other situation but without success :
>
> I have one Model with two objects and a bi directional relation
> between both.
> objects. And i succeed to split an instance of this model in two
> resources like following :
>
> file 1 : object A href="file 2#//object B"
> file 2 : object B href="file 1#//object A"
>
> However, when i try to load this two resources even i use the same
> resource set, i obtain duplicate object in memory : object B
> referenced by A when i load file 1 is not the same that object B when
> i load file 2.
> I don't know why?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: two instance but same identity : problem with Map.contains [message #760367 is a reply to message #760334] Fri, 02 December 2011 07:58 Go to previous messageGo to next message
jonathan Missing name is currently offline jonathan Missing nameFriend
Messages: 12
Registered: August 2010
Junior Member
Ed,

the number of resource evolve like following
_ I create a resource set "rs"
_ I get the resource associated with file 1 with rs.getResource(<file1>, true)
_ EMF create the resource with contents but when i check resources contain in resource set, there is still one. At this point, i have an object B in memory but with attribute no complete when i look in content of resource.
_ I get the resource associated with file 2 with rs.getResource(<file2>, true)
_ EMF create the resource with contents and now, there are both resources. However, I obtain an new object B in memory with correct attribute but it is not the same instance than before. Of course, i have the same difference with both object B.
Re: two instance but same identity : problem with Map.contains [message #760369 is a reply to message #760367] Fri, 02 December 2011 08:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Jonathan,

Comments below.

On 02/12/2011 8:58 AM, jonathan wrote:
> Ed,
>
> the number of resource evolve like following
> _ I create a resource set "rs"
> _ I get the resource associated with file 1 with
> rs.getResource(<file1>, true)
> _ EMF create the resource with contents but when i check resources
> contain in resource set, there is still one. At this point, i have an
> object B in memory but with attribute no complete when i look in
> content of resource.
Is eIsProxy true for B? If it's true, you can cast it to
InternalEObject and check the value of eProxyURI. What value is that?
If it's false, what's the value of B.eResource().getURI()?
> _ I get the resource associated with file 2 with
> rs.getResource(<file2>, true)
You're sure there are only two resource in the resource set at this point?
> _ EMF create the resource with contents and now, there are both
> resources. However, I obtain an new object B in memory with correct
> attribute but it is not the same instance than before. Of course, i
> have the same difference with both object B.
There must be some reason that the reference of A to B is an unresolved
proxy. But it's almost impossible to imagine that you won't have three
resources in the resource set because calling A.getB() will attempt to
resolve the proxy and that inevitably will lead to a resource being
added to the resource set. So I imagine there are three resources.

In your follow up question, be sure to specify exactly the value of
EcoreUtil.getURI of the two different instances of B.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: two instance but same identity : problem with Map.contains [message #760386 is a reply to message #760369] Fri, 02 December 2011 09:08 Go to previous messageGo to next message
jonathan Missing name is currently offline jonathan Missing nameFriend
Messages: 12
Registered: August 2010
Junior Member
Ed,

i forgot to tell you something : i check memory using debugger of eclipse. And until now, i have not used A.getB() in my code. I understand what happened. After calling A.getB(), EMF lazy load object B correctly in memory by resolving the proxy while before call, debugger display a "stub" of object B.

However, when i use only A.setB(null), there no proxy resolution before set B to null expect if i call A.getB() to force proxy resolution before call A.setB(null).

is there an better elegant method to force the proxy resolution at the beginning than call getB() before setB()?

Re: two instance but same identity : problem with Map.contains [message #760389 is a reply to message #760386] Fri, 02 December 2011 09:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Jonathan,

I'm not sure why you'd need to resolve a proxy before assigning null,
but EcoreUtil.resolveAll can be used to force all proxies to resolve.


On 02/12/2011 10:08 AM, jonathan wrote:
> Ed,
> i forgot to tell you something : i check memory using debugger of
> eclipse. And until now, i have not used A.getB() in my code. I
> understand what happened. After calling A.getB(), EMF lazy load object
> B correctly in memory by resolving the proxy while before call,
> debugger display a "stub" of object B.
>
> However, when i use only A.setB(null), there no proxy resolution
> before set B to null expect if i call A.getB() to force proxy
> resolution before call A.setB(null).
>
> is there an better elegant method to force the proxy resolution at the
> beginning than call getB() before setB()?
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: two instance but same identity : problem with Map.contains [message #760395 is a reply to message #760389] Fri, 02 December 2011 09:46 Go to previous messageGo to next message
jonathan Missing name is currently offline jonathan Missing nameFriend
Messages: 12
Registered: August 2010
Junior Member
Ed,

I want to resolve the proxy, before calling A.setB(null) because If I don't force this proxy resolution before assigning with A.setB(null), then the return of B.getA() would not be null, would it?
Re: two instance but same identity : problem with Map.contains [message #760399 is a reply to message #760395] Fri, 02 December 2011 09:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Jonathan,

Oh, of course. I hadn't stop to think there was a bidirectional
reference involved. I suppose it's kind of unusual to blindly set it to
null... You'd be doing that even it if was null already?


On 02/12/2011 10:46 AM, jonathan wrote:
> Ed,
>
> I want to resolve the proxy, before calling A.setB(null) because If I
> don't force this proxy resolution before assigning with A.setB(null),
> then the return of B.getA() would not be null, would it?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: two instance but same identity : problem with Map.contains [message #760414 is a reply to message #760399] Fri, 02 December 2011 10:20 Go to previous messageGo to next message
jonathan Missing name is currently offline jonathan Missing nameFriend
Messages: 12
Registered: August 2010
Junior Member
Ed,

until now, i have not token habit to control the value of attribute (or reference here) before to assign it. But i suppose in EMF, the cost of get function is lesser than a call of set function.

That why you suggest me to control the value with calling get function before doing a assignement?
Re: two instance but same identity : problem with Map.contains [message #760418 is a reply to message #760414] Fri, 02 December 2011 10:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Jonathan,

No, I'm just remarking that it seems unusual to modify an object without
inspecting the current value in the first place. After all, setting it
to null when it's already null is pointless. In an editor, commands
would be used, and they'd need to record the original value for undo
support.


On 02/12/2011 11:20 AM, jonathan wrote:
> Ed,
>
> until now, i have not token habit to control the value of attribute
> (or reference here) before to assign it. But i suppose in EMF, the
> cost of get function is lesser than a call of set function.
> That why you suggest me to control the value with calling get function
> before doing a assignement?


Ed Merks
Professional Support: https://www.macromodeling.com/
[Resolved] Re: two instance but same identity : problem with Map.contains [message #760421 is a reply to message #760418] Fri, 02 December 2011 10:33 Go to previous message
jonathan Missing name is currently offline jonathan Missing nameFriend
Messages: 12
Registered: August 2010
Junior Member
Ed,

Ok, i understand. Anyway, thank you for your precious help.
Previous Topic:CDO: when are revisions added to the server side cache?
Next Topic:Use NOOP revision cache on the server?
Goto Forum:
  


Current Time: Fri Apr 26 00:51:18 GMT 2024

Powered by FUDForum. Page generated in 0.04064 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top