Skip to content

Query driven soft interconnection of EMF models (MODELS12)

Anett Kiss edited this page Nov 5, 2015 · 10 revisions

######Tags:EMF-IncQuery example publication

We demonstrate how the incremental query evaluation of EMF-IncQuery can be used to maintain soft interconnections between EMF models stored even if they are stored separately, moved or modified without the all the corresponding models loaded at all times.


The interconnection of complex EMF-based system models imposes several technical problems due to the identification strategies of model elements in the EMF infrastructure. When serializing a model, a model element is either identified by a unique identifier generated by EMF, or by a relative path of containment hierarchy in the given EMF resource. These techniques are used when interconnecting models using associations (EReferences) e.g. for internal traceability purposes: the target end of the association points to an object resided in a different model resource. Such interconnections are also used in external traceability scenarios where inter-model links are introduced from traceability metamodel elements to existing metamodels which cannot be altered.

These scenarios demonstrate various shortcomings of the core EMF technology. First, (1) interconnected EMF model fragments with circular dependencies cannot be serialized. Furthermore, without truly intelligent multi-resource transaction management, (2) local changes in a model fragment may introduce broken links (and consequent runtime exceptions) unless all dependent model fragments are manipulated together in working memory. Such broken links require tool-specific resolutions --- with a worst case scenario of fixing the links manually by the designer using text editors (and not the modeling tool). Finally, (3) all traceability links captured by associations are explicitly persisted every time even if traceability links could be derived from existing unique identifiers.

Query-driven soft interconnections can overcome these challenges and due to the high performance of the EMF-IncQuery engine (see our Performance page), it can be applied in industry tools that handle models with millions of model elements. For example, in AUTOSAR the references between elements are defined in a way that only identifiers are stored and the references are created based on these. Our approach would be an elegant and efficient solution for managing the actual references between the elements using query-driven soft links

For more details on the approach, we suggest that readers to check out the complete paper.

###Obtaining the example

  1. Install EMF-IncQuery as described here.
  2. Import the derivedModels, derivedModels.edit, derivedModels.editor, derivedTest, derivedTest.validation projects from the attached archive.

a. Alternatively, you can check out the projects from (see Generating the EMF-IncQuery code)


####Used EMF metamodels

The process metamodel describes simplified business processes including activities (either tasks or gateways).

The system metamodel represents a set of jobs and data objects which are related to the tasks in processes.

The operation metamodel defines checklists which are connected to processes and contain menu and entry elements. Entries refer to tasks in the process of the checklist and jobs in the system model, while they also contain some runtime information as well. The runtime information is also referenced from the job connected to the entry.

