Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF Object comparisons.
EMF Object comparisons. [message #397736] Fri, 06 January 2006 15:27 Go to next message
saurabh is currently offline saurabhFriend
Messages: 8
Registered: July 2009
Junior Member
Hi there,

I have 2 EMF models(say Model A and Model B) , I am adding EObjects from
Model A into Model B as EAnnotations. I have a GUI which lets me select
EObjects
in Model B and map them into Model A, these objects are proxy.

I am also trying to compare these objects, for example.

Model A has

EObject A which refers EObject X from Model B

I want to get all EObjects in Model A which refer to EObject X from Model B
The first time when i load up Model and B, i create references and on
comparing
EObject X from Model A.equals(EObject X from B) they are both equal but
when i
delete a reference (EObject X -reference in A) and re add the same and
compare
the two objects are different, does anyone know the solution to this..?

Regards,
Jeecom
Re: EMF Object comparisons. [message #397739 is a reply to message #397736] Fri, 06 January 2006 17:07 Go to previous messageGo to next message
Marcelo Paternostro is currently offline Marcelo PaternostroFriend
Messages: 602
Registered: July 2009
Senior Member
Hi Jeecom,

How did you load the object you are "re adding"? If you are using the
same ResourceSet all the time, for both Models A and B, you should be
always getting the same object.

If this is not the case, I would suggest you to review your code keeping
in mind that (proxyObject != resolvedObject), ie, after resolving the
proxy you get a new EObject. A long time ago, before joining the EMF
team, I had a similar problem because I was comparing a proxyObject I
had cached somewhere with the resolved one.

Cheers,
Marcelo

saurabh wrote:
> Hi there,
>
> I have 2 EMF models(say Model A and Model B) , I am adding EObjects from
> Model A into Model B as EAnnotations. I have a GUI which lets me select
> EObjects
> in Model B and map them into Model A, these objects are proxy.
>
> I am also trying to compare these objects, for example.
>
> Model A has
>
> EObject A which refers EObject X from Model B
>
> I want to get all EObjects in Model A which refer to EObject X from Model B
> The first time when i load up Model and B, i create references and on
> comparing
> EObject X from Model A.equals(EObject X from B) they are both equal but
> when i
> delete a reference (EObject X -reference in A) and re add the same and
> compare
> the two objects are different, does anyone know the solution to this..?
>
> Regards,
> Jeecom
>
>
Re: EMF Object comparisons. [message #397740 is a reply to message #397739] Fri, 06 January 2006 18:41 Go to previous messageGo to next message
saurabh is currently offline saurabhFriend
Messages: 8
Registered: July 2009
Junior Member
Thanks for the prompt reply,

Yes both the models are opened from the same resourceset.

I open both models, at this time all the (Model b)objects referenced by
Model A
are proxies (href=c:/B.model//#_CvffgfgfvvffXw), now when i try to replace a
reference in Model A with an Object reference of Model B ,because Model B is
still open this current reference is not a proxy but other similar
references are still
proxies and yes (proxyObject != resolvedObject) is true in this case for me.

What's the solution to this...? I overcome this by unloading the model the
moment
the reference is replaced in Model A. Now all the objects behave as proxies
and
the comparisons are correct. I am not sure if this a good way as it could be
very expensive. So you have any other suggestions...?


"Marcelo Paternostro" <marcelop@ca.ibm.com> wrote in message
news:dpm87d$449$1@utils.eclipse.org...
> Hi Jeecom,
>
> How did you load the object you are "re adding"? If you are using the
> same ResourceSet all the time, for both Models A and B, you should be
> always getting the same object.
>
> If this is not the case, I would suggest you to review your code keeping
> in mind that (proxyObject != resolvedObject), ie, after resolving the
> proxy you get a new EObject. A long time ago, before joining the EMF
> team, I had a similar problem because I was comparing a proxyObject I had
> cached somewhere with the resolved one.
>
> Cheers,
> Marcelo
>
> saurabh wrote:
>> Hi there,
>>
>> I have 2 EMF models(say Model A and Model B) , I am adding EObjects from
>> Model A into Model B as EAnnotations. I have a GUI which lets me select
>> EObjects
>> in Model B and map them into Model A, these objects are proxy.
>>
>> I am also trying to compare these objects, for example.
>>
>> Model A has
>>
>> EObject A which refers EObject X from Model B
>>
>> I want to get all EObjects in Model A which refer to EObject X from Model
>> B
>> The first time when i load up Model and B, i create references and on
>> comparing
>> EObject X from Model A.equals(EObject X from B) they are both equal but
>> when i
>> delete a reference (EObject X -reference in A) and re add the same and
>> compare
>> the two objects are different, does anyone know the solution to this..?
>>
>> Regards,
>> Jeecom
Re: EMF Object comparisons. [message #397743 is a reply to message #397740] Fri, 06 January 2006 19:03 Go to previous messageGo to next message
Marcelo Paternostro is currently offline Marcelo PaternostroFriend
Messages: 602
Registered: July 2009
Senior Member
So if I got it correctly, your scenario is not working because
(proxyObject != resolvedObject). If this is not the case, please
forgive me for not getting it as fast as Ed would ;-) and try to explain
it again.

If it is the case, continue reading...

Although we can say (proxyObject != resolvedObject) is always true in
EMF, once the proxyObject is resolved to resolveEObject in the context
of a ResourceSet, *every* resolution of a different proxy object that
points to the same eObject will always return resolveEObject. In other
words

- proxyObject1 and proxyObject2 were created in the *same* resource set
- proxyObject1 and proxyObject2 are proxies for the same object
- resolvedObject == resolved(proxyObject1) == resolved(proxyObject2)
- resolvedObject != proxyObject1 && resolvedObject != proxyObject2

So, given that you are using one ResourceSet, I am guessing your problem
can be either

- You are caching the proxy object somewhere and comparing this cached
version against the resolved one

- In one place you are using EMF apis to get a reference to an object
without resolving it and in the other you are using the methods in the
generated interface that would always resolve.

You could solve the latter in two ways:

- Make sure you are resolving all the proxies before comparing the
objects (if you resolved one proxy, there would be almost no cost to
resolve a second proxy that "points" to the same object)

- Compare the uri returned by EcoreUtil.getURI(EObject) instead of
comparing the objects themselves.

I would suggest trying the former first.

Cheers,
Marcelo

saurabh wrote:
> Thanks for the prompt reply,
>
> Yes both the models are opened from the same resourceset.
>
> I open both models, at this time all the (Model b)objects referenced by
> Model A
> are proxies (href=c:/B.model//#_CvffgfgfvvffXw), now when i try to replace a
> reference in Model A with an Object reference of Model B ,because Model B is
> still open this current reference is not a proxy but other similar
> references are still
> proxies and yes (proxyObject != resolvedObject) is true in this case for me.
>
> What's the solution to this...? I overcome this by unloading the model the
> moment
> the reference is replaced in Model A. Now all the objects behave as proxies
> and
> the comparisons are correct. I am not sure if this a good way as it could be
> very expensive. So you have any other suggestions...?
>
>
> "Marcelo Paternostro" <marcelop@ca.ibm.com> wrote in message
> news:dpm87d$449$1@utils.eclipse.org...
>
>>Hi Jeecom,
>>
>>How did you load the object you are "re adding"? If you are using the
>>same ResourceSet all the time, for both Models A and B, you should be
>>always getting the same object.
>>
>>If this is not the case, I would suggest you to review your code keeping
>>in mind that (proxyObject != resolvedObject), ie, after resolving the
>>proxy you get a new EObject. A long time ago, before joining the EMF
>>team, I had a similar problem because I was comparing a proxyObject I had
>>cached somewhere with the resolved one.
>>
>>Cheers,
>>Marcelo
>>
>>saurabh wrote:
>>
>>>Hi there,
>>>
>>>I have 2 EMF models(say Model A and Model B) , I am adding EObjects from
>>>Model A into Model B as EAnnotations. I have a GUI which lets me select
>>>EObjects
>>>in Model B and map them into Model A, these objects are proxy.
>>>
>>>I am also trying to compare these objects, for example.
>>>
>>>Model A has
>>>
>>>EObject A which refers EObject X from Model B
>>>
>>>I want to get all EObjects in Model A which refer to EObject X from Model
>>>B
>>>The first time when i load up Model and B, i create references and on
>>>comparing
>>>EObject X from Model A.equals(EObject X from B) they are both equal but
>>>when i
>>>delete a reference (EObject X -reference in A) and re add the same and
>>>compare
>>>the two objects are different, does anyone know the solution to this..?
>>>
>>>Regards,
>>>Jeecom
>
>
>
Re: EMF Object comparisons. [message #397751 is a reply to message #397743] Sat, 07 January 2006 16:16 Go to previous messageGo to next message
saurabh is currently offline saurabhFriend
Messages: 8
Registered: July 2009
Junior Member
Well, sorry i think i have not been able to explain this correctly, let me
try again.

proxyObject1 and proxyObject2 were created in the *same* resource set
proxyObject1 and proxyObject2 are proxies for the same object
These objects are in my model say (file:/c:/a.model) and are proxies with
respect
to the model they are refered in say model b, model b is currently loaded
using a
resourceset.

Now assume that i open the resource(file:/c:/a.model) using the sme
resourceset , delete the reference to proxyObject1 using my logic and
replace it with the similar object reference again but both my resources is
still loaded at this time and when i compare the current object (this is not
a proxy any more)because object.eIsProxy() is false. I compare this object
with (proxyObject2) and proxyObject2.eIsProxy() is true and i resolve this
and compare them and they both are not equal. Also when i call
resource.getID(proxyObject2) i get an Id but calling the same on
(proxyObject1 ,not really a proxy any more) returns null.Well first of all i
don't understand why one is a proxy and the other isn't, maybe the reference
is still in memory..?

Also when i open open the resource(file:/c:/a.model) and delete the
proxyObject1 using my logic and replace it with the similar reference again
and call resource.unoad() and do what i (just explained above ) i find that
both (proxyObject1 and proxyObject2 ) are proxies and point to the same
reference
and are equal.

I hope this clarifies the problem.




"Marcelo Paternostro" <marcelop@ca.ibm.com> wrote in message
news:dpmf14$f9l$1@utils.eclipse.org...
> So if I got it correctly, your scenario is not working because
> (proxyObject != resolvedObject). If this is not the case, please forgive
> me for not getting it as fast as Ed would ;-) and try to explain it again.
>
> If it is the case, continue reading...
>
> Although we can say (proxyObject != resolvedObject) is always true in EMF,
> once the proxyObject is resolved to resolveEObject in the context of a
> ResourceSet, *every* resolution of a different proxy object that points to
> the same eObject will always return resolveEObject. In other words
>
> - proxyObject1 and proxyObject2 were created in the *same* resource set
> - proxyObject1 and proxyObject2 are proxies for the same object
> - resolvedObject == resolved(proxyObject1) == resolved(proxyObject2)
> - resolvedObject != proxyObject1 && resolvedObject != proxyObject2
>
> So, given that you are using one ResourceSet, I am guessing your problem
> can be either
>
> - You are caching the proxy object somewhere and comparing this cached
> version against the resolved one
>
> - In one place you are using EMF apis to get a reference to an object
> without resolving it and in the other you are using the methods in the
> generated interface that would always resolve.
>
> You could solve the latter in two ways:
>
> - Make sure you are resolving all the proxies before comparing the objects
> (if you resolved one proxy, there would be almost no cost to resolve a
> second proxy that "points" to the same object)
>
> - Compare the uri returned by EcoreUtil.getURI(EObject) instead of
> comparing the objects themselves.
>
> I would suggest trying the former first.
>
> Cheers,
> Marcelo
>
> saurabh wrote:
>> Thanks for the prompt reply,
>>
>> Yes both the models are opened from the same resourceset.
>>
>> I open both models, at this time all the (Model b)objects referenced by
>> Model A
>> are proxies (href=c:/B.model//#_CvffgfgfvvffXw), now when i try to
>> replace a
>> reference in Model A with an Object reference of Model B ,because Model B
>> is
>> still open this current reference is not a proxy but other similar
>> references are still
>> proxies and yes (proxyObject != resolvedObject) is true in this case for
>> me.
>>
>> What's the solution to this...? I overcome this by unloading the model
>> the moment
>> the reference is replaced in Model A. Now all the objects behave as
>> proxies and
>> the comparisons are correct. I am not sure if this a good way as it could
>> be very expensive. So you have any other suggestions...?
>>
>>
>> "Marcelo Paternostro" <marcelop@ca.ibm.com> wrote in message
>> news:dpm87d$449$1@utils.eclipse.org...
>>
>>>Hi Jeecom,
>>>
>>>How did you load the object you are "re adding"? If you are using the
>>>same ResourceSet all the time, for both Models A and B, you should be
>>>always getting the same object.
>>>
>>>If this is not the case, I would suggest you to review your code keeping
>>>in mind that (proxyObject != resolvedObject), ie, after resolving the
>>>proxy you get a new EObject. A long time ago, before joining the EMF
>>>team, I had a similar problem because I was comparing a proxyObject I had
>>>cached somewhere with the resolved one.
>>>
>>>Cheers,
>>>Marcelo
>>>
>>>saurabh wrote:
>>>
>>>>Hi there,
>>>>
>>>>I have 2 EMF models(say Model A and Model B) , I am adding EObjects from
>>>>Model A into Model B as EAnnotations. I have a GUI which lets me select
>>>>EObjects
>>>>in Model B and map them into Model A, these objects are proxy.
>>>>
>>>>I am also trying to compare these objects, for example.
>>>>
>>>>Model A has
>>>>
>>>>EObject A which refers EObject X from Model B
>>>>
>>>>I want to get all EObjects in Model A which refer to EObject X from
>>>>Model B
>>>>The first time when i load up Model and B, i create references and on
>>>>comparing
>>>>EObject X from Model A.equals(EObject X from B) they are both equal but
>>>>when i
>>>>delete a reference (EObject X -reference in A) and re add the same and
>>>>compare
>>>>the two objects are different, does anyone know the solution to this..?
>>>>
>>>>Regards,
>>>>Jeecom
>>
>>
Re: EMF Object comparisons. [message #397771 is a reply to message #397751] Mon, 09 January 2006 17:51 Go to previous message
Marcelo Paternostro is currently offline Marcelo PaternostroFriend
Messages: 602
Registered: July 2009
Senior Member
Hi Jeecom,

Thx for the detailed explanation. There are things really fishy here.
See my comments below.

Cheers,
Marcelo

saurabh wrote:
> Well, sorry i think i have not been able to explain this correctly, let me
> try again.
>
> proxyObject1 and proxyObject2 were created in the *same* resource set
> proxyObject1 and proxyObject2 are proxies for the same object
> These objects are in my model say (file:/c:/a.model) and are proxies with
> respect
> to the model they are refered in say model b, model b is currently loaded
> using a
> resourceset.
>
> Now assume that i open the resource(file:/c:/a.model) using the sme
> resourceset , delete the reference to proxyObject1 using my logic

Here you've deleted the proxyObject1. In order to get a reference to
this proxy, you've probably did something like (assuming a single reference)

proxyObject1 = objectFromModelB.eGet(featureFoo, false);

because any of the following lines would automatically resolve
proxyObject1 into object1

object1 = objectFromModelB.eGet(featureFoo, true);
object1 = objectFromModelB.eGet(featureFoo);
object1 = objectFromModelB.getFoo();

and
> replace it with the similar object reference again but both my resources is
> still loaded at this time and when i compare the current object (this is not
> a proxy any more)because object.eIsProxy() is false.

In theory I would assume that by "similar object reference" you mean the
object that would be resolved by proxyObject1 if it was not deleted.
(Let's call it theObject1). How you got a reference to theObject1 is
really the key to solve this problem. Anything different than getting
it from the original ResourceSet or from a Resource created by the
original ResourceSet will make your equality test fail.

I compare this object
> with (proxyObject2) and proxyObject2.eIsProxy() is true

Again, you've probably got a reference to proxyObject2 using something like

proxyObject2 = anotherObjectFromModelB.eGet(featureFoo, false);

and i resolve this

So you've resolved proxyObject2 into, say, theObject2.

> and compare them and they both are not equal.

So here, theObject1 != theObject2. Sorry being repetitive, but if
proxyObject2 was a proxy to theObject1, the only way to have theObject1
!= theObject2 is if they were loaded by different resources (which would
be mean different ResourceSets)

Also when i call
> resource.getID(proxyObject2) i get an Id but calling the same on
> (proxyObject1 ,not really a proxy any more) returns null.

I think I can finally say that you are not using the same ResourceSet
and actually loading the objects from different Resources (please don't
hate me ;-)). See, the getID(EObject) method available in the
XMLResource interface gets the object's id from a map that is local to
the resource. If you were actually getting theObject1 and theObject2
(that were supposed to equal) from the same resource, they would *have*
to be associated with the same id.

Btw, the ResourceSet implementation ensures that a given resource is
only loaded once - the resource is uniquely identified by the URI you've
used when doing something like

Resource resource = resourceSet.createResource(uri)

Well first of all i
> don't understand why one is a proxy and the other isn't, maybe the reference
> is still in memory..?
>

As I said in the comment that starts with "In theory", the key is to
review how you've got a reference to theObject1.

> Also when i open open the resource(file:/c:/a.model) and delete the
> proxyObject1 using my logic and replace it with the similar reference again
> and call resource.unoad() and do what i (just explained above ) i find that
> both (proxyObject1 and proxyObject2 ) are proxies and point to the same
> reference
> and are equal.
>
> I hope this clarifies the problem.
>
>
>
>
> "Marcelo Paternostro" <marcelop@ca.ibm.com> wrote in message
> news:dpmf14$f9l$1@utils.eclipse.org...
>
>>So if I got it correctly, your scenario is not working because
>>(proxyObject != resolvedObject). If this is not the case, please forgive
>>me for not getting it as fast as Ed would ;-) and try to explain it again.
>>
>>If it is the case, continue reading...
>>
>>Although we can say (proxyObject != resolvedObject) is always true in EMF,
>>once the proxyObject is resolved to resolveEObject in the context of a
>>ResourceSet, *every* resolution of a different proxy object that points to
>>the same eObject will always return resolveEObject. In other words
>>
>>- proxyObject1 and proxyObject2 were created in the *same* resource set
>>- proxyObject1 and proxyObject2 are proxies for the same object
>>- resolvedObject == resolved(proxyObject1) == resolved(proxyObject2)
>>- resolvedObject != proxyObject1 && resolvedObject != proxyObject2
>>
>>So, given that you are using one ResourceSet, I am guessing your problem
>>can be either
>>
>>- You are caching the proxy object somewhere and comparing this cached
>>version against the resolved one
>>
>>- In one place you are using EMF apis to get a reference to an object
>>without resolving it and in the other you are using the methods in the
>>generated interface that would always resolve.
>>
>>You could solve the latter in two ways:
>>
>>- Make sure you are resolving all the proxies before comparing the objects
>>(if you resolved one proxy, there would be almost no cost to resolve a
>>second proxy that "points" to the same object)
>>
>>- Compare the uri returned by EcoreUtil.getURI(EObject) instead of
>>comparing the objects themselves.
>>
>>I would suggest trying the former first.
>>
>>Cheers,
>>Marcelo
>>
>>saurabh wrote:
>>
>>>Thanks for the prompt reply,
>>>
>>>Yes both the models are opened from the same resourceset.
>>>
>>>I open both models, at this time all the (Model b)objects referenced by
>>>Model A
>>>are proxies (href=c:/B.model//#_CvffgfgfvvffXw), now when i try to
>>>replace a
>>>reference in Model A with an Object reference of Model B ,because Model B
>>>is
>>>still open this current reference is not a proxy but other similar
>>>references are still
>>>proxies and yes (proxyObject != resolvedObject) is true in this case for
>>>me.
>>>
>>>What's the solution to this...? I overcome this by unloading the model
>>>the moment
>>>the reference is replaced in Model A. Now all the objects behave as
>>>proxies and
>>>the comparisons are correct. I am not sure if this a good way as it could
>>>be very expensive. So you have any other suggestions...?
>>>
>>>
>>>"Marcelo Paternostro" <marcelop@ca.ibm.com> wrote in message
>>>news:dpm87d$449$1@utils.eclipse.org...
>>>
>>>
>>>>Hi Jeecom,
>>>>
>>>>How did you load the object you are "re adding"? If you are using the
>>>>same ResourceSet all the time, for both Models A and B, you should be
>>>>always getting the same object.
>>>>
>>>>If this is not the case, I would suggest you to review your code keeping
>>>>in mind that (proxyObject != resolvedObject), ie, after resolving the
>>>>proxy you get a new EObject. A long time ago, before joining the EMF
>>>>team, I had a similar problem because I was comparing a proxyObject I had
>>>>cached somewhere with the resolved one.
>>>>
>>>>Cheers,
>>>>Marcelo
>>>>
>>>>saurabh wrote:
>>>>
>>>>
>>>>>Hi there,
>>>>>
>>>>>I have 2 EMF models(say Model A and Model B) , I am adding EObjects from
>>>>>Model A into Model B as EAnnotations. I have a GUI which lets me select
>>>>>EObjects
>>>>>in Model B and map them into Model A, these objects are proxy.
>>>>>
>>>>>I am also trying to compare these objects, for example.
>>>>>
>>>>>Model A has
>>>>>
>>>>>EObject A which refers EObject X from Model B
>>>>>
>>>>>I want to get all EObjects in Model A which refer to EObject X from
>>>>>Model B
>>>>>The first time when i load up Model and B, i create references and on
>>>>>comparing
>>>>>EObject X from Model A.equals(EObject X from B) they are both equal but
>>>>>when i
>>>>>delete a reference (EObject X -reference in A) and re add the same and
>>>>>compare
>>>>>the two objects are different, does anyone know the solution to this..?
>>>>>
>>>>>Regards,
>>>>>Jeecom
>>>
>>>
>
Previous Topic:Using Model.Edit for View
Next Topic:Child object observing another child
Goto Forum:
  


Current Time: Sat Apr 27 02:24:58 GMT 2024

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

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

Back to the top