Skip to main content

Translating KM3 into SQL DDL using AMW and ATL - HowTo

This example is a complete bridge between KM3 and SQL DDL (Data Definition Language) that uses injection, extraction, weaving and transformations. It is similar to the example that transforms SQL to KM3, but in the opposite direction.

This example contains a weaving model between a KM3 metamodel and a SQL DDL metamodel. It uses the same metamodel extensions as the ones used to transform SQL into KM3. The weaving model is used to produce an ATL transformation that translates KM3 models into SQL models. We used a KM3 file generated by the example "Translating SQL into KM3".

Most part of the ATL transformation is also used to generate the files of the Atlantic SQL DDL Zoo.


Loading the weaving model into AMW:

The weaving model (models/mw_km3_sqlddl.amw) can be loaded by double-clicking on the file or by using the wizard.

When using the wizard, there are two metamodel extensions that need to be loaded : "mw_base_ext" and "metamodels/mmw_sql_km3". The complete weaving metamodel is saved at metamodels/mmw_sql_km3.ecore
This step is not necessary to execute the transformations.
Left metamodel: metamodels/KM3.ecore.
Right metamodel: metamodels/SQLDDL.ecore.

Executing the transformations

There is an Ant Script (scripts/executeAll.xml) that takes the models/mantis.km3 file, and automatically produces a .SQL file. It executes the following actions:

  • injects the mantis.km3 file into a KM3 model (models/mantis-KM3.ecore) conforming to KM3 metamodel,
  • the weaving model (models/mw_km3_sqlddl.amw) contains links between the metamodels/KM3.ecore metamodel and the metamodels/SQLDDL.ecore metamodel,
  • executes the ATL HOT (hot/AMWtoATL_KM32SQL.atl) that takes the weaving model mw_km3_sqlddl.amw as input and produces the ATL model (output/KM32SQL.ecore) conforming to the ATL metamodel,
  • extracts the ATL model into an ATL file (output/KM32SQL.atl),
  • executes the ATL transformation (KM32SQL.atl). This transformation takes the mantis-KM3.ecore model as input and produces the SQLDDL model (models/mantis-sql.ecore) as output,
  • extracts the SQL model (mantis-sql.ecore) into a SQL file (models/mantis-sql.sql).


  • The HOT and the KM32SQL transformations can be executed separatedly as well. Each transformartion has a predefined "launch configuration" file.
  • There are Ant scripts to execute the injection of .km3 files (KM3Injector.xml) and the extraction of ATL models(ATLExtractor.xml). The files in the scripts/ folder are mandatory files to execute the Ant Scripts.
  • When the ATL model is extracted into KM32SQL.atl, the KM32SQL.asm file is generated by the ATL engine. It is possible that the executeAll.xml script tries to execute the transformation before it is extracted (in the first time the script is executed), causing an error. To solve this issue the script needs to be executed a second time.
  • This example was updated to be compatible with the latest releases and sources of ATL (ATL2006).

Back to the top