ATL Class2Relational
ATL Class2Relational
TRANSFORMATION EXAMPLE
1.1.1. Metamodels
The Class metamodel (see Figure 1 Class) consists of classes having a name which they inherit from
the abstract class NamedElts. The principal class is the class Class, which contains a set of attributes
of the type Attribute and has the super references pointing to superclasses for modelling inheritance
trees. The class DataType models primitive data types. Class and DataType inherit from Classifier
which serves to declare the type of Attributes. Attributes can be multivalued, which has an important
impact on the transformation.
NamedElt
+name:String
Classifier
+ type
The Relational metamodel (see Figure 2) consists of classes having a name which they inherit from
the abstract class Named. The principal class Table contains a set of Columns and has a reference to
its keys. The class Column has the references owner and keyOf pointing to the Table it belongs to and
of which it is part of the key (in case it is a key). Furthermore, Column has a reference to Type.
____________________________________________________________________________________________________________
Page 1/7
ATL
TRANSFORMATION EXAMPLE
Named
+name:String
+ owner *
{ ordered }
o The col reference set has to contain all Columns that have been created for single-
valued attributes and also the key described in the following.
o The key reference set has to contain a pointer to the key described in the following.
Its type reference has to reference a Type with the name Integer which - if not
yet existing - has to be created.
• For each single-valued Attribute instance of the type DataType, a Column instance has to be
created.
• For each multi-valued Attribute instance of the type DataType, a Table instance has to be
created.
o The Table’s name is the name of the Attribute’s Class concatenated with an
underscore and the name of the Attribute.
o The col reference set has to reference the two Columns described in the following.
____________________________________________________________________________________________________________
Page 2/7
ATL
TRANSFORMATION EXAMPLE
Its name has to be set to the Attribute’s class name concatenated with ‘Id’
Its type reference has to reference a Type with the name Integer which - if not
yet existing - has to be created.
• For each single-valued Attribute of the type Class, a new Column has to be created.
o Its name has to be set to the attribute’s name concatenated with ‘id’.
o Its type reference has to reference a Type with the name Integer which - if not yet
existing - has to be created.
• For each multi-valued Attribute of the type Class, a new Table has to be created.
o The Table’s name is the name of the Attribute’s Class concatenated with an
underscore and the name of the Attribute.
o The col reference set has to reference the two Columns described in the following.
Its name has to be set to the Attribute’s class name concatenated with ‘Id’.
Its type reference has to reference a Type with the name Integer which - if not
yet existing - has to be created.
Its name has to be set to the Attribute’s name concatenated with ‘Id’.
Its type reference has to reference a Type with the name Integer which - if not
yet existing - has to be created.
module Class2Relational;
create OUT : Relational from IN : Class;
____________________________________________________________________________________________________________
Page 3/7
ATL
TRANSFORMATION EXAMPLE
uses strings;
rule Class2Table {
from
c : Class!Class
to
out : Relational!Table (
name <- c.name,
-- Columns are generated from Attributes in another rule not
-- explicitly called here !
col <- Sequence {key}->
union(c.attr->select(e | not e.multiValued)),
key <- Set {key}
),
key : Relational!Column (
name <- 'objectId',
type <- thisModule.objectIdType
)
}
rule DataType2Type {
from
dt : Class!DataType
to
out : Relational!Type (
name <- dt.name
)
}
rule SingleValuedDataTypeAttribute2Column {
from
a : Class!Attribute (
a.type.oclIsKindOf(Class!DataType) and not a.multiValued
)
to
out : Relational!Column (
name <- a.name,
type <- a.type
-- explicit use of implicit tracking links
-- (first expected syntax, then present actual syntax)
-- owner <- [Class2Type.key]a.owner
-- owner <- thisModule.resolveTemp(a.owner, 'key')
)
}
____________________________________________________________________________________________________________
Page 4/7
ATL
TRANSFORMATION EXAMPLE
rule MultiValuedDataTypeAttribute2Column {
from
a : Class!Attribute (
a.type.oclIsKindOf(Class!DataType) and a.multiValued
)
to
out : Relational!Table (
name <- a.owner.name + '_' + a.name,
col <- Sequence {id, value}
),
id : Relational!Column (
name <- a.owner.name.firstToLower() + 'Id',
type <- thisModule.objectIdType
),
value : Relational!Column (
name <- a.name,
type <- a.type
)
}
rule ClassAttribute2Column {
from
a : Class!Attribute (
a.type.oclIsKindOf(Class!Class) and not a.multiValued
)
to
out : Relational!Column (
name <- a.name + 'Id',
type <- thisModule.objectIdType
)
}
rule MultiValuedClassAttribute2Column {
from
a : Class!Attribute (
a.type.oclIsKindOf(Class!Class) and a.multiValued
)
to
out : Relational!Table (
name <- a.owner.name + '_' + a.name,
col <- Sequence {id, foreignKey}
),
id : Relational!Column (
name <- a.owner.name.firstToLower() + 'Id',
type <- thisModule.objectIdType
),
foreignKey : Relational!Column (
name <- a.name + 'Id',
type <- thisModule.objectIdType
)
}
____________________________________________________________________________________________________________
Page 5/7
ATL
TRANSFORMATION EXAMPLE
package Sample {
datatype String;
datatype Integer;
class Family {
attribute name : String;
attribute members[*] : Person;
}
class Person {
attribute firstName : String;
attribute closestFriend : Person;
attribute emailAddresses[*] : String;
}
}
table Person {
primary column objectId : Integer;
column firstName : String;
column closestFriendId : Integer;
}
table Family_members {
column familyId : Integer;
column membersId : Integer;
}
table Person_emailAddresses {
column personId : Integer;
column emailAddresses : String;
}
table Family {
primary column objectId : Integer;
column name : String;
}
____________________________________________________________________________________________________________
Page 6/7
ATL
TRANSFORMATION EXAMPLE
References
[1] Lawley, M., Duddy, K., Gerber, A., Raymond, K. Language Features for Re-Use and Maintainability of
MDA Transformations. OOPSLA & GPCE Workshop, 2004
____________________________________________________________________________________________________________
Page 7/7