Skip to content

2020_m2m

Gábor Bergmann edited this page Apr 27, 2020 · 4 revisions

Model-to-model transformation

The task

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.

Workflow

Environment setup

Required Plug-ins Install

First, we have to install some plug-ins, if these are not installed already.

  • 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

Setup language projects

  1. Start with an empty Eclipse workspace: close or remove (no need to delete from disk) every project from existing workspace

  2. Git clone https://github.com/ftsrg/mdsd-examples

  3. Fetch all tags and checkout m2m-2020-phase1

    • On the Eclipse EGit GUI:
      1. Switch to the Git perspective, find the repository in the git repositories view (add if clone via the command line)
      2. Right click the repository, Remote > Fetch...
      3. Hit next, press Add All Tags Spec, and Finish.
      4. Under the repository, right click 1.0.2019 and issue Create Branch.
      5. 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
  4. 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)
  5. 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

    ▶ Watch the video ▶

Setup transformation projects

  1. 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.)

  2. 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
  3. After clean&build, there should be no compiler errors.

  4. 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.

    ▶ Watch the video ▶

Setup user environment

  1. Import example project hu.bme.mit.mdsd.erdiagram.examplediagrams from the Git working copy.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

    ▶ Watch the video ▶

Exercises

  1. 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
  2. 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 and m2m-2020-phase2 for solutions.

References and further reading

Lab material

MDSD 2021

MDSD 2020

MDSD 2019

(Gradually replaced with updated content)

MDSD 2018

MDSD 2017

MDSD 2016

MDSD 2015

MDSD 2014

System Integration 2014

Clone this wiki locally