Edapt doesn't do specialize reference type while ecore migration changes [message #1802396] |
Fri, 08 February 2019 06:00 |
Arun Kumar Messages: 14 Registered: January 2016 |
Junior Member |
|
|
I am new to custom edapt migration operation and trying to adapt the edapt migration for below ecore model changes.
I have attribute in one of the Eclass which has the reference to eclass "mapElementClass". Now, my ecore change is that, I made mapElementClass as abstract and created two more sub-class named "mapElementSubClass1" and "mapElementSubClass2" respectively.
I am trying to migrate this model changes with custom migration, and I am performing instance.migrate("ecoreName.mapElementSubClass1"); . After migration performing, in my file, nothing got changed , when I load the file, attribute is vanishing since it still points to abstract class. Hence, I add to manually make below manual changes on that reference element to make it work properly.
xsi:type="com.xxx.yyy.zzz.mapElementSubClass1"
How to make this migration correct? Even, I tried to create 'specialize reference type ' via edapt operation and still it is not working.
MetaModel changes:
<eClassifiers xsi:type="ecore:EClass" name="MappingObjectClass" eSuperTypes="#//SomeClass">
....
<eStructuralFeatures xsi:type="ecore:EReference" name="attrElement" lowerBound="1"
eType="#//mapElementClass"/>
</eClassifiers>
== Added two sub-type class. This is the model changes ==
<eClassifiers xsi:type="ecore:EClass" name="mapElementSubClass1" eSuperTypes="#//mapElementClass">
.... <some attribute definition>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="mapElementSubClass2" eSuperTypes="#//mapElementClass">
.... <some attribute definition>
</eClassifiers>
I might be doing something wrong here. I get struck at this point and any help would be appreciated.
|
|
|
Re: Edapt doesn't do specialize reference type while ecore migration changes [message #1802405 is a reply to message #1802396] |
Fri, 08 February 2019 10:39 |
|
Hi,
If I understand you correctly you want to map all existing mapElementClass-instances in the existing model to mapElementSubClass1? So you don't need to decide whether they should become mapElementSubClass1 or mapElementSubClass2?
So the easiest way starting from your old model is:
Create mapElementSubClass1 and mapElementSubClass2 as subclasses of mapElementClass using the "Create Class" operation from the operation browser.
Now select mapElementClass in and chose the "Make Class Abstract"-Operation and chose mapElementSubClass1 as a subclass in the parameters tab. This will replace existing instances with elements of the chosen subclass.
Cheers,
Johannes
Johannes Faltermeier
Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
|
|
|
|
|
Re: Edapt doesn't do specialize reference type while ecore migration changes [message #1802868 is a reply to message #1802511] |
Mon, 18 February 2019 11:01 |
|
Hi,
Actually a custom migration should work as follows.
Create the Subclasses as above. Instead of using the Make-Abstract-Operation, make the class abstract in the ecore editor. Then in the history, right click to recorded change -> Edapt -> Attach Custom Migration to Changes.
In the custom migration in migrateAfter (i.e, the MapElementClass is abstract now) use the Instance#migrate method after identifying which EClass to use.
public class MyCustomMigration extends CustomMigration {
@Override
public void migrateAfter(Model model, Metamodel metamodel) throws MigrationException {
model.getAllInstances("packageName.MapElementClass")// get all old instances
.forEach(i -> i.migrate(findOutWhichSubClassToUse(i, metamodel)));
}
private EClass findOutWhichSubClassToUse(Instance i, Metamodel metamodel) {
// decide which subclass to use
return metamodel.getEClass("packageName.MapElementSubClass1"); //$NON-NLS-1$
}
}
Cheers,
Johannes
Johannes Faltermeier
Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
|
|
|
|
Powered by
FUDForum. Page generated in 0.03983 seconds