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 |
Markus Jo 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 #911268 is a reply to message #911262] |
Tue, 11 September 2012 09:16 |
Ed Merks 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 #911820 is a reply to message #911810] |
Wed, 12 September 2012 11:33 |
Ed Merks 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 #911918 is a reply to message #911852] |
Wed, 12 September 2012 15:29 |
Ed Merks 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/
|
|
|
Goto Forum:
Current Time: Thu Apr 25 02:13:25 GMT 2024
Powered by FUDForum. Page generated in 0.04670 seconds
|