/[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 358 - (show annotations)
Fri May 2 06:20:01 2008 UTC (12 years, 7 months ago) by gerard.lemson
File MIME type: application/xml
File size: 9585 byte(s)
Update to put configuration properties (here eclipseLink.jdbc parameters) in build.properties.
TODO do same for the names of models etc.
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 <!-- Configuraiton parameters, set in build.properties -->
19 <xsl:param name="eclipseLink.jdbc.url"/>
20
21 <xsl:param name="eclipseLink.jdbc.user"/>
22 <xsl:param name="eclipseLink.jdbc.password"/>
23
24 <xsl:param name="eclipseLink.jdbc.driver"/>
25 <xsl:param name="eclipseLink.jdbc.read-connections.min"/>
26 <xsl:param name="eclipseLink.jdbc.read-connections.max"/>
27 <xsl:param name="eclipseLink.jdbc.write-connections.min"/>
28 <xsl:param name="eclipseLink.jdbc.write-connections.max"/>
29
30
31
32 <xsl:key name="element" match="*//*" use="@xmiid"/>
33
34
35
36 <xsl:template match="objectType|dataType" mode="JPAAnnotation">
37 <xsl:variable name="className" select="name" />
38 <xsl:variable name="childMod">
39 <xsl:choose>
40 <xsl:when test="count(//extends/*[@class = $className]) > 0">1</xsl:when>
41 <xsl:otherwise>0</xsl:otherwise>
42 </xsl:choose>
43 </xsl:variable>
44 <xsl:variable name="extMod">
45 <xsl:choose>
46 <xsl:when test="count(extends) = 1">1</xsl:when>
47 <xsl:otherwise>0</xsl:otherwise>
48 </xsl:choose>
49 </xsl:variable>
50 <xsl:variable name="hasName">
51 <xsl:choose>
52 <xsl:when test="count(attribute[name = 'name']) > 0">1</xsl:when>
53 <xsl:otherwise>0</xsl:otherwise>
54 </xsl:choose>
55 </xsl:variable>
56
57 @Entity
58 @Table(name="<xsl:apply-templates select="." mode="tableName"/>")
59 <xsl:if test="$childMod = 1">
60 <!-- JOINED strategy for inheritance -->
61 @Inheritance(strategy=InheritanceType.JOINED)
62 @DiscriminatorColumn(name="<xsl:value-of select="$discriminatorColumnName"/>", discriminatorType=DiscriminatorType.STRING, length=<xsl:value-of select="$discriminatorColumnLength"/>)
63 </xsl:if>
64 <xsl:if test="$extMod = 1">
65 @DiscriminatorValue("<xsl:apply-templates select="$className"/>") <!-- TODO decide whether this should be a path -->
66 </xsl:if>
67
68 @NamedQueries( {
69 @NamedQuery(name = "<xsl:apply-templates select="$className"/>.findById", query = "SELECT o FROM <xsl:apply-templates select="$className"/> o WHERE o.id = :id")
70 <xsl:if test="$hasName = 1">
71 , @NamedQuery(name = "<xsl:apply-templates select="$className"/>.findByName", query = "SELECT o FROM <xsl:apply-templates select="$className"/> o WHERE o.name = :name")
72 </xsl:if>
73 } )
74 </xsl:template>
75
76
77
78
79
80 <!-- work in progress -->
81
82
83
84 <!-- TODO check whether type is complex or simple -->
85 <xsl:template match="attribute" mode="JPAAnnotation">
86 <xsl:variable name="type" select="key('element', datatype)"/>
87
88 <xsl:choose>
89 <xsl:when test="name($type) = 'primitiveType'">
90 <xsl:if test="$type/name = 'datetime'">
91 @Temporal(TemporalType.TIMESTAMP)
92 </xsl:if>
93 @Column(name="<xsl:apply-templates select="." mode="columnName"/>")
94 </xsl:when>
95 <xsl:otherwise>
96 @Transient
97 </xsl:otherwise>
98 </xsl:choose>
99 <!--
100 <xsl:choose>
101 <xsl:when test="@type">
102 </xsl:when>
103 <xsl:otherwise>
104 @Embedded
105 @AttributeOverrides({
106 <xsl:apply-templates select="attribute" mode="JPAAnnotation_embedded"/>
107 })
108 </xsl:otherwise>
109 </xsl:choose>
110 -->
111 </xsl:template>
112
113
114 <xsl:template match="reference" mode="JPAAnnotation">
115 @ManyToOne
116 <!-- @Column(name="<xsl:apply-templates select="." mode="columnName"/>") -->
117 </xsl:template>
118
119
120
121
122 <xsl:template match="collection" mode="JPAAnnotation">
123 @Transient
124 <!-- @Column(name="<xsl:apply-templates select="." mode="columnName"/>") -->
125 </xsl:template>
126
127
128
129
130
131
132
133
134
135
136
137
138
139 <!-- work in progress : begin -->
140
141
142 <xsl:template match="attribute" mode="JPAAnnotation_embedded">
143 <xsl:param name="prefix"/>
144 <xsl:apply-templates select="key('types',@xmiid)/attribute" mode="JPAAnnotation_embedded">
145 <xsl:with-param name="prefix" select="name"/>
146 </xsl:apply-templates>
147 </xsl:template>
148
149
150 <!--
151 <xsl:template match="dataType" mode="JPAAnnotation">
152 @Embeddable
153 </xsl:template>
154 -->
155
156
157 <xsl:template match="dataType" mode="JPAAnnotation_embedded">
158 @AttributeOverride
159 </xsl:template>
160
161
162
163 <!--
164 <xsl:template match="enumeration" mode="JPAAnnotation">
165 @Embeddable
166 </xsl:template>
167 -->
168
169 <!-- work in progress : end -->
170
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 <!-- open file for global jpa configuration -->
186 <xsl:message >Opening file <xsl:value-of select="$file"/></xsl:message>
187 <xsl:result-document href="{$file}" format="persistenceInfo">
188 <persistence version="1.0"
189 xmlns="http://java.sun.com/xml/ns/persistence"
190 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
191 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
192 &cr;
193 &cr;
194 <persistence-unit name="SnapDbPU" transaction-type="RESOURCE_LOCAL">
195 <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
196 &cr;
197 &cr;
198 <xsl:comment>generated JPA entities</xsl:comment>
199 &cr;
200 &cr;
201 <xsl:for-each select="package">
202 <xsl:call-template name="packageJpaConfig">
203 <xsl:with-param name="path" select="$root_package"/>
204 </xsl:call-template>
205 </xsl:for-each>
206 &cr;
207 <xsl:comment>JPA Properties</xsl:comment>
208 &cr;
209 &cr;
210 <properties>
211
212 <!--
213 <property name="eclipselink.ddl-generation" value="create-tables"/>
214 -->
215 <!-- local -->
216 <property name="eclipseLink.jdbc.url">
217 <xsl:attribute name="value" select="$eclipseLink.jdbc.url"/>
218 </property>
219 <property name="eclipseLink.jdbc.user">
220 <xsl:attribute name="value" select="$eclipseLink.jdbc.user"/>
221 </property>
222 <property name="eclipseLink.jdbc.password">
223 <xsl:attribute name="value" select="$eclipseLink.jdbc.password"/>
224 </property>
225 <property name="eclipseLink.jdbc.driver">
226 <xsl:attribute name="value" select="$eclipseLink.jdbc.driver"/>
227 </property>
228 <property name="eclipseLink.jdbc.read-connections.min">
229 <xsl:attribute name="value" select="$eclipseLink.jdbc.read-connections.min"/>
230 </property>
231 <property name="eclipseLink.jdbc.read-connections.max">
232 <xsl:attribute name="value" select="$eclipseLink.jdbc.read-connections.max"/>
233 </property>
234 <property name="eclipseLink.jdbc.write-connections.min">
235 <xsl:attribute name="value" select="$eclipseLink.jdbc.write-connections.min"/>
236 </property>
237 <property name="eclipseLink.jdbc.write-connections.max">
238 <xsl:attribute name="value" select="$eclipseLink.jdbc.write-connections.max"/>
239 </property>
240 &cr;
241 &cr;
242 <xsl:comment>
243 SQL Log :
244 OFF - disable logging
245 SEVERE - Logs exceptions indicating eclipseLink cannot continue, as well as any exceptions generated during login. This includes a stack trace.
246 WARNING - Logs exceptions that do not force eclipseLink to stop, including all exceptions not logged with severe level. This does not include a stack trace.
247 INFO - Logs the login/logout per sever session, including the user name. After acquiring the session, detailed information is logged.
248 CONFIG - Logs only login, JDBC connection, and database information.
249 FINE - Logs SQL.
250 FINER - Similar to warning. Includes stack trace.
251 FINEST - Includes additional low level information.
252 </xsl:comment>
253 &cr;
254 &cr;
255 <property name="eclipseLink.logging.level" value="INFO"/>
256 &cr;
257 &cr;
258 <xsl:comment> cache : NONE, Full, HardWeak, SoftWeak, Weak : </xsl:comment>
259 &cr;
260 &cr;
261 <property name="eclipseLink.cache.size.default" value="5000"/>
262 <property name="eclipseLink.cache.type.default" value="HardWeak"/>
263 <property name="eclipseLink.cache.shared.default" value="true"/>
264 &cr;
265 &cr;
266 <xsl:comment> entity cache : NONE, Full, HardWeak, SoftWeak, Weak : </xsl:comment>
267 &cr;
268 &cr;
269 <property name="eclipseLink.cache.type.Cardinality" value="Full"/>
270 <property name="eclipseLink.cache.type.DataType" value="Full"/>
271 </properties>
272 </persistence-unit>
273 </persistence>
274 </xsl:result-document>
275 </xsl:template>
276
277
278
279
280 <xsl:template name="packageJpaConfig">
281 <xsl:param name="path"/>
282
283 <xsl:variable name="newpath">
284 <xsl:choose>
285 <xsl:when test="$path">
286 <xsl:value-of select="concat($path,'.',name)"/>
287 </xsl:when>
288 <xsl:otherwise>
289 <xsl:value-of select="name"/>
290 </xsl:otherwise>
291 </xsl:choose>
292 </xsl:variable>
293
294 <xsl:message>package = <xsl:value-of select="$newpath"></xsl:value-of></xsl:message>
295
296 <xsl:for-each select="objectType|dataType">
297 <xsl:element name="class" namespace="http://java.sun.com/xml/ns/persistence">
298 <xsl:value-of select="$newpath"/><xsl:text>.</xsl:text><xsl:value-of select="name"/>
299 </xsl:element>
300 </xsl:for-each>
301
302 <xsl:for-each select="package">
303 <xsl:call-template name="packageJpaConfig">
304 <xsl:with-param name="path" select="$newpath"/>
305 </xsl:call-template>
306 </xsl:for-each>
307 </xsl:template>
308
309
310 </xsl:stylesheet>

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