/[volute]/trunk/projects/theory/snapdm/res/intermediate2ddl.xsl
ViewVC logotype

Contents of /trunk/projects/theory/snapdm/res/intermediate2ddl.xsl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 219 - (show annotations)
Tue Apr 15 06:23:24 2008 UTC (12 years, 7 months ago) by gerard.lemson
File MIME type: application/xml
File size: 5192 byte(s)
Committing resources dealing with generation of intermediate and DDLs.
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3 This XSLT script transforms a data model from our
4 interediate representation to a relational database
5 Data Definition Language script.
6
7 It depends on our assumed object-relational mapping
8 prescription and should be compatible with the persistence
9 framework used for example in the Java/JPA generation.
10
11 We also generate view definitions representing each objectType.
12
13 We assume that all tables are in a single schema.
14 For now we assume that objectType's names are unique over the complete model.
15 TODO We need to check this explicitly and modify the generation if not.
16
17 -->
18
19 <!DOCTYPE stylesheet [
20 <!ENTITY cr "<xsl:text>
21 </xsl:text>">
22 <!ENTITY bl "<xsl:text> </xsl:text>">
23 <!ENTITY tab "<xsl:text> </xsl:text>">
24 ]>
25
26 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
27
28
29 <xsl:output method="text" encoding="UTF-8" indent="yes" />
30
31 <xsl:output name="packageInfo" method="html" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
32
33 <xsl:strip-space elements="*" />
34
35 <xsl:param name="xmlLastModified"/>
36 <xsl:param name="xslLastModified"/>
37
38
39 <xsl:param name="schema"/> <!-- select="'SNAP.'" -->
40
41
42 <xsl:variable name="lastModified">
43 <xsl:choose>
44 <xsl:when test="number(/model/lastModifiedDate) > number($xslLastModified)"><xsl:value-of select="/model/lastModifiedDate"/></xsl:when>
45 <xsl:otherwise><xsl:value-of select="$xslLastModified"/></xsl:otherwise>
46 </xsl:choose>
47 </xsl:variable>
48
49 <xsl:variable name="defaultVarcharLength" select="'256'"/>
50
51
52 <xsl:template match="/">
53 <xsl:apply-templates select="model"/>
54 </xsl:template>
55
56
57
58
59 <xsl:template match="model">
60 <xsl:message>Model = <xsl:value-of select="name"></xsl:value-of></xsl:message>
61
62
63 -- last modification date of the UML model <xsl:value-of select="$lastModified"/>&cr;
64
65 <xsl:apply-templates select=".//objectType[not(extends)]" mode="singleTable"/>
66 </xsl:template>
67
68
69
70
71 <xsl:template match="objectType" mode="singleTable">
72 <!-- generate a single table for the whole object hierarchy below the matched objectType -->
73 <xsl:variable name="tableName" select="name" />
74
75 CREATE TABLE <xsl:value-of select="$tableName"/> (
76 id bigint NOT NULL
77 <xsl:apply-templates select="." mode="hierarchy"/>
78 );&cr;&cr;
79 </xsl:template>
80
81
82
83
84
85 <xsl:template match="objectType" mode="hierarchy">
86 <xsl:variable name="xmiid" select="@xmiid"/>
87
88 -- fields from <xsl:value-of select="name"/>
89 <xsl:apply-templates select="attribute" />
90 <xsl:apply-templates select="reference" />
91 <xsl:apply-templates select="/model//objectType[extends/datatype/@xmiidref = $xmiid]" mode="hierarchy"/>
92 </xsl:template>
93
94
95
96 <xsl:template match="attribute" >
97 <xsl:choose>
98 <xsl:when test="datatype/@class">
99 <xsl:apply-templates select="." mode="complex"/>
100 </xsl:when>
101 <xsl:otherwise>
102 <xsl:apply-templates select="." mode="simple"/>
103 </xsl:otherwise>
104 </xsl:choose>
105 </xsl:template>
106
107
108
109 <xsl:template match="attribute" mode="simple">
110 ,&cr;&bl;&bl;<xsl:value-of select="name"/>&bl;<xsl:apply-templates select="datatype" mode="sqltype"/><xsl:if test="multiplicity = '1'"> not null</xsl:if>
111 </xsl:template>
112
113
114
115 <!-- We need lengths for (var)char datatypes -->
116 <xsl:template match="datatype" mode="sqltype">
117 <xsl:choose>
118 <xsl:when test="@type = 'boolean'">bit</xsl:when>
119 <xsl:when test="@type = 'p_boolean'">bit</xsl:when>
120 <xsl:when test="@type = 'integer'">integer</xsl:when>
121 <xsl:when test="@type = 'p_integer'">integer</xsl:when>
122 <xsl:when test="@type = 'long'">bigint</xsl:when>
123 <xsl:when test="@type = 'p_long'">bigint</xsl:when>
124 <xsl:when test="@type = 'datetime'">dateTime</xsl:when>
125 <xsl:when test="@type = 'real'">float</xsl:when>
126 <xsl:when test="@type = 'p_real'">float</xsl:when>
127 <xsl:when test="@type = 'double'">real</xsl:when>
128 <xsl:when test="@type = 'p_double'">real</xsl:when>
129 <xsl:otherwise>
130 <xsl:variable name="length">
131 <xsl:choose>
132 <xsl:when test="@length">
133 <xsl:value-of select="@length"/>
134 </xsl:when>
135 <xsl:otherwise>
136 <xsl:value-of select="$defaultVarcharLength"/>
137 </xsl:otherwise>
138 </xsl:choose>
139 </xsl:variable>
140 varchar(<xsl:value-of select="$length"/>)
141 </xsl:otherwise>
142 </xsl:choose>
143 </xsl:template>
144
145
146
147
148 <xsl:template match="reference">
149 <xsl:if test="not(subsets)">
150 ,&cr; <xsl:value-of select="name"/>Id&bl;bigint<xsl:if test="multiplicity = '1'"> not null</xsl:if>
151 </xsl:if>
152 </xsl:template>
153
154
155
156 <!-- TODO
157 Add templates retrieving for a given objectType the table it is in
158 for a given attribute the column(s) it is in
159 for a given reference the column it is in
160 for a given collection the containerId column it is in.
161 -->
162
163
164 </xsl:stylesheet>

msdemlei@ari.uni-heidelberg.de
ViewVC Help
Powered by ViewVC 1.1.26