/[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 435 - (show annotations)
Fri May 9 16:17:58 2008 UTC (13 years ago) by gerard.lemson
File MIME type: application/octet-stream
File size: 5854 byte(s)
Views do not have v_ in front of their names, tables have t_ as prefix. The views are the public interface to the world.
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 <xsl:variable name="IDDatatype" select="'NUMERIC(18)'"/>
23
24
25
26
27 <!-- for now no special camelcase 2 '_' transformation -->
28 <xsl:template match="objectType" mode="tableName">
29 <xsl:value-of select="concat('t_',name)"/>
30 </xsl:template>
31
32
33
34 <!-- for now no special camelcase 2 '_' transformation -->
35 <xsl:template match="objectType" mode="viewName">
36 <xsl:value-of select="name"/>
37 </xsl:template>
38
39
40
41 <!--
42 Return the column name for a single attribute, assumed to be primitive
43 Currently nothing special done, simply returns the name of the attribute.
44 -->
45 <xsl:template match="attribute" mode="columnName">
46 <xsl:value-of select="name"/>
47 </xsl:template>
48
49
50
51 <!--
52 Return a node-set of columns for a single attribute, which may be structured
53 -->
54 <xsl:template match="attribute" mode="columns">
55 <xsl:param name="prefix"/>
56 <xsl:param name="attrprefix"/>
57
58 <xsl:variable name="columnname">
59 <xsl:choose>
60 <xsl:when test="$prefix">
61 <xsl:value-of select="concat($prefix,'_',name)"/>
62 </xsl:when>
63 <xsl:otherwise>
64 <xsl:value-of select="name"/>
65 </xsl:otherwise>
66 </xsl:choose>
67 </xsl:variable>
68 <xsl:variable name="attrname">
69 <xsl:choose>
70 <xsl:when test="attrprefix">
71 <xsl:value-of select="concat($attrprefix,'.',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="type" select="key('element',datatype/@xmiidref)"/>
79
80 <xsl:choose>
81 <xsl:when test="name($type) = 'primitiveType' or name($type) = 'enumeration'">
82 <xsl:variable name="sqltype">
83 <xsl:call-template name="sqltype">
84 <xsl:with-param name="type" select="$type"/>
85 <xsl:with-param name="constraints" select="constraints"/>
86 </xsl:call-template>
87 </xsl:variable>
88 <column>
89 <attrname><xsl:value-of select="$attrname"/></attrname>
90 <name><xsl:value-of select="$columnname"/></name>
91 <type><xsl:value-of select="$type/name"/></type>
92 <sqltype><xsl:value-of select="$sqltype"/></sqltype>
93 <xsl:copy-of select="constraints"/>
94 <xsl:copy-of select="multiplicity"/>
95 </column>
96 </xsl:when>
97 <xsl:otherwise>
98 <xsl:for-each select="$type/attribute">
99 <xsl:apply-templates select="." mode="columns">
100 <xsl:with-param name="prefix" select="$columnname"/>
101 <xsl:with-param name="attrprefix" select="name"/>
102 </xsl:apply-templates>
103 </xsl:for-each>
104 </xsl:otherwise>
105 </xsl:choose>
106
107 </xsl:template>
108
109
110
111
112 <!-- return the column name a reference is mapped to -->
113 <xsl:template match="reference" mode="columnName">
114 <xsl:value-of select="concat(name,'Id')"/>
115 </xsl:template>
116
117
118
119
120
121 <!-- We need lengths for (var)char datatypes -->
122 <xsl:template name="sqltype">
123 <xsl:param name="type"/>
124 <xsl:param name="constraints"/>
125
126 <!--
127 Primitive types :
128 boolean
129 short
130 int
131 long
132 float
133 double
134
135 Date type :
136 datetime
137
138 Characters type :
139 string
140
141 Unsupported type (later) => string :
142 complex
143 rational
144 -->
145 <xsl:choose>
146 <xsl:when test="$type/name = 'boolean'">bit</xsl:when>
147 <xsl:when test="$type/name = 'short'">integer</xsl:when>
148 <xsl:when test="$type/name = 'integer'">integer</xsl:when>
149 <xsl:when test="$type/name = 'long'">bigint</xsl:when>
150 <xsl:when test="$type/name = 'float'">float</xsl:when>
151 <xsl:when test="$type/name = 'double'">real</xsl:when>
152 <xsl:when test="$type/name = 'datetime'">
153 <xsl:choose>
154 <xsl:when test="$vendor = 'mssqlserver'">datetime</xsl:when>
155 <xsl:otherwise>timestamp</xsl:otherwise>
156 </xsl:choose>
157 </xsl:when>
158 <xsl:otherwise>
159 <xsl:variable name="length">
160 <xsl:choose>
161 <xsl:when test="$constraints/length">
162 <xsl:value-of select="$constraints/length"/>
163 </xsl:when>
164 <xsl:when test="$constraints/maxLength">
165 <xsl:value-of select="$constraints/maxLength"/>
166 </xsl:when>
167 <xsl:otherwise>
168 <xsl:value-of select="$defaultVarcharLength"/>
169 </xsl:otherwise>
170 </xsl:choose>
171 </xsl:variable>
172 <xsl:choose>
173 <xsl:when test="$length &lt;= 0"><xsl:value-of select="$unboundedstringtype"/></xsl:when>
174 <xsl:otherwise>varchar(<xsl:value-of select="$length"/>)</xsl:otherwise>
175 </xsl:choose></xsl:otherwise>
176 </xsl:choose>
177 </xsl:template>
178
179
180
181
182
183 </xsl:stylesheet>

Properties

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

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