####Soft links between the models

  • System model
    • Job.tasks (refers to the Task in a Process model with the id included in the stored taskIds) and info (refers to an info that is contained by a checklist entry that refers this Job). Note that the definition of the soft link uses an other soft link (
@QueryBasedFeature(feature = "tasks")
pattern JobTaskCorrespondence(Job : Job, Task : Task) = {

@QueryBasedFeature(feature = "info")
pattern JobInfoCorrespondence(Job : Job, Info : RuntimeInformation) = {, Info);, Job);
  • Data.writingTask and readingTask (both refer to Tasks in a Process model with the ids included in the stored taskIds)
@QueryBasedFeature(feature = "readingTask")
pattern DataTaskReadCorrespondence(Data : Data, Task : Task) = {

@QueryBasedFeature(feature = "writingTask")
pattern DataTaskWriteCorrespondence(Data : Data ,Task : Task) = {
  • Operation model
    • Checklist.process (refers to a process with the id stored in processId)
@QueryBasedFeature(feature = "process")
pattern ChecklistProcessCorrespondence(Checklist : Checklist, Process : Process) = {,ProcessId);
  • ChecklistEntry.task (refers to the Task in a Process model with the id included in the stored taskId) and jobs (since the elements in the System model do not have unique identifiers, the name of the Job and the name of the System that contains it are used as a path)
@QueryBasedFeature(feature = "jobs")
pattern ChecklistEntryJobCorrespondence(CLE : ChecklistEntry, Job : Job) = {,JobName);,SysName);
 check((JobPath as String).equals((SysName as String).concat('/').concat(JobName as String)));

@QueryBasedFeature(feature = "task")
pattern ChecklistEntryTaskCorrespondence(CLE : ChecklistEntry, Task : Task) = {, TaskId);

###Loading models including query-based soft links

  1. Make sure to start a runtime Eclipse with each project included (derivedModels, derivedModels.edit, derivedModels.editor, derivedTest, derivedTest.validation).

a. Alternatively, you can install these plugins into the host Eclipse using "Export -> Deployable plugins and fragments -> Install into host".

  1. Check out the derivedModels.example project from into the workspace. The project contians 4 separate EMF models, which have no direct references to each other. This can be checked by opening one in it's own generated editor, or in the "Sample Reflective Ecore Model Editor". Referenced resources are loaded lazily, so you have to select each element to ensure that no other models are loaded (the models contain less than 10 elements each).
  2. First, open Simple.system in the "Sample Reflective Ecore Model Editor", navigate to the Job1 or Data elements. Note that the various task ids fields are set, but the tasks fields are not. These derived features will only have a value when the tasks they refer to are loaded.

  1. Next, use the "Load resource" menu, "Browse workspace", and select Simple.process, then press "OK" twice to load the EMF model into the editor. This model contains the tasks corresponding to the ids used by the soft links.

  1. Similarly, if you load the Simple.operation resource, the field will be set, since the loaded operation model contains an entry that references Job1 using the name of the System that contains it and the name of Job1 as a path.

  1. Note, that you can move the files anywhere in the workspace (even in the file system), it won't break the soft links, since they are backed by queries that are evaluated on the loaded models and use information that doesn't depend on the location of the file. Similarly, you can also rename the files without affecting the soft links.

###Validation of soft links

Since the soft-links are computed from attributes that use simple data type values, it is best to have integrated validation that can indicate broken links or links that violate some requirements. For example, the checklist entry refers to a task that is not part of the process that the checklist refers to:

@Constraint(location = "ChecklistEntry",
 message = "Entry $$ corresponds to Task $$ outside of process $$ defined for the checklist!",
 severity = "error")
pattern IncorrectEntryInChecklist(ChecklistEntry,Task,Process) = {
 find ChecklistProcessCorrespondence(Checklist,Process);
 find ChecklistEntryTaskCorrespondence(ChecklistEntry,Task);
 neg find TaskInProcess(Task,Process);

Simply by adding the @Constraint annotation, the relevant source code is automatically generated. You can initialize the validation in the local menu of the "Sample Reflective Ecore Model Editor" (-> EMF-IncQuery -> Initialize EMF-IncQuery validators)

Check out our example for more details on the validation framework.

###Developing soft links

####Overview of the framework

To support soft links captured as derived features, the outputs of the EMF-IncQuery engine need to be integrated into the EMF model access layer at two points: (1) query results are provided in the getter functions of derived features, and (2) query result deltas are processed to generate EMF Notification objects that are passed through the standard EMF API so that application code can process them transparently.

The application accesses both the model and the query results through the standard EMF model access layer -- hence, no modification of application source code is necessary. In the background, our novel soft link handlers are attached to the EMF model plugin that integrate the generated query components (pattern matchers).

When an EMF application intends to read a soft link (B1), the current value is provided by the corresponding handler (B2) by simply retrieving the value from the cache of the related query. When the application modifies the EMF model (A1), this change is propagated to the generated query components of \incquery{} along notifications (A2), which may update the delta monitors of the handlers (A3). Changes of soft links and derived features may in turn trigger further changes in the results sets of other derived features (A4).

####Definition of soft links in the metamodel

First, the soft-links are defined in the metamodels using features with the following configuration:

  • derived = true (to indicate that the value of the feature is computed from the model)
  • changeable = false (to remove setter methods)
  • transient = true (to avoid persisting the value into file)
  • volatile = true (to remove the field declaration in the object)

Next, the model code is generated and you can start preparing the query to back the derived feature. For defining derived features using queries, see our derived features example.

####Generating the code

  1. Check out the derivedModels, derivedModels.edit, derivedModels.editor, derivedTest, derivedTest.validation projects from Git into an Eclipse with EMF-IncQuery installed.
  2. If the src-gen folder in the derivedTest project is empty, invoke the code generation of EMF-IncQuery by selecting Project -> Clean from the menu.
  3. The glue code for initializing matchers and retrieving values from the handlers are automatically generated based on the @DerivedFeature annotations, as described in the linked example.

Attachment: Source code of the example

Clone this wiki locally
You can’t perform that action at this time.