O'Reilly logo

Model-Driven Software Development: Technology, Engineering, Management by Bettina von Stockfleth, Krzysztof Czarnecki, Simon Helsen, Arno Haase, Jorn Bettin, Markus Völter, Thomas Stahl

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A

Model Transformation Cod

A.1 Complete QVT Relations alma2db Example

transformation alma2db(alma : AlmaMM, db : DbMM) {
 
   /* keys are required to avoid duplication in the target
      repository on iterative runs. */
 
   /* tables are solely identified by their names. */
   key Table {name};
   /* for a column, its name as well as its container, i.e. a table,
      uniquely identify a column. */
   key Column {table, name};
   /* a key is uniquely determined by its owner, which is the table. */
   key Key {table}
   /* a foreign key is identified by its owner (the table), as well as the primary key it is
      referring to. */
   key ForeignKey{table, key}
 
   /******************************/
   /* Mapping entities to tables */
   /******************************/
 
   /* Each entity has a corresponding db table with the same name */
   top relation EntityToTable {
      prefix, eName : String;
 
   checkonly domain alma entity:Entity {
      name = eName
   };
   enforce domain db table:Table {
      name = eName
   };
   where {
      /* For each entity and associated table, we calculate
        all columns that correspond to the different fields of
        the entity. Since we flatten out all nested fields, we
        need to make sure all created columns get a unique name.
        This is achieved by the prefix. */
      prefix = “;
      RecordToColumns(entity, table, prefix);
   }
}
/* For each field of a record, several columns may be created
   depending on the type ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required