Prerequisites

Ensure you have installed Tefkat properly and that you are familiar with creating EMF models.

Getting Started

Create a new Simple project and add folders called "models", "instances", and "transformations".
  • Bring up the new project dialog.
  • Expand "Simple" and select "Project". Click the "Next" button.
  • Give the project a name, say, "transformation". Click the "Finish" button.
  • Bring up the new folder dialog.
  • Name the folder then click the "Finish" button. Repeat for the "instances" and "transformations" folders.

Creating Meta-Models

Create the source and target metamodels "simpleuml.ecore" and "relational.ecore" and save them in the "models" folder.

Creating source instance

simpleuml1.xmi

Creating a simple transformation specification

Create a new file called "uml2rel.qvt" and save it in the "transformations" folder.
This version, "uml2rel2.qvt", is the same transformation but using the alternate object literal syntax.

TRANSFORMATION uml2rel : uml -> rel

NAMESPACE http://simpleuml
NAMESPACE http://relational

  // Produces a Table and Key for each persistent UMLClass.
  //
  RULE Class2Table(c, t, k)
    FORALL  UMLClass c
    WHERE   c.kind = "persistent"
    MAKE    Table t, Key k
    SET     t.name = c.name, t.key = k,
            k.name = c.name
  ;

  // Produces Columns belonging to a Table for
  // each persistent UMLClass with storable Attributes.
  //
  
  RULE Attr2Column(c, a, t, k, col)
  EXTENDS Class2Table(c, t, k)
    FORALL  Attribute a
    WHERE   hasAttr(c, a, n)
    MAKE    Column col FROM c4a(c,a,n)
    SET     col.name = n,
            t.column = col
  ;

  // Immediate Attributes of a UMLClass that are primary have
  // their corresponding Column as part of the Table's Key.
  //
  ABSTRACT
  RULE KeyColumns(c, a, t, k, col)
  EXTENDS Attr2Column(c, a, t, k, col)
    WHERE   a.kind = "primary" AND
	        inhAttr(c, a)
    SET     col.belongsTo = k
  ;

  // An Attribute is "storable" if it is a simple type (PrimitiveDataType),
  // or it is UMLClass-valued and that UMLClass is persistent.
  //
  PATTERN storable(A)
    FORALL Attribute A
    WHERE
	   C = A.type AND
	   (
	       PrimitiveDataType C
	   OR
	       (UMLClass C AND A.type.kind = "persistent")
	   )
  ;


  // A UMLClass "inherits" an Attribute if it owns it directly,
  // or it has a superclass that "inherits" the Attribute.
  //
  // [Note - other's mapping examples ignore this, but what is a
  //  "class" model without inheritance?]
  //
  PATTERN inhAttr(C, A)
    FORALL UMLClass C, Attribute A, UMLClass C2
    WHERE
	  A.owner = C
       OR
	  (C.parents = C2 AND inhAttr(C2, A))
  ;


  // This pattern is used to handle so-called "complex types".
  // A UMLClass "has" and Attribute with a fully qualified name
  // if it "inherits" the attribute and the attribute is storable,
  // or it "inherits" another UMLClass-valued attribute for which the
  // UMLClass is not persistent (ie a complex type) and that UMLClass
  // "has" the attribute.
  //
  // This will cycle if two non-persistent UMLClasses transitively
  // reference each other.
  //
  PATTERN hasAttr(C, A, N)
    FORALL UMLClass C, Attribute A
    WHERE
	  (
	    inhAttr(C, A) AND
	    storable(A) AND
	    A.name = N
	  )
       OR
	  (
	    inhAttr(C, A2) AND
	    A2.type = C2 AND
	    UMLClass C2 AND
	    C2.kind != "persistent" AND
	    hasAttr(C2, A, N2) AND
            N = append(A2.name, append("_", N2))
	  )
  ;

Register Meta-Models

Because we haven't generated code for the meta-models and installed the resulting plugins, we need to tell Tefkat (EMF) where to find the meta-models when the model instances are loaded.
  • Open Eclipse's Preferences and select "Tefkat".
  • Click "Add".
  • Enter the source meta-model's URI (http://simpleuml) in the "URI Source" field and the corresponding file's URI (platform:/resource/transformation/models/simpleuml.ecore) in the "URI Target" field.
  • Repeat for the target meta-model.

Configuring a Transformation

Create a Tefkat Configuration and edit to specify the inputs and outputs for Tefkat to run the transformation.
  • Right-click on the project and select "New>Other..."
  • In "Example EMF Model Creation Wizards" select "TefkatConfig model" and click "Next".
  • Enter the filename a click "Next".
  • In the drop-down for "Model Object" select "Configuration" then click "Finish". The new document shoud open automatically.
  • Click on the disclosure triangle to expose the "Configuration" element.
  • Right-click on the "Configuration" element and select "New Child" -> "Transformation Task".
  • Right-click on the "Transformation Task" element and select "New Child" -> "Transformation Model". Repeat for "Source Models Model", and "Target Models Model".
  • Right-click on the "Transformation Task" element and select "Show Properties View".
  • Select each of "transformation", "sourceModels", and "targetModels", and set their values appropriately in the "Properties View". (Leave the "Var Group" property unset.)
  • Select the "Transformation Task" element and change the value of the "Enabled" property from "false" to "true".
  • Save the document "uml2rel.tefkatconfig".

Running a Transformation

Create an Eclipse launch configuration to run the transformation.
  • In the "Run" menu, open the Run dialog.
  • Select "Tefkat" and create a new launch configuration.
  • Click "Browse..." and naviagte to then choose the previously created Tefkat configuration file, "uml2rel.tefkatconfig".
  • Click "OK" and then click "Run".
Congratulations!