<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>EMF-Syncer solution to T TC'20 round-trip migration case</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Artur Boronat</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>School of Computing and Mathematical Sciences, University of Leicester</institution>
          ,
          <addr-line>University Rd, LE1 7RH, Leicester</addr-line>
          ,
          <country country="UK">United Kingdom</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>In this paper, we present a solution to the TTC'20 ofline case Round-trip migration of object-oriented data model instances [1]. This case involves the application of maintenance tasks to web APIs that are associated with domain models so that updates are backward compatible. The solution presented in this article features the EMF-Syncer [2], a synchronization tool for bridging MDE-agnostic programs and MDE-aware programs, which may have some similarities in their object-oriented data models at run time. EMF-Syncer provides a generic synchronization strategy that exploits such similarities automatically and is, therefore, a suitable candidate for solving the proposed problems, since each problem relies on a small change and there is a large overlap between two versions of the same data model. In the paper, we used the case benchmark framework to justify that our solution exhibits a good balance between specification conciseness and performance.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Model syncing</kwd>
        <kwd>model-driven engineering</kwd>
        <kwd>round-trip engineering</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>
        assumes that MDE-agnostic programs are implemented
in a JVM language and that MDE-aware programs
repreThe Round-trip migration of object-oriented data model sent their data model using EMF-generated code.
instances case [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] for the TTC’20 exposes an evolution Given a source data model (represented in a package
problem in the context of web API development, where of classes in the MDE-agnostic program), a target data
diferent APIs work on top of a common data model. To model (represented as an Ecore model in an EMF-based
accommodate new or changing requirements in the sys- program), and a collection of objects representing the
tem, API designers need to ensure backward-compatible source program state, EMF-Syncer translates the
MDEchanges in the underlying data model. Assuming an agile agnostic objects as an EMF model instance in the target
software development environment where data models EMF-based program, synchronizing the state of both
promay evolve rapidly, the case proposes the use of round- grams at run time. EMF-Syncer automatically infers
trip migration services, relying on Model-Driven Engi- structural similarities between object-oriented data
modneering (MDE) technology, for enabling the co-existence els by mapping object structural features by name, when
of diferent versions of the data model at run time. In found, translating both attribute and reference values.
particular, the Eclipse Modeling Framework (EMF) [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] is This translation can be performed using a push-based
used to encode data models with the EMF meta-modeling model, where the entire source program state is migrated,
language, namely Ecore, so that tools built atop EMF can or using a pull-based model, where only those feature
be used to implement data migration services. values accessed in the target program are migrated. Once
      </p>
      <p>
        The solution presented in this article features the EMF- synchronization is established, changes that have been
Syncer [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], a synchronization tool for bridging MDE- applied to target EMF model instances can be
incremenagnostic programs and MDE-aware programs, which tally back-propagated to the source MDE-agnostic
counmay have some similarities in their object-oriented data terpart. Incrementality of back-migration entails that
models1, at run time. EMF-Syncer provides a generic only changes in target model instances are propagated
synchronization strategy that exploits such similarities back and merged within the source instance.
automatically and is, therefore, a suitable candidate for The aforementioned generic mapping strategy that is
solving the proposed problems, since each problem relies built in EMF-Syncer can be customized in order to allow
on a small change and there is a large overlap between for more complex data transformations between the data
two versions of the same data model. The EMF-Syncer models involved. A domain-specific mapping strategy is
TTC’20: Transformation Tool Contest, Part of the Software declared with a mapping specification that maps a source
Technologies: Applications and Foundations (STAF) federated feature type to a target feature type, possibly including
conferences, Eds. A. Boronat, A. García-Domínguez, G. Hinkel, and F. feature value transformations, either from source to
tarKřikava, 17 July 2020, Bergen, Norway (online). get, or from target to source, or both. Two main custom
" artur.boronat@leicester.ac.uk (A. Boronat) mapping strategies can be declared:
~ https://arturboronat.github.io/ (A. Boronat)
      </p>
      <p>
        0000-0©002032-12C0op2y4rig-h1t7fo3r 6thi(sApa.peBrboyriotsnauathto)rs. Use permitted under Creative • Renaming of feature types: such renamings may
