-
Notifications
You must be signed in to change notification settings - Fork 1
2021_m2m
In this laboratory, we will learn to develop event-driven model transformations through an example. This transformation will create (and then incrementally update while active) a relational database schema from any entity relationship model.
First, we have to install some plug-ins, if these are not installed already. The example codebase was tested with:
- Eclipse Modeling 2019-12
- EMF - Eclipse Modeling Framework SDK 2.20.0
- Ecore Tools 3.3.2
- Xtend 2.20
- Sirius 6.3.0
- VIATRA 2.3.0
- EGit 5.6.0
-
Start with an empty Eclipse workspace: close or remove (no need to delete from disk) every project from existing workspace
-
Git clone https://github.com/ftsrg/mdsd-examples
-
Fetch all tags and checkout
m2m-2020-phase1
- On the Eclipse EGit GUI:
- Switch to the Git perspective, find the repository in the git repositories view (add if clone via the command line)
- Right click the repository, Remote > Fetch...
- Hit next, press Add All Tags Spec, and Finish.
- Under the repository, right click
1.0.2019
and issue Create Branch. - Name the branch as
m2m
and make sure the "Check out new branch" box is checked.
- Or on the command line:
git fetch --all --tags && git checkout tags/m2m-2020-phase1 -b m2m
- On the Eclipse EGit GUI:
-
Import the following metamodel / language development projects (but NOT the other projects):
- hu.bme.mit.mdsd.erdiagram - erdiagram ecore project (i.e. the source metamodel)
- hu.bme.mit.mdsd.erdiagram.design - erdiagram Sirius-based editor definition
- hu.bme.mit.mdsd.rdb - rdb ecore project (i.e. the target metamodel)
- hu.bme.mit.mdsd.rdb.design - rdb Sirius-based editor definition
- hu.bme.mit.mdsd.trace - trace ecore project (i.e. the correspondence / traceability metamodel)
-
There are some initial compile errors; all of them should be resolved by locating the
.genmodel
files and issueing "Generate all" in the following order:- hu.bme.mit.mdsd.erdiagram/model/erdiagram.ecore
- hu.bme.mit.mdsd.rdb/model/rdb.ecore
- hu.bme.mit.mdsd.trace/model/trace.ecore
-
Start the runtime Eclipse, and close or remove (no need to delete from disk) every project from its existing workspace. (Note: continuing in the host Eclipse is possible, but the VQL editor would be very slow in that case due to operating on metamodels developed in the same workspace.)
-
Import transformation projects:
- hu.bme.mit.mdsd.m2m2c - the core model-to-model transformation code
- hu.bme.mit.mdsd.m2m2c.ui - user interface bindings to invoke said transformation
-
After clean&build, there should be no compiler errors.
-
Create new "Eclipse Application" lauch configuration, name it e.g. "RuntimeEclipse2", specify a workspace folder (e.g.
${workspace_loc}/../runtime2-workspace
) and launch it. Ensure workspace is empty.
-
Import example project
hu.bme.mit.mdsd.erdiagram.examplediagrams
from the Git working copy. -
Switch to the Modeling perspective. In the Model Explorer, expand the source model file (
My.erdiagram
), right-click the root model element, and issue "Prepare EDT". This will initialize the rdb schema and trace model files. -
Make sure that both the ERD and the RDB instance model have Sirius diagrams (if missing, right click > new representation). Open both diagrams side-by-side.
-
Again in the Model Explorer, right-click the root model element, and issue "Start EDT". See the model transformation in action: after a short delay due to loading, there will be model elements created in the target model.
-
From the toolbar of the target model (RDB) diagram, use the first two buttons (Select All, and then Arrange) to make Sirius try to layout the diagram. See that each Entity has an associated Table with a matching name, but Attributes have not been mapped yet (although the Table will have an automatically generated default key column, if the corresponding Entity has no attributes with isKey=true). Likewise, is-a links and Relations have not yet been mapped.
-
Confirm that the implemented mappings do work, and the transformation is event-driven: experiment with modifying the source model, and with stopping&restarting the event-driven transformation ("Finish EDT" and "Start EDT" from the context menu of the ERD root model element in the Model Explorer). See also the events logged to the standard out.
- Familiarize yourself with how the transformation is implemented, particularly inspect the most important files:
- both .vql files for the Viatra queries
- ErdToRdbRuleSet.xtend for the actual transformation rules
- TracingHelperUtility.java for helper functions to manipulate the trace model
- CommonHelperMethods.xtend for miscellaneous useful static helper methods that aid the mappings
- ErdToRdbLiveTransformation.xtend for the transformation entry point itself
- Extend the event-driven transformation with the missing aspects (key and non-key attributes, is-a links, relations with endings). Although not necessary, it is permitted to modify the trace metamodel (introduce multiple trace object types, or more kinds of references, or attributes of the trace object), or to introduce priorities for the transformation rules (see commented out lines in ErdToRdbLiveTransformation.xtend). You may peek at tags
m2m-2020-phase2
andm2m-2020-phase3
for solutions.
- Xtend language elements (including templating) - https://eclipse.org/xtend/documentation/203_xtend_expressions.html
- VIATRA Query API - https://www.eclipse.org/viatra/documentation/query-api.html
- VIATRA Transformations API - https://www.eclipse.org/viatra/documentation/transformations.html
- Eclipse basics
- EMF (incl. advanced topics)
- VIATRA Query
- Sirius
- Xtext+Xtend
- M2M
- Eclipse basics
- EMF (incl. advanced topics)
- VIATRA Query
- Sirius
- Xtext
- M2M
(Gradually replaced with updated content)
- Eclipse basics
- EGit
- EMF (incl. advanced topics)
- VIATRA Query
- Sirius
- Xtext
- M2M (VIATRA)
- Eclipse basics
- EGit
- EMF (incl. advanced topics)
- VIATRA Query
- Sirius
- Xtext
- M2M (VIATRA)