Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f8e217f9a350bae2ac33bf32a55b77fc9c44be89 (plain) (blame)
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
-- @nsURI UML=http://www.eclipse.org/uml2/2.1.0/UML
-- @path Relational=/org.eclipse.m2m.atl.tests/data/inputs/Relational2UML/relational.ecore


module Relational2UML2;
create OUT: UML from IN: Relational, PRO: UML;

----------------------------------------------------------------------
-- HELPERS -----------------------------------------------------------
----------------------------------------------------------------------

helper def: stringType: UML!PrimitiveType =
	OclUndefined;

helper def: integerType: UML!PrimitiveType =
	OclUndefined;

helper context Relational!Column def: computeType(): UML!PrimitiveType =
	if self.type = #VARCHAR then
		thisModule.stringType
	else
		if self.type = #NUMERIC then
			thisModule.integerType
		else
			thisModule.integerType
		endif
	endif;

helper def: getStereotype(name: String): UML!Stereotype =
	UML!Stereotype.allInstancesFrom('PRO') -> select(p | p.name = name) -> first();

----------------------------------------------------------------------
-- RULES -------------------------------------------------------------
----------------------------------------------------------------------
rule Database2Model {
	from
		d: Relational!Database
	to
		out: UML!Model (
			name <- d.name,
			packagedElement <- Sequence{d.ownedSchemas,
							integer,
							string} -> flatten()
		),
		integer: UML!PrimitiveType (
			name <- 'Integer'
		),
		string: UML!PrimitiveType (
			name <- 'String'
		)
	do {
		thisModule.stringType <- string;
	    thisModule.integerType <- integer;

	    out.applyProfile(UML!Profile.allInstancesFrom('PRO') -> select(p | p.name =
			'relational') -> first());
	    out.applyStereotype(thisModule.getStereotype('Database'));	
	}
}

rule Schema2Package {
	from
		s: Relational!Schema
	to
		out: UML!Package (
			name <- s.name,
			packagedElement <- s.ownedTables
		)
	do {
		out.applyStereotype(thisModule.getStereotype('Schema')); 
	}
}

rule Table2Class {
	from
		t: Relational!Table
	to
		out: UML!Class (
			name <- t.name,
			ownedAttribute <- t.ownedColumns
		)
	do {
		out.applyStereotype(thisModule.getStereotype('Table')); 
	}
}

rule Column2Property {
	from
		p: Relational!Column
	to
		out: UML!Property (
			name <- p.name,
			isUnique <- p.isUnique,
			type <- p.computeType()
		)
	do {
		out.applyStereotype(thisModule.getStereotype('Column')); 
	}
}

Back to the top