/[volute]/trunk/projects/theory/snapdm/res/common-ddl.xsl
ViewVC logotype

Contents of /trunk/projects/theory/snapdm/res/common-ddl.xsl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 422 - (show annotations)
Thu May 8 16:52:53 2008 UTC (12 years, 6 months ago) by gerard.lemson
File MIME type: application/octet-stream
File size: 5815 byte(s)
Started work on properly (?) mapping embedded datatypes.
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
4
5 <!--
6 Common templates used by XSLT scripts
7 -->
8 <!-- possible values: postgres, mssqlserver -->
9 <xsl:param name="vendor" select="'mssqlserver'"/>
10
11 <!-- Define parameters/variables that can be reused in this script an in others using it (JPA) -->
12 <!-- next two might also be parameters, or obtained from a config file -->
13 <xsl:variable name="defaultVarcharLength" select="'256'"/>
14 <xsl:variable name="unboundedstringtype" select="'text'"/> <!-- SQLServer specific but supported by postgres -->
15
16 <xsl:variable name="discriminatorColumnName" select="'DTYPE'"/>
17 <xsl:variable name="discriminatorColumnLength" select="'32'"/>
18
19 <xsl:variable name="discriminatorColumnType"> varchar(<xsl:value-of select="$discriminatorColumnLength"/>) </xsl:variable>
20
21 <xsl:variable name="primaryKeyColumnName" select="'ID'"/>
22
23
24
25
26 <!-- for now no special camelcase 2 '_' transformation -->
27 <xsl:template match="objectType|dataType|enumeration" mode="tableName">
28 <xsl:value-of select="name"/>
29 </xsl:template>
30
31
32
33 <!-- for now no special camelcase 2 '_' transformation -->
34 <xsl:template match="objectType" mode="viewName">
35 <xsl:value-of select="concat('v_',name)"/>
36 </xsl:template>
37
38
39
40 <!--
41 Return the column name for a single attribute, assumed to be primitive
42 Currently nothing special done, simply returns the name of the attribute.
43 -->
44 <xsl:template match="attribute" mode="columnName">
45 <xsl:value-of select="name"/>
46 </xsl:template>
47
48
49
50 <!--
51 Return a node-set of columns for a single attribute, which may be structured
52 -->
53 <xsl:template match="attribute" mode="columns">
54 <xsl:param name="prefix"/>
55 <xsl:param name="attrprefix"/>
56
57 <xsl:variable name="columnname">
58 <xsl:choose>
59 <xsl:when test="$prefix">
60 <xsl:value-of select="concat($prefix,'_',name)"/>
61 </xsl:when>
62 <xsl:otherwise>
63 <xsl:value-of select="name"/>
64 </xsl:otherwise>
65 </xsl:choose>
66 </xsl:variable>
67 <xsl:variable name="attrname">
68 <xsl:choose>
69 <xsl:when test="attrprefix">
70 <xsl:value-of select="concat($attrprefix,'.',name)"/>
71 </xsl:when>
72 <xsl:otherwise>
73 <xsl:value-of select="name"/>
74 </xsl:otherwise>
75 </xsl:choose>
76 </xsl:variable>
77 <xsl:variable name="type" select="key('element',datatype/@xmiidref)"/>
78
79 <xsl:choose>
80 <xsl:when test="name($type) = 'primitiveType' or name($type) = 'enumeration'">
81 <xsl:variable name="sqltype">
82 <xsl:call-template name="sqltype">
83 <xsl:with-param name="type" select="$type"/>
84 <xsl:with-param name="constraints" select="constraints"/>
85 </xsl:call-template>
86 </xsl:variable>
87 <column>
88 <attrname><xsl:value-of select="$attrname"/></attrname>
89 <name><xsl:value-of select="$columnname"/></name>
90 <type><xsl:value-of select="$type/name"/></type>
91 <sqltype><xsl:value-of select="$sqltype"/></sqltype>
92 <xsl:copy-of select="constraints"/>
93 <xsl:copy-of select="multiplicity"/>
94 </column>
95 </xsl:when>
96 <xsl:otherwise>
97 <xsl:for-each select="$type/attribute">
98 <xsl:apply-templates select="." mode="columns">
99 <xsl:with-param name="prefix" select="$columnname"/>
100 <xsl:with-param name="attrprefix" select="name"/>
101 </xsl:apply-templates>
102 </xsl:for-each>
103 </xsl:otherwise>
104 </xsl:choose>
105
106 </xsl:template>
107
108
109
110
111 <!-- return the column name a reference is mapped to -->
112 <xsl:template match="reference" mode="columnName">
113 <xsl:value-of select="concat(name,'Id')"/>
114 </xsl:template>
115
116
117
118
119
120 <!-- We need lengths for (var)char datatypes -->
121 <xsl:template name="sqltype">
122 <xsl:param name="type"/>
123 <xsl:param name="constraints"/>
124
125 <!--
126 Primitive types :
127 boolean
128 short
129 int
130 long
131 float
132 double
133
134 Date type :
135 datetime
136
137 Characters type :
138 string
139
140 Unsupported type (later) => string :
141 complex
142 rational
143 -->
144 <xsl:choose>
145 <xsl:when test="$type/name = 'boolean'">bit</xsl:when>
146 <xsl:when test="$type/name = 'short'">integer</xsl:when>
147 <xsl:when test="$type/name = 'integer'">integer</xsl:when>
148 <xsl:when test="$type/name = 'long'">bigint</xsl:when>
149 <xsl:when test="$type/name = 'float'">float</xsl:when>
150 <xsl:when test="$type/name = 'double'">real</xsl:when>
151 <xsl:when test="$type/name = 'datetime'">
152 <xsl:choose>
153 <xsl:when test="$vendor = 'mssqlserver'">datetime</xsl:when>
154 <xsl:otherwise>timestamp</xsl:otherwise>
155 </xsl:choose>
156 </xsl:when>
157 <xsl:otherwise>
158 <xsl:variable name="length">
159 <xsl:choose>
160 <xsl:when test="$constraints/length">
161 <xsl:value-of select="$constraints/length"/>
162 </xsl:when>
163 <xsl:when test="$constraints/maxLength">
164 <xsl:value-of select="$constraints/maxLength"/>
165 </xsl:when>
166 <xsl:otherwise>
167 <xsl:value-of select="$defaultVarcharLength"/>
168 </xsl:otherwise>
169 </xsl:choose>
170 </xsl:variable>
171 <xsl:choose>
172 <xsl:when test="$length &lt;= 0"><xsl:value-of select="$unboundedstringtype"/></xsl:when>
173 <xsl:otherwise>varchar(<xsl:value-of select="$length"/>)</xsl:otherwise>
174 </xsl:choose></xsl:otherwise>
175 </xsl:choose>
176 </xsl:template>
177
178
179
180
181
182 </xsl:stylesheet>

Properties

Name Value
svn:mime-type application/octet-stream

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