Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Persistence: loading whole object before adding it
Persistence: loading whole object before adding it [message #712577] Sun, 07 August 2011 12:58 Go to next message
Martin  odloucký is currently offline Martin odlouckýFriend
Messages: 49
Registered: July 2010
Member
Hi,

I have a problem with persistence of my EMF model. I save my model as XMI. Sometimes I have an object (say A) which has to be complete (all of its features loaded from the file) before it is set as a value of some reference from object B. I have discovered that the parser sets A as value right after reading all attributes of its defining element. The parser, however, resolves nested elements of A (representing references) AFTER A is set as value.

I have an adapter attached to object B which presumes that A has all its references non-NULL before it is attached to B.

Is there some way to ensure that object A is loaded with all of its features resolved before its is added as a value to B?

Thanks in advance
Re: Persistence: loading whole object before adding it [message #712602 is a reply to message #712577] Sun, 07 August 2011 13:29 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Martin,

Comments below.


On 07/08/2011 5:58 AM, Martin odlouck wrote:
> Hi,
> I have a problem with persistence of my EMF model. I save my model as
> XMI. Sometimes I have an object (say A) which has to be complete (all
> of its features loaded from the file) before it is set as a value of
> some reference from object B.
That doesn't sound good. Why is that? What if those values change
after it has been set?
> I have discovered that the parser sets A as value right after reading
> all attributes of its defining element.
Yes, those are available immediately in the SAX callbacks when the
element is created...
> The parser, however, resolves nested elements of A (representing
> references) AFTER A is set as value.
Generally the nested elements represent addition features to be
populated and of course processing their nested content might well
result in a reference to A needing to be set.
> I have an adapter attached to object B which presumes that A has all
> its references non-NULL before it is attached to B.
So that's a bad assumption. That won't work with EcoreUtil.copy
either. You can imagine that in general if A can refer to B and B can
refer to A that it's hard (or impossible if it's not a bidirectional
reference) to ensure both are fully populated. If three mutually
referencing values are involved, it would be impossible in general.
> Is there some way to ensure that object A is loaded with all of its
> features resolved before its is added as a value to B?
Perhaps OPTION_DEFER_IDREF_RESOLUTION will help though even then, the
population of cross references at the end of loading isn't necessarily
going to follow some specific order...

You'd be better to have whatever B depends on from A to be handled
lazily... (Like the EClass.eAllSuperTypes isn't computed until you
first ask for that value; it couldn't be populated properly until the
resource is fully loaded and often even involves cross file references).
>
> Thanks in advance


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Persistence: loading whole object before adding it [message #712627 is a reply to message #712602] Sun, 07 August 2011 14:20 Go to previous messageGo to next message
Martin  odloucký is currently offline Martin odlouckýFriend
Messages: 49
Registered: July 2010
Member
Thank your for quick response. I see what are you traying to tell me. My model is rather specific so I try to create simplier example. Let's suppose object A is a student and B is a students club. Every student has a reference to the university he/she attands. When calling club.getStudents().add(student), the club needs to check student.getUniversity().getName() to assign him responsibilities (for example). If student's university is NULL the club does not know what to do with him.
So what si the best solution in such a case? The clubs accesses the student's reference to university immediately after addition. However, the university reference is loaded later.
(no subject) [message #712632 is a reply to message #712602] Sun, 07 August 2011 14:20 Go to previous messageGo to next message
Martin  odloucký is currently offline Martin odlouckýFriend
Messages: 49
Registered: July 2010
Member
Thank your for quick response. I see what are you traying to tell me. My model is rather specific so I try to create simplier example. Let's suppose object A is a student and B is a students club. Every student has a reference to the university he/she attands. When calling club.getStudents().add(student), the club needs to check student.getUniversity().getName() to assign him responsibilities (for example). If student's university is NULL the club does not know what to do with him.
So what si the best solution in such a case? The clubs accesses the student's reference to university immediately after addition. However, the university reference is loaded later.
Re: Persistence: loading whole object before adding it [message #712643 is a reply to message #712627] Sun, 07 August 2011 14:40 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Martin,

Comments below.

On 07/08/2011 7:20 AM, Martin odlouck wrote:
> Thank your for quick response. I see what are you traying to tell me.
> My model is rather specific so I try to create simplier example. Let's
> suppose object A is a student and B is a students club. Every student
> has a reference to the university he/she attands. When calling
> club.getStudents().add(student), the club needs to check
> student.getUniversity().getName() to assign him responsibilities (for
> example).
I would have imagined the assignment of responsibilities are themselves
serialized and are set appropriately based on that persisted information.
> If student's university is NULL the club does not know what to do with
> him.
Suppose he was expelled? How should the model update? Suppose he
transfers to a different university. Should he be removed from the club
too?
> So what si the best solution in such a case? The clubs accesses the
> student's reference to university immediately after addition.
If you serialize universities before students in a single resource (it's
bad news to resolve proxies to university during loading if they are in
a different resource) and serialize the student's reference to the
university before that of their references to clubs, that will help;
these can be controlled with the order at the root of the resource of
the feature order in the classes.
> However, the university reference is loaded later.
Is that because of feature order in the class?

Without all the details of what are containment references, how many
resources are involved, and so on, it's very hard to give specific
answers. One thing is for sure though, these order dependencies of what
must be set first are problematic from all aspects. Even when working
with the API, it will be necessary to assign the university before
assigning club; who's to know that just looking at the API...


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EMF & hiberate, one-to-many mapping
Next Topic:eIsSet databinding.
Goto Forum:
  


Current Time: Fri Apr 26 04:57:47 GMT 2024

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

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

Back to the top