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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 360 - (show annotations)
Mon May 5 18:18:10 2008 UTC (12 years, 6 months ago) by bourges.laurent
File MIME type: application/xml
File size: 7535 byte(s)
runtime properties are given in properties/jpa-config.properties (jdbc.url, username, password, database)
persistence.xml is generated from an xml template in res/persistence.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <!DOCTYPE stylesheet [
4 <!ENTITY cr "<xsl:text>
5 </xsl:text>">
6 <!ENTITY bl "<xsl:text> </xsl:text>">
7 ]>
8
9 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
10
11 <!--
12 Common templates used by XSLT scripts
13 -->
14 <xsl:import href="common-ddl.xsl"/>
15
16 <xsl:output name="persistenceInfo" method="xml" encoding="UTF-8" indent="yes" />
17
18
19 <!-- Configuraiton parameters, set in build.properties -->
20 <xsl:param name="eclipseLink.jdbc.url"/>
21
22 <xsl:param name="eclipseLink.jdbc.user"/>
23 <xsl:param name="eclipseLink.jdbc.password"/>
24
25 <xsl:param name="eclipseLink.jdbc.driver"/>
26 <xsl:param name="eclipseLink.jdbc.read-connections.min"/>
27 <xsl:param name="eclipseLink.jdbc.read-connections.max"/>
28 <xsl:param name="eclipseLink.jdbc.write-connections.min"/>
29 <xsl:param name="eclipseLink.jdbc.write-connections.max"/>
30
31
32
33 <xsl:key name="element" match="*//*" use="@xmiid"/>
34
35
36
37 <xsl:template match="objectType|dataType" mode="JPAAnnotation">
38 <xsl:variable name="className" select="name" />
39 <xsl:variable name="childMod">
40 <xsl:choose>
41 <xsl:when test="count(//extends/*[@class = $className]) > 0">1</xsl:when>
42 <xsl:otherwise>0</xsl:otherwise>
43 </xsl:choose>
44 </xsl:variable>
45 <xsl:variable name="extMod">
46 <xsl:choose>
47 <xsl:when test="count(extends) = 1">1</xsl:when>
48 <xsl:otherwise>0</xsl:otherwise>
49 </xsl:choose>
50 </xsl:variable>
51 <xsl:variable name="hasName">
52 <xsl:choose>
53 <xsl:when test="count(attribute[name = 'name']) > 0">1</xsl:when>
54 <xsl:otherwise>0</xsl:otherwise>
55 </xsl:choose>
56 </xsl:variable>
57
58 @Entity
59 @Table(name="<xsl:apply-templates select="." mode="tableName"/>")
60 <xsl:if test="$childMod = 1">
61 <!-- JOINED strategy for inheritance -->
62 @Inheritance(strategy=InheritanceType.JOINED)
63 @DiscriminatorColumn(name="<xsl:value-of select="$discriminatorColumnName"/>", discriminatorType=DiscriminatorType.STRING, length=<xsl:value-of select="$discriminatorColumnLength"/>)
64 </xsl:if>
65 <xsl:if test="$extMod = 1">
66 @DiscriminatorValue("<xsl:apply-templates select="$className"/>") <!-- TODO decide whether this should be a path -->
67 </xsl:if>
68
69 @NamedQueries( {
70 @NamedQuery(name = "<xsl:apply-templates select="$className"/>.findById", query = "SELECT o FROM <xsl:apply-templates select="$className"/> o WHERE o.id = :id")
71 <xsl:if test="$hasName = 1">
72 , @NamedQuery(name = "<xsl:apply-templates select="$className"/>.findByName", query = "SELECT o FROM <xsl:apply-templates select="$className"/> o WHERE o.name = :name")
73 </xsl:if>
74 } )
75 </xsl:template>
76
77
78
79
80
81 <!-- work in progress -->
82
83
84
85 <!-- TODO check whether type is complex or simple -->
86 <xsl:template match="attribute" mode="JPAAnnotation">
87 <xsl:variable name="type" select="key('element', datatype)"/>
88
89 <xsl:choose>
90 <xsl:when test="name($type) = 'primitiveType'">
91 <xsl:if test="$type/name = 'datetime'">
92 @Temporal(TemporalType.TIMESTAMP)
93 </xsl:if>
94 @Column(name="<xsl:apply-templates select="." mode="columnName"/>")
95 </xsl:when>
96 <xsl:otherwise>
97 @Transient
98 </xsl:otherwise>
99 </xsl:choose>
100 <!--
101 <xsl:choose>
102 <xsl:when test="@type">
103 </xsl:when>
104 <xsl:otherwise>
105 @Embedded
106 @AttributeOverrides({
107 <xsl:apply-templates select="attribute" mode="JPAAnnotation_embedded"/>
108 })
109 </xsl:otherwise>
110 </xsl:choose>
111 -->
112 </xsl:template>
113
114
115 <xsl:template match="reference" mode="JPAAnnotation">
116 @Transient
117 <!-- @Column(name="<xsl:apply-templates select="." mode="columnName"/>") -->
118 </xsl:template>
119
120
121
122
123 <xsl:template match="collection" mode="JPAAnnotation">
124 @Transient
125 <!-- @Column(name="<xsl:apply-templates select="." mode="columnName"/>") -->
126 </xsl:template>
127
128
129
130
131
132
133
134
135
136
137
138
139
140 <!-- work in progress : begin -->
141
142
143 <xsl:template match="attribute" mode="JPAAnnotation_embedded">
144 <xsl:param name="prefix"/>
145 <xsl:apply-templates select="key('types',@xmiid)/attribute" mode="JPAAnnotation_embedded">
146 <xsl:with-param name="prefix" select="name"/>
147 </xsl:apply-templates>
148 </xsl:template>
149
150
151 <!--
152 <xsl:template match="dataType" mode="JPAAnnotation">
153 @Embeddable
154 </xsl:template>
155 -->
156
157
158 <xsl:template match="dataType" mode="JPAAnnotation_embedded">
159 @AttributeOverride
160 </xsl:template>
161
162
163
164 <!--
165 <xsl:template match="enumeration" mode="JPAAnnotation">
166 @Embeddable
167 </xsl:template>
168 -->
169
170 <!-- work in progress : end -->
171
172
173
174
175
176
177
178
179
180
181 <!-- persistence.xml configuration file -->
182
183 <xsl:template match="model" mode="jpaConfig">
184 <xsl:variable name="file" select="'META-INF/persistence.xml'"/>
185
186 <!-- reading persistence-template.xml file : -->
187
188 <xsl:variable name="jpaConf" select="document('./persistence.xml')"/>
189
190 <!-- open file for global jpa configuration -->
191 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
192 <xsl:result-document href="{$file}" format="persistenceInfo">
193
194 <xsl:apply-templates select="$jpaConf" mode="otherXml">
195 <xsl:with-param name="model" select="."/>
196 </xsl:apply-templates>
197
198 </xsl:result-document>
199 </xsl:template>
200
201
202
203
204 <xsl:template match="@*|node()" mode="otherXml">
205 <xsl:param name="model"/>
206
207 <xsl:choose>
208 <xsl:when test="name() = 'properties'">
209 &cr;
210 &cr;
211 <xsl:comment>generated JPA entities</xsl:comment>
212 &cr;
213 &cr;
214 <xsl:for-each select="$model/package">
215 <xsl:call-template name="packageJpaConfig">
216 <xsl:with-param name="package" select="."/>
217 <xsl:with-param name="path" select="$root_package"/>
218 </xsl:call-template>
219 </xsl:for-each>
220 &cr;
221 &cr;
222 <xsl:comment>JPA Properties</xsl:comment>
223 &cr;
224 &cr;
225 <xsl:element name="properties" namespace="http://java.sun.com/xml/ns/persistence">
226
227 <xsl:apply-templates select="child::*" mode="otherXml"/>
228
229 &cr;
230 &cr;
231 <xsl:comment>
232 &lt;property name="eclipseLink.cache.type.Cardinality" value="Full"/&gt;
233 &lt;property name="eclipseLink.cache.type.DataType" value="Full"/&gt;
234 </xsl:comment>
235
236 </xsl:element>
237
238 </xsl:when>
239 <xsl:otherwise>
240 <xsl:copy>
241 <xsl:apply-templates select="@*|node()" mode="otherXml">
242 <xsl:with-param name="model" select="$model"/>
243 </xsl:apply-templates>
244 </xsl:copy>
245 </xsl:otherwise>
246 </xsl:choose>
247
248 </xsl:template>
249
250
251
252
253 <xsl:template name="packageJpaConfig">
254 <xsl:param name="package"/>
255 <xsl:param name="path"/>
256
257 <xsl:variable name="newpath">
258 <xsl:choose>
259 <xsl:when test="$path">
260 <xsl:value-of select="concat($path,'.',$package/name)"/>
261 </xsl:when>
262 <xsl:otherwise>
263 <xsl:value-of select="$package/name"/>
264 </xsl:otherwise>
265 </xsl:choose>
266 </xsl:variable>
267
268 <xsl:message>package = <xsl:value-of select="$newpath"></xsl:value-of></xsl:message>
269
270 <xsl:for-each select="$package/objectType|$package/dataType">
271 <xsl:element name="class" namespace="http://java.sun.com/xml/ns/persistence">
272 <xsl:value-of select="$newpath"/><xsl:text>.</xsl:text><xsl:value-of select="name"/>
273 </xsl:element>
274 </xsl:for-each>
275
276 <xsl:for-each select="$package/package">
277 <xsl:call-template name="packageJpaConfig">
278 <xsl:with-param name="package" select="."/>
279 <xsl:with-param name="path" select="$newpath"/>
280 </xsl:call-template>
281 </xsl:for-each>
282 </xsl:template>
283
284
285 </xsl:stylesheet>

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