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

Properties

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

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