Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Many Packages and ManyModelFiles -> No Refs Model load
Many Packages and ManyModelFiles -> No Refs Model load [message #910739] Mon, 10 September 2012 10:05 Go to next message
Markus Jo is currently offline Markus JoFriend
Messages: 83
Registered: January 2012
Member
Hi,
I have the following situation.

- I have one .ecore metamodel that has some nested packages.
- When saving I split the metamodel to one basics model-file and some fragment files.

Lets say in my basics modelfile I have a list of train-types and a list of railways stations of which each has a list of trains.

When I do the save every railways station has its own model file that conatins all of it trains.
Every train has a train-type attribute. The train type is contained in the basics file and each train references one train-type.

So far so good.....but when I save my model and reopen it, all references that I set before (from train to its traintype) are wrong. The point to the first train-type in the train-types list of the basics file.

Why is the modelfile loader not able to restore the references properly? Is it even possible ? Is it possible that the apckages in my ecore file are the problem ?

thx

[Updated on: Mon, 10 September 2012 10:05]

Report message to a moderator

Re: Many Packages and ManyModelFiles -> No Refs Model load [message #910749 is a reply to message #910739] Mon, 10 September 2012 10:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Markus,

Comments below.

On 10/09/2012 12:05 PM, Markus Jo wrote:
> Hi,
> I have the following situation.
>
> - I have one .ecore metamodel that has some nested packages.
As I've said many times on the newsgroup, those are mostly asking for
problems.
> - When saving I split the metamodel to one basics model-file and some
> fragment files.
You mean the instances I assume...
>
> Lets say in my basics modelfile I have a list of train-types and a
> list of railways stations of which each has a list of trains.
>
> When I do the save every railways station has its own model file that
> conatins all of it trains.
So you create new resources as part of an override of doSave in the editor?
> Every train has a train-type attribute. The train type is contained in
> the basics file and each train references one train-type.
>
> So far so good.....but when I save my model and reopen it, all
> references that I set before (from train to its traintype) are wrong.
> The point to the first train-type in the train-types list of the
> basics file.
What do the saved references to the train-type look like in the XML?
>
> Why is the modelfile loader not able to restore the references
> properly? Is it even possible ?
It all sounds possible and supported, but likely there is some error in
how you set it up. It's hard to say what without code or more accurate
details. Showing me what the serialized reference looks like will help.
>
> thx


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Many Packages and ManyModelFiles -> No Refs Model load [message #910828 is a reply to message #910749] Mon, 10 September 2012 13:04 Go to previous messageGo to next message
Markus Jo is currently offline Markus JoFriend
Messages: 83
Registered: January 2012
Member
Hi Ed.

"So you create new resources as part of an override of doSave in the editor?"....yes, by overridng doSave and doSaveAs

I found the problem.....its a sort. We are sorting the train-types list. The trains in the outsourced modelfile fragments however are still using to old index to realize the reference, altough at time of the sort there references were already loaded by

   // @createModel()  of Editor
if(epa.getTimeTables() != null && model.getTrains().getTrain().size() > 0){
			for(int i = 0; i < model.getTrains().getTrain).size(); i++){
				model.getTrains().getTrain.get(i); // force load of resource
			}
		}
		for (Resource resource : res) {
			resource.setTrackingModification(true);
		}


The sort is some lines after, in the editors createModel() method, too.

Is sorting not possible when splitting the model, or do i have to trigger some kind of refresh to the fragement resource files or the model root element ?
Re: Many Packages and ManyModelFiles -&amp;gt; No Refs Model load [message #910905 is a reply to message #910828] Mon, 10 September 2012 15:41 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Markus,

Comments below.

On 10/09/2012 3:04 PM, Markus Jo wrote:
> Hi Ed.
>
> "So you create new resources as part of an override of doSave in the
> editor?"....yes, by overridng doSave and doSaveAs
>
> I found the problem.....its a sort. We are sorting the train-types
> list. The trains in the outsourced modelfile fragments however are
> still using to old index to realize the reference, altough at time of
> the sort there references were already loaded by
> // @createModel() of Editor
> if(epa.getTimeTables() != null && model.getTrains().getTrain().size()
> > 0){
> for(int i = 0; i < model.getTrains().getTrain).size(); i++){
> model.getTrains().getTrain.get(i); // force load of
> resource
> }
> }
> for (Resource resource : res) {
> resource.setTrackingModification(true);
> }
>
>
> The sort is some lines after, in the editors createModel() method, too.
You can force all proxies to resolve with something like
EcoreUtil.resolveAll. Another approach is to specialize the fragment
paths that are used so they're not index based. You can look at
EModelElementImpl as an example. Or you can specify from attribute of
the referenced type as a key that uniquely identifying the reference
object within that reference.
>
> Is sorting not possible when splitting the model, or do i have to
> trigger some kind of refresh to the fragement resource files or the
> model root element ?
The details are still a bit vague for me to give a good answer. It
sounds like you have places that are using index-based references that
ultimately aren't stable because of the sorting you do. So using some
type of key-based access should work better.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Many Packages and ManyModelFiles -&amp;gt; No Refs Model load [message #911262 is a reply to message #910905] Tue, 11 September 2012 09:07 Go to previous messageGo to next message
Markus Jo is currently offline Markus JoFriend
Messages: 83
Registered: January 2012
Member
Hmm....the key based way sounds good, but not all of our referenced elements have one key attribute....sometimes we would need two attributes or three to build an unique key and that seems not to be allowed in the ecore file....he complains that there can only be one attribute with ID set to true.

I do not really see what the EModelElementImpl does.... specialize fragments paths? I dont think this could be a solution... whatever this path might look like, there are two possibilities....use an index or use a key, isnt it ? The first is bad when sorting or even when using drag and drop because the fragements do not notice the changed indicies. And the key approach does only work if we always have one key attribute.

But I have another idea that is special for our project and has nothing to do with emf. We already have a mechanism to restore/build references by a collection of so called refID attributes, because we import data from a server. So my idea is just to save the refIds we have to the model file, set the ecore-refrences to transient and use the restoreReferences-Algo, that we use after importing data, when we open/load the model file. I'll try that workaround. When I get problems I might be here again.

Thanks so far Ed.
Re: Many Packages and ManyModelFiles -&amp;amp;gt; No Refs Model load [message #911268 is a reply to message #911262] Tue, 11 September 2012 09:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Markus,

Comments below.

On 11/09/2012 11:07 AM, Markus Jo wrote:
> Hmm....the key based way sounds good, but not all of our referenced
> elements have one key attribute....sometimes we would need two
> attributes or three to build an unique key and that seems not to be
> allowed in the ecore file....he complains that there can only be one
> attribute with ID set to true.
Don't confuse EAttribute.iD with EReference.eKeys. The former means the
attributes string value must be unique in the entire resource. The
latter only means that the combination of the string values for the key
attributes must be unique within that one reference. The former results
in the ID being used as the fragment, that latter affects only the
segment in the fragment so it's of the form
@<feature-name>[<key>='<value>] rather than @<feature-name>.<index>.
>
> I do not really see what the EModelElementImpl does.... specialize
> fragments paths?

See
org.eclipse.emf.ecore.impl.EModelElementImpl.eURIFragmentSegment(EStructuralFeature,
EObject) and
org.eclipse.emf.ecore.impl.EModelElementImpl.eObjectForURIFragmentSegment(String).
> I dont think this could be a solution... whatever this path might look
> like, there are two possibilities....use an index or use a key, isnt it ?
Yes, and indexes are fast but fragile.
> The first is bad when sorting or even when using drag and drop because
> the fragements do not notice the changed indicies.
Not while there are unresolved proxies.
> And the key approach does only work if we always have one key attribute.
Well, you've mixed up IDs with keys.
>
> But I have another idea that is special for our project and has
> nothing to do with emf. We already have a mechanism to restore/build
> references by a collection of so called refID attributes, because we
> import data from a server. So my idea is just to save the refIds we
> have to the model file, set the ecore-refrences to transient and use
> the restoreReferences-Algo, that we use after importing data, when we
> open/load the model file. I'll try that workaround. When I get
> problems I might be here again.
Better to solve this nicely in the model. Try the above, it should work
well. If you're stuck, ask more questions.
>
> Thanks so far Ed.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Many Packages and ManyModelFiles -&amp;amp;gt; No Refs Model load [message #911810 is a reply to message #911268] Wed, 12 September 2012 11:23 Go to previous messageGo to next message
Markus Jo is currently offline Markus JoFriend
Messages: 83
Registered: January 2012
Member
Hmm....I really confused EAttribute.iD with EReference.eKeys. The eKeys approach seems an easy way. I hope in combination with EcoreUtil.resolveAll(editingDomain.getRessourceSet()) we are save.

I think a cause for our failures was not the unresolved state of our fragements (they should already have been resolved on createModel). Could it be that the problem is that our sort doesnt send a notification? This is the sort in our EObject

/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void sort() {
		ECollections.sort(this.getClientOrganization(),new Comparator<ClientOrganization>(){
				@Override
				public int compare(ClientOrganization p1, ClientOrganization p2) {
					if (p1.getName() != null && p2.getName() != null){
						return p1.getName().compareToIgnoreCase(p2.getName());
					}
					if (p1.getName() != null ) return -1;
					if (p2.getName() != null ) return 1;
					return 0;
				}
			});
	}



Is there missing something like this at the end: eNotify(new ENotificationImpl(this, Notification.MOVE, ClientorganizationPackage.CLIENT_ORGANIZATIONS__CLIENT_ORGANIZATION, null, null));
Re: Many Packages and ManyModelFiles -&amp;amp;amp;gt; No Refs Model load [message #911820 is a reply to message #911810] Wed, 12 September 2012 11:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Markus,

Comments below.

On 12/09/2012 1:23 PM, Markus Jo wrote:
> Hmm....I really confused EAttribute.iD with EReference.eKeys.
Yes, very similar concepts...
> The eKeys approach seems an easy way. I hope in combination with
> EcoreUtil.resolveAll(editingDomain.getRessourceSet()) we are save.
I kind of doubt you'll need to eagerly resolve all proxies if the proxy
URI fragments are resilient to reordering...
>
> I think a cause for our failures was not the unresolved state of our
> fragements (they should already have been resolved on createModel).
> Could it be that the problem is that our sort doesnt send a
> notification? This is the sort in our EObject
>
>
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated NOT
> */
> public void sort() {
> ECollections.sort(this.getClientOrganization(),new
> Comparator<ClientOrganization>(){
> @Override
> public int compare(ClientOrganization p1,
> ClientOrganization p2) {
> if (p1.getName() != null && p2.getName() != null){
> return
> p1.getName().compareToIgnoreCase(p2.getName());
> }
> if (p1.getName() != null ) return -1;
> if (p2.getName() != null ) return 1;
> return 0;
> }
> });
> }
>
>
No, any change to the list will do moves and that will produce MOVE
notifications.
>
> Is there missing something like this at the end: eNotify(new
> ENotificationImpl(this, Notification.MOVE,
> ClientorganizationPackage.CLIENT_ORGANIZATIONS__CLIENT_ORGANIZATION,
> null, null));
No.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Many Packages and ManyModelFiles -&amp;amp;amp;gt; No Refs Model load [message #911852 is a reply to message #911820] Wed, 12 September 2012 13:01 Go to previous messageGo to next message
Markus Jo is currently offline Markus JoFriend
Messages: 83
Registered: January 2012
Member
Ok, right again.....without EcoreUtil.resolveAll it was not resolved all.

BUT....we used fragments in order to improve the save-action. We use resource.isModified (after setting resource.trackModification) to evaluate while saving which resources have to be saved.

The problem is, sorting the list in fragement1 does not set isModified to true for fragement2, although there is a reference that has to be updated. If we always save all fragements/resources everything seems to be working. But then we wait about half a minute for the save action to be finished.

Is there a better way than the "if(resource.isModified())" one to prevent that everytime all resources are saved ?
Re: Many Packages and ManyModelFiles -&amp;amp;amp;amp;gt; No Refs Model load [message #911918 is a reply to message #911852] Wed, 12 September 2012 15:29 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Markus,

Comments below.

On 12/09/2012 3:01 PM, Markus Jo wrote:
> Ok, right again.....without EcoreUtil.resolveAll it was not resolved all.
>
> BUT....we used fragments in order to improve the save-action. We use
> resource.isModified (after setting resource.trackModification) to
> evaluate while saving which resources have to be saved.
> The problem is, sorting the list in fragement1 does not set isModified
> to true for fragement2, although there is a reference that has to be
> updated.
Yes, that's why we use Resource.OPTION_SAVE_ONLY_IF_CHANGED because
changes in other resource can affect the way references are saved...
> If we always save all fragements/resources everything seems to be
> working. But then we wait about half a minute for the save action to
> be finished.
>
> Is there a better way than the "if(resource.isModified())" one to
> prevent that everytime all resources are saved ?
Not really. It sounds like you'd have to save every resource that
references this resource with sorted things in it. Is the sorting
really necessary other than to provide a nice view?


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] Opening an EMF editor on a remote CDO repository
Next Topic:Comparing EObjects with EcoreUtils
Goto Forum:
  


Current Time: Thu Apr 25 02:13:25 GMT 2024

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

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

Back to the top