The key concept can be simulated in some cases by the use of additional relations. Consider the case where two UML classes "A1" and "A2" specialize a common abstract super class "A". If an attribute att 1 is modeled in "A" and a forward transformation is performed, then this attribute should be transformed to a column in tables "A1" and "A2". Conversely, if a column att2 is modeled in tables "A1" and "A2" and a backward transformation is performed, then only one attribute att2 is expected in class "A".
To achieve the backward transformation, we need to simulate the key of an attribute composed of its class and name. Otherwise two attributes will be created in class "A" with the same name att2 . The following script excerpt realizes such a transformation.
transformation umlToRdbms(uml:SimpleUML, rdbms:SimpleRDBMS) { /* Other relations are omitted */ relation PrimitiveAttribute2Column { theName: String; checkonly domain uml c:UMLClass { attributes=a:UMLAttribute { name=theName, } }; enforce domain rdbms t:Table { columns=cl:Column { name=theName } }; primitive domain prefix:String; when { if Element2ElementOwnerAndName(a, c, theName) then true else true endif; } where { Element2ElementOwnerAndName(a, c, theName); } } relation Element2ElementOwnerAndName { enforce domain uml element: UMLModelElement{}; enforce domain rdbms elementOwner: UMLModelElement{}; primitive domain elementName: String; } }For the first att2 column from table "A1", the Element2ElementOwnerAndName("a", "c", theName) call in the when-clause will fail because Element2ElementOwnerAndName is non top-level and has not yet been invoked from any where-clause. However the "when" clause evaluates to true because of the "else" branch so that a new attribute is created which together with the class and name form a binding as a result of the where-clause evaluation. When the second att2 column from table "A2" is transformed, the Element2ElementOwnerAndName("a", "c", theName) binds the already created attribute to "a". Therefore no new attribute is created when evaluating the target domain.
![]() |
Note |
---|---|
This simulation is not applicable to all cases where the "key" concept should apply. For example, assuming the key of a package is its name, if a package is transformed to a schema, deleted, then re-created with the same name and then retransformed, the first schema will be deleted and a new one will be created. Note however that this approach may be more powerful than the key concept in some case, since complex OCl expressions may serve as keys while the key concept itself only allows properties of the given metamodel class to form a key for this class. |