CPWrEooUrckReshdoinpgs 1IhStpWN:/c1e6u1r3-w-0s.o7r3ge rCCeoEmfemUroRntsoLWictehonsereskAestthrdiboaupttioanPm4r.0ooIncdteeerenladstiioannsagl s(dCoC(CmBYEa4U.i0n)R.m-WoSd.eolrsgi)n [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. iasfecdtecthlaerenda,maendoft htheencalmases,owf htheerefethateufreea. tuTrheis
mapping strategy allows for transformations that constructor. All of the solutions use the push-based
modify the data model either syntactically, when model in syncForward, which is specified by indicating
either a class or a feature is renamed in the tar- syncer.syncingStrategy = SyncingStrategy.EAGER,
get model, or structurally, when a feature type is forcing the migration of the entire source instance.
moved to an unrelated object type. In this case, In the method migrate, the statement
feature values are transformed using the generic syncer.syncForward(person_v1) migrates
synchronization strategy. the source Person instance obtaining the target
• Transformation of feature values, with or without instance with the age feature, which is not
initialrenaming of feature types: feature value trans- ized until the statement person_v2.age = -1 is
formations are expressed using Xtend lambda ex- evaluated. In the method migrateBack, the
statepressions defined for a contextual object type, ment syncer.syncBack(person_v2) migrates the
from the source data model, and result in a sin- instance back to the source Java program.
gle target feature value. This mapping strategy The method modify is used to implement changes to
allows for semantic transformations, where the target model instances that need to be propagated back.
feature value can be computed using navigation This logic is hardcoded in test cases in the benchmark
expressions from the contextual type. A feature framework. EMF-Syncer needs to track which changes
value transformation is applied in a single direc- are performed in the target model instance in order to
tion, either from source to target or from target enable incremental back migration. Therefore, this logic
to source. A programmer can opt to provide fea- has been moved from test cases to task classes.
ture value transformations in both directions (as
in Task_2 in §2.2), only in one (as in Task_3 in
§2.3), or none at all. The last case corresponds to
a simple renaming of feature types as explained
above.
      </p>
    </sec>
    <sec id="sec-2">
      <title>2. Solution</title>
      <p>
        The solutions to the diferent tasks of the It is important to note that the bidirectional
transforcase are explained below and are available at mation between both data models is completely inferred
https://github.com/emf-syncer/ttc20-roundtrip. The by the EMF-Syncer automatically in this task. In the
solution has been implemented using the language back migration, as the age feature does not exist in the
Xtend [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. source program, it is not propagated.
      </p>
      <sec id="sec-2-1">
        <title>The solution to the symmetric problem</title>
        <p>2.1. Task 1: create/delete field Task1_M2_M1_M2 is achieved by inverting the
direction in which the EMF-Syncer is applied to the data
In this task, a new feature age is added to the class models, as seen in the listing below. In this case, the data
Person in the modified data model 2 and when a model M2 is regarded as the Java program and the data
Person instance is migrated, its feature value is set to model M1 as the EMF program. In this case, the value
-1. When the instance is migrated back, this information of the age feature of a Person class is preserved on
is lost. the back migration because this feature does not exist</p>
        <p>The solution Task1_M1_M2_M1, shown in the listing in M1 and, therefore, no changes can be applied to the
below, illustrates the pattern used in all of the solutions. feature age. In the following subsections, solutions to
The EMF-Syncer is used by instantiating the class symmetric problems are achieved by flipping, as for this
EMFSyncer between a source Java package name list task, the direction in which the EMF-Syncer is applied
#[’scenario1_v1’] and a target Ecore model in the and are not included in the paper.</p>
        <sec id="sec-2-1-1">
          <title>2.2. Task 2: rename field</title>
          <p>18 ]
19 )
20
21 new (EPackage model1, EPackage model2) {
22 super(model1, model2);
23 syncer = new EMFSyncer(#[’scenario2_v1’], model2,</p>
          <p>newArrayList(mapping))
syncer.syncingStrategy = SyncingStrategy.EAGER
24
25 }
26
27 override migrate(EObject instance) {
28 val person_v1 = instance as Person
29 return syncer.syncForward(person_v1) as scenario2_v2.Person
30 }
31
32 override migrateBack(EObject instance) {
33 val person_v2 = instance as scenario2_v2.Person
34 return syncer.syncBack(person_v2) as Person
35 }
36
37 override modify(EObject instance) { }
38 }
gets a Person instance from the source data model and
returns the ybirth value. When the EMF-Syncer
applies the transformation syncForward, the feature value
In this task, the feature age of the class Person is
re2.3. Task 3: declare field
named to ybirth, and its semantics is changed by
repreoptional/mandatory
senting the age and the year of birth, respectively. This
renaming involves domain-specific semantics that is not In this task, the multiplicity of a feature type is modiefid
present in the Ecore model, requiring a mapping spec- so that the feature is mandatory in one data model and
ification so that the EMF-Syncer can perform the data optional in the modified version. This task exposes a
transformation correctly. diference between a MDE-agnostic program, where it</p>
          <p>A mapping specification consists of a collection of is not possible to know whether a feature is optional in
