1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
module Class2Relational;
create OUT : Relational from IN : Class;
-- inheritance not supported yet
-- issue: choose an object-id Type (Integer, String?).
-- We choose Integer here, assuming this type is defined in the source model.
-- global variable
-- context
helper def: objectIdType : Relational!Type =
Class!DataType.allInstances()->select(e | e.name = 'Integer')->first();
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 DataTypeAttribute2Column {
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')
)
}
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 + '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
foreignKey : Relational!Column (
name <- a.name + 'Id',
type <- thisModule.objectIdType
)
}
rule MultiValuedClassAttribute2Column {
from
a : Class!Attribute (
a.type.oclIsKindOf(Class!Class) and a.multiValued
)
to
t : Relational!Table (
name <- a.owner.name + '_' + a.name,
col <- Sequence {id, foreignKey}
),
id : Relational!Column (
name <- a.owner.name + 'Id',
type <- thisModule.objectIdType
),
foreignKey : Relational!Column (
name <- a.name + 'Id',
type <- thisModule.objectIdType
)
}
|