Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Deleting objects with non containment references
Deleting objects with non containment references [message #420896] Wed, 16 July 2008 07:14 Go to next message
Manfred Hahn is currently offline Manfred HahnFriend
Messages: 64
Registered: July 2009
Member
Hello,

I have the following standard situation:
there are two knots K1 and K2 and a connection between them, C1.
K1 knows C1 as outgoing connection and K2 knows C1 as incomming
connection. These references are of course no containment connections.
All elements K1, K2 and C1 are contained by a document object.

The deletion of C1 removes C1 automatically from its container, the
document object, but the references in K1 and K2 are not removed.
I'm working in a GMF environment, so the deletion is done from the
framework when I delete the connection figure.
So I changed the eInverseRemove() method of C1 to set the reference to K1
and K2 to null, which in reverse removes the references of C1 in K1 and K2.

This works, but I wonder if there is a way to handle this situation in the
model (.genmodel or .ecore) so I don't have to change the generated code?

gr. Manfred
Re: Deleting objects with non containment references [message #420898 is a reply to message #420896] Wed, 16 July 2008 08:31 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Manfred,
Maybe Ed can given an answer for the EMF specifics. It is not possible to specify this in the
hibernate mapping. Another approach could be to use a hibernate post-delete event listener and do
the work there but I am not sure if this is nicer than your current approach.

gr. Martin

Manfred Hahn wrote:
> Hello,
>
> I have the following standard situation:
> there are two knots K1 and K2 and a connection between them, C1.
> K1 knows C1 as outgoing connection and K2 knows C1 as incomming
> connection. These references are of course no containment connections.
> All elements K1, K2 and C1 are contained by a document object.
>
> The deletion of C1 removes C1 automatically from its container, the
> document object, but the references in K1 and K2 are not removed.
> I'm working in a GMF environment, so the deletion is done from the
> framework when I delete the connection figure.
> So I changed the eInverseRemove() method of C1 to set the reference to
> K1 and K2 to null, which in reverse removes the references of C1 in K1
> and K2.
>
> This works, but I wonder if there is a way to handle this situation in
> the model (.genmodel or .ecore) so I don't have to change the generated
> code?
>
> gr. Manfred
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: Deleting objects with non containment references [message #420902 is a reply to message #420896] Wed, 16 July 2008 09:40 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Manfred,

This sounds very similar to a recent question.

Manfred Hahn wrote:
> Hello,
>
> I have the following standard situation:
> there are two knots K1 and K2 and a connection between them, C1.
> K1 knows C1 as outgoing connection and K2 knows C1 as incomming
> connection. These references are of course no containment connections.
If I understand the analogy correctly, couldn't the knots contain either
their outgoing connections or their incoming connections?
> All elements K1, K2 and C1 are contained by a document object.
>
> The deletion of C1 removes C1 automatically from its container, the
> document object, but the references in K1 and K2 are not removed.
In editors, when an object is deleted, all references to that object are
also cleaned up. At the model level, that doesn't happen automatically;
you have to find all the incoming references and clean them up.
> I'm working in a GMF environment, so the deletion is done from the
> framework when I delete the connection figure.
I would expect that to clean up all incoming references to the deleted
object.
> So I changed the eInverseRemove() method of C1 to set the reference to
> K1 and K2 to null, which in reverse removes the references of C1 in K1
> and K2.
It's a bit tricky because during eInverseRemove, notifications are still
being accumulated so the notifications for the other removes you are
doing sound like they would be fired while the model might be in an
inconsistent (intermediate) state.
>
> This works, but I wonder if there is a way to handle this situation in
> the model (.genmodel or .ecore) so I don't have to change the
> generated code?
No, there is no direct support for this kind of cascading of updates
across features. Generally when things are removed, all incoming
references need to be tracked down and cleaned up...
>
> gr. Manfred
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Deleting objects with non containment references [message #420949 is a reply to message #420902] Thu, 17 July 2008 07:02 Go to previous messageGo to next message
Manfred Hahn is currently offline Manfred HahnFriend
Messages: 64
Registered: July 2009
Member
Hi Ed,

thank you for your answer. I commented your comments...

> Manfred,

> This sounds very similar to a recent question.

I've found a discussion thread about overwriting the EMF deletion command.
Since GMF covers the complete command generation and execution I could not
do that.
Sorry if I didn't find the right discussion thread for my question. I can
imagine that it's exhausting to answer the same questions over and over
again...

> Manfred Hahn wrote:
>> Hello,
>>
>> I have the following standard situation:
>> there are two knots K1 and K2 and a connection between them, C1.
>> K1 knows C1 as outgoing connection and K2 knows C1 as incomming
>> connection. These references are of course no containment connections.
> If I understand the analogy correctly, couldn't the knots contain either
> their outgoing connections or their incoming connections?

In GMF you can disconnect a connection from one knot and reconnect it to
another knot so a knot can not contain the connection.

>> All elements K1, K2 and C1 are contained by a document object.
>>
>> The deletion of C1 removes C1 automatically from its container, the
>> document object, but the references in K1 and K2 are not removed.
> In editors, when an object is deleted, all references to that object are
> also cleaned up. At the model level, that doesn't happen automatically;
> you have to find all the incoming references and clean them up.

Because of GMF I have no EMF editor, but I generated one to look at the
kind the object are deleted. Didn' find a hint.

>> I'm working in a GMF environment, so the deletion is done from the
>> framework when I delete the connection figure.
> I would expect that to clean up all incoming references to the deleted
> object.

Yes, I will ask a similar question in the GMF newsgroup. But I suppose GMF
handles only the direct counterparts to their graphical objects. That is,
with the deletion of the line that is the graphical representation of the
connection just the connection is deleted and nothing more.

>> So I changed the eInverseRemove() method of C1 to set the reference to
>> K1 and K2 to null, which in reverse removes the references of C1 in K1
>> and K2.
> It's a bit tricky because during eInverseRemove, notifications are still
> being accumulated so the notifications for the other removes you are
> doing sound like they would be fired while the model might be in an
> inconsistent (intermediate) state.

That sounds as if my solution is not the best one. But the deletion is
done inside of a transaction and can be undone without problems.

>>
>> This works, but I wonder if there is a way to handle this situation in
>> the model (.genmodel or .ecore) so I don't have to change the
>> generated code?
> No, there is no direct support for this kind of cascading of updates
> across features. Generally when things are removed, all incoming
> references need to be tracked down and cleaned up...
>>

gr. Manfred
Re: Deleting objects with non containment references [message #420953 is a reply to message #420949] Thu, 17 July 2008 11:11 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Manfred,

Comments below.

Manfred Hahn wrote:
> Hi Ed,
>
> thank you for your answer. I commented your comments...
I usually like to get the last word. :-P
>
>> Manfred,
>
>> This sounds very similar to a recent question.
>
> I've found a discussion thread about overwriting the EMF deletion
> command. Since GMF covers the complete command generation and
> execution I could not do that.
> Sorry if I didn't find the right discussion thread for my question. I
> can imagine that it's exhausting to answer the same questions over and
> over again...
Of course folks will argue that if it's repeated, it ought to be in the
FAQ. But then the FAQ is a wiki and anyone can help put questions and
answers in there.
>
>> Manfred Hahn wrote:
>>> Hello,
>>>
>>> I have the following standard situation:
>>> there are two knots K1 and K2 and a connection between them, C1.
>>> K1 knows C1 as outgoing connection and K2 knows C1 as incomming
>>> connection. These references are of course no containment connections.
>> If I understand the analogy correctly, couldn't the knots contain
>> either their outgoing connections or their incoming connections?
>
> In GMF you can disconnect a connection from one knot and reconnect it
> to another knot so a knot can not contain the connection.
It sounds like moving the knot from one container to another... After
all, consider changing the words to knot/connection to parent/child and
the statement still reads well...
>
>>> All elements K1, K2 and C1 are contained by a document object.
>>>
>>> The deletion of C1 removes C1 automatically from its container, the
>>> document object, but the references in K1 and K2 are not removed.
>> In editors, when an object is deleted, all references to that object
>> are also cleaned up. At the model level, that doesn't happen
>> automatically; you have to find all the incoming references and clean
>> them up.
>
> Because of GMF I have no EMF editor, but I generated one to look at
> the kind the object are deleted. Didn' find a hint.
I'm pretty sure GMF has the same kind of cleanup after a delete logic,
otherwise they'd have all kinds of dangling reference problems...
>
>>> I'm working in a GMF environment, so the deletion is done from the
>>> framework when I delete the connection figure.
>> I would expect that to clean up all incoming references to the
>> deleted object.
>
> Yes, I will ask a similar question in the GMF newsgroup. But I suppose
> GMF handles only the direct counterparts to their graphical objects.
> That is, with the deletion of the line that is the graphical
> representation of the connection just the connection is deleted and
> nothing more.
They'd better support something more rich. For example in a graphical
editor for Ecore itself, if an EClass is deleted, all features with that
as their type and all other EClasses with that as their super class will
need some attention...
>
>>> So I changed the eInverseRemove() method of C1 to set the reference
>>> to K1 and K2 to null, which in reverse removes the references of C1
>>> in K1 and K2.
>> It's a bit tricky because during eInverseRemove, notifications are
>> still being accumulated so the notifications for the other removes
>> you are doing sound like they would be fired while the model might be
>> in an inconsistent (intermediate) state.
>
> That sounds as if my solution is not the best one. But the deletion is
> done inside of a transaction and can be undone without problems.
I think it ought to be done using commands. I'm convinced that GMF must
have something to deal with this kind of issue.
>
>>>
>>> This works, but I wonder if there is a way to handle this situation
>>> in the model (.genmodel or .ecore) so I don't have to change the
>>> generated code?
>> No, there is no direct support for this kind of cascading of updates
>> across features. Generally when things are removed, all incoming
>> references need to be tracked down and cleaned up...
>>>
>
> gr. Manfred
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EMF JET Template Class.javajet - Problems with changes
Next Topic:Save special chars ?
Goto Forum:
  


Current Time: Fri Apr 26 16:43:43 GMT 2024

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

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

Back to the top