mappings between feature types by name, ’Person’, plain Java, and a MDE-aware one, where this
informa’age’, /* &lt;–&gt; */ ’Person’, ’ybirth’, and by tion is encoded in the Ecore model. As the EMF-Syncer
adding optional feature value transformations as lambda treats the source program as a plain Java program, it
disreexpressions. For example, in the solution, the lambda gards the information contained in the Ecore model, and
expression the logic to transform null values in to empty Strings
1 val person_v1 = it as scenario2_v1.Person needs to be provided in a custom mapping. The
ex2 Integer.valueOf(Calendar.getInstance().get(Calendar.YEAR) - pression person_v2.name ?: "" returns an empty
person_v1.age) as Object</p>
        </sec>
      </sec>
      <sec id="sec-2-2">
        <title>String when the name of the Person instance is null, which is checked using the Elvis operator ?:. The rest of the data transformation is fully inferred by the EMFSyncer .</title>
        <p>for Person::ybirth will be obtained by applying this
expression. The rest of the solution follows the same
structure as the solution explained in §2.1.
1 class Task_2_M1_M2_M1 extends AbstractTask {
2 val EMFSyncer syncer
3
4 // custom mapping strategy: M1 &lt;--&gt; M2
5 val public static mapping = new EMFSyncerMapping(
6 ’Person’, ’age’, /* &lt;--&gt; */ ’Person’, ’ybirth’,
7 // source to target feature value transformation
8 [
9
10
val person_v1 = it as scenario2_v1.Person
Integer.valueOf(Calendar.getInstance().get(Calendar.YEAR)
person_v1.age) as Object
// target to source feature value transformation
[
val person_v2 = it as scenario2_v2.Person
1 class Task_3_M1_M2_M1 extends AbstractTask {
2 val EMFSyncer syncer
3
4 // custom mapping strategy: M1 &lt;--&gt; M2
5 val public static mapping = new EMFSyncerMapping(
6 ’Person’, ’name’, /* &lt;--&gt; */ ’Person’, ’name’,
7 null,
8 // target to source feature value transformation
9 [
10 val person_v2 = it as scenario3_v2.Person
11 person_v2.name ?: ""
12 ]
13 )
14
15 new (EPackage model1, EPackage model2) {
16 super(model1, model2);
17 syncer = new EMFSyncer(#[’scenario3_v1’], model2,
18 newArrayList(mapping))
19 syncer.syncingStrategy = SyncingStrategy.EAGER
20 }
21
22 override migrate(EObject instance) {
23 val person_v1 = instance as scenario3_v1.Person
24 return syncer.syncForward(person_v1) as Person
25 }
26
27 override migrateBack(EObject instance) {
28 val person_v2 = instance as Person
29 syncer.syncBack(person_v2) as scenario3_v1.Person
30 }
31
32 override modify(EObject instance) {
33 val person_v2 = instance as Person
34 syncer.track[ person_v2.name = null ]
35 return person_v2
36 }
37 }</p>
        <p>This solution also contains an example of how to track
changes performed in the target instance, in the modify
method, that need to be migrated back. This change is
encoded in the corresponding test case in the original
test framework.
2.4. Task 4: multiple edits
framework has been adapted in order to work with code
generated from Ecore models via EMF, which is required
by EMF-Syncer . The main properties (namely, name,
nsPrefix and nsUri) of the EPackage in each Ecore
model were updated in order to generate disjoint
namespaces. In test cases, loading resources for each Ecore
model was modified in order to use the corresponding
generated factory for each model instance. Model
instances, used as input/output data, were modified to
refer to the corresponding nsUri. In some cases, the test
case also performs a change in the target instance, as in</p>
      </sec>
      <sec id="sec-2-3">
        <title>Task_3, that needs to be propagated back to the source</title>
        <p>instance. Such modifications have been encoded in the
task itself, in the method modify, as the EMF-Syncer
needs to track those changes. Such changes refer to
implementation details and do not alter the correctness
properties checked2 by the test suite.</p>
      </sec>
      <sec id="sec-2-4">
        <title>Solutions for all of the tasks have been implemented</title>
        <p>and all of them pass the correctness check.</p>
      </sec>
      <sec id="sec-2-5">
        <title>This task combines Task_1 and Task_2 with the aim</title>
        <p>of analysing reuse mechanisms that can be employed. 3.2. Comprehensibility</p>
      </sec>
      <sec id="sec-2-6">
        <title>The solution below reuses the transformation logic of</title>
        <p>Task_1, as it is handled by the EMF-Syncer automati- Task solutions have been implemented using Xtend.
cally, and it reuses the mapping specification of Task_2, However, the EMF-Syncer can be used from Java
prowhich is defined as a static field. The rest of the solution is grams as well. Given that the transformation in most
as in §2.1, after renaming the corresponding namespaces. of the solutions is inferred automatically and that
so1 class Task_4_M1_M2_M1 extends AbstractTask { lutions use generated code, instead of using the EMF
2 val EMFSyncer syncer reflection API for accessing/mutating values, we argue
43 new (EPackage model1, EPackage model2) { that solutions are likely to be more comprehensible than
5 super(model1, model2); the reference ones.
76 synnecweArrr=anyeLwisEtM(TFaSsykn_c2e_r(M#1_[’Ms2c_eMn1a.mraipop4i_nvg1’)]), model2, When custom mappings are required, e.g. in Task_2
8 syncer.syncingStrategy = SyncingStrategy.EAGER and in Task_4, these are defined by instantiating the
109 } class EMFSyncerMapping, where feature value
transfor11 override migrate(EObject instance) { mations are defined as Xtend lambda expressions. Such
1123 rveatlucronnstyaninceerr._svy1nc=Fionrswtaarnd(cceonatsasicneenra_rvi1)o4a_sv1s.Ccoennatraiion4e_rv2. mapping expressions could have been defined similarly</p>
        <p>Container in Java as well.
14 }
15
16 override migrateBack(EObject instance) {
17 val container_v2 = instance as scenario4_v2.Container
18 syncer.syncBack(container_v2) as scenario4_v1.Container
19 }
20
21 override modify(EObject instance) { }
22 }</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>3. Evaluation</title>
      <sec id="sec-3-1">
        <title>In this section, we provide an evaluation of the solution according to the evaluation criteria proposed in [1].</title>
        <sec id="sec-3-1-1">
          <title>3.1. Expressiveness</title>
        </sec>
      </sec>
      <sec id="sec-3-2">
        <title>Two test cases are provided for checking the correctness of each task. A test case provides the input for a round-trip migration and the expected output. The test</title>
        <sec id="sec-3-2-1">
          <title>3.3. Bidirectionality</title>
          <p>In the solution for most of the tasks, the EMF-Syncer
infers both transformations to be applied, syncForward
and syncBack, automatically. In such cases, the
programmer does not need to provide a transformation
specification and a bidirectional data transformation is being
used internally so that Java instances can be migrated
to an EMF program, and back again, at run time. A
custom mapping specification containing only feature type
renamings is fully bidirectional. Feature value
transformation expressions are unidirectional though.</p>
        </sec>
      </sec>
      <sec id="sec-3-3">
        <title>Therefore, the EMF-Syncer provides support for bidi</title>
        <p>rectional transformations by default for all of the
solutions and accommodates special cases with unidirectional</p>
      </sec>
      <sec id="sec-3-4">
        <title>2The test case task_3_M1_M2_M1_b had to be updated in or</title>
        <p>der to check that the name was migrated back correctly.
Comprehensibility</p>
        <p>Bidirectionality</p>
        <p>Re-usability</p>
      </sec>
      <sec id="sec-3-5">
        <title>Re-usability is internalized in the EMF-Syncer by infer</title>
        <p>ring transformations automatically. That is, when a user
does not need to provide a mapping specification, the
transformation logic in the EMF-Syncer is reused for
any data model change. For example, reuse of the logic
transformation in Task_1 falls under this category.</p>
      </sec>
      <sec id="sec-3-6">
        <title>On the other hand, as EMF-Syncer is a JVM library, a</title>
        <p>programmer can rely on reuse mechanisms provided by
the JVM language of choice. For example, reuse of the
transformation logic in Task_2 falls under this category.
The mapping specification defined for Task_2 is reused
by calling a static field and by using a common interface
for the class Person, which has been implemented using
inheritance in Task_4.</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>4. Conclusions</title>
      <sec id="sec-4-1">
        <title>Following from the justification of the evaluation criteria</title>
        <p>in the section above, the results are summarized in
Ta3.5. Performance ble 1, where the score  out of  is expressed as ( ).</p>
      </sec>
      <sec id="sec-4-2">
        <title>Overall, this solution shows that the EMF-Syncer helps</title>
        <p>We have run the performance tests both for the refer- in achieving a competitive trade-of between data
migraence solution and for the EMF-Syncer solution on a tion specification and performance. On the one hand, the
MacBookPro11,5 Core i7 2.5 GHz, with four cores and automatic inference of data transformations between
dif16 GB of RAM. The runtime results (in ms.) obtained ferent object-oriented data models reduces the need for
are displayed in Fig. 1. The EMF-Syncer solution ex- specifying data transformations. When these have to be
hibits a linear growth with respect to the number of specified, a programmer can rely on their programming
iterations, as instructed in the case benchmark. However, skills, using a JVM programming language, for reusing
the EMF-Syncer solution is more eficient than the refer- transformation logic. On the other hand, EMF-Syncer
ence one thanks to its support for incremental migration can be used as an eficient data migration service at run
of changes. While the reference solution takes about 31 s. time. For example, the EMF-Syncer solution is faster
for 2 million iterations, the EMF-Syncer solution takes than the reference solution developed in raw Java.
EMFabout 9 s, with an improvement factor of 70%. The in- Syncer can be used for building more scalable solutions,
cremental propagation relies on a traceability model that involving very large models, by using the pull-based
caches relevant data at run time. An analysis of memory model for propagating changes in syncForward only
consumption is left for future work as it was not part of when they are required in the target program.
the case benchmark.</p>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>L.</given-names>
            <surname>Beurer-Kellner</surname>
          </string-name>
          , J. von Pilgrim, T. Kehrer,
          <article-title>RoundTrip Migration of Object-Oriented Data Model Instances, in: Proceedings of the 13th Transformation Tool Contest, a part of the Software Technologies: Applications and Foundations (STAF 2018) federation of conferences</article-title>
          ,
          <source>CEUR Workshop Proceedings, CEUR-WS.org</source>
          ,
          <year>2020</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>A.</given-names>
            <surname>Boronat</surname>
          </string-name>
          ,
          <article-title>Code-first model-driven engineering: On the agile adoption of mde tooling</article-title>
          ,
          <source>in: Proceedings of the 34th IEEE/ACM International Conference on Automated Software Engineering (ASE</source>
          <year>2019</year>
          ), San Diego, CA, November
          <volume>11</volume>
          -15, ACM,
          <year>2019</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>D.</given-names>
            <surname>Steinberg</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Budinsky</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Paternostro</surname>
          </string-name>
          , E. Merks,
          <source>EMF: Eclipse Modeling Framework 2.0</source>
          , 2nd ed.,
          <string-name>
            <surname>Addison-Wesley Professional</surname>
          </string-name>
          ,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>T. E.</given-names>
            <surname>Foundation</surname>
          </string-name>
          ,
          <source>Xtend (oficial web page)</source>
          ,
          <year>2018</year>
          . http://www.eclipse.org/xtend/.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>