-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_db.xml
239 lines (166 loc) · 8.54 KB
/
build_db.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!--
build_db.xml file : specific targets for database management
-->
<!-- presets -->
<!-- Performs an SQL query with the database defined in jpa-config.properties. -->
<presetdef name="doSqlTarget">
<sql classpathref="jdbc-drivers.class.path"
driver="${targetdb.driver}"
url="${targetdb.url}"
userid="${targetdb.admin}"
password="${targetdb.adminpassword}" />
</presetdef>
<presetdef name="doSqlAdminLoadCLOB">
<sql classpathref="jdbc-drivers.class.path"
driver="${admindb.driver}"
url="${admindb.url}"
userid="${admindb.admin}"
password="${admindb.adminpassword}" />
</presetdef>
<presetdef name="doSqlAdminReadCLOB">
<sql classpathref="jdbc-drivers.class.path"
driver="${admindb.driver}"
url="${admindb.url}"
userid="${admindb.admin}"
password="${admindb.adminpassword}" />
</presetdef>
<!-- Performs an SQL query with the admin roles database defined in ${input}/project.properties -->
<presetdef name="doSqlAdmindb">
<sql classpathref="jdbc-drivers.class.path"
driver="${admindb.driver}"
url="${admindb.url}"
userid="${admindb.admin}"
password="${admindb.adminpassword}" />
</presetdef>
<!-- targets -->
<!-- sets DB properties -->
<target name="DB-initFor">
<!-- Get jpa-config properties -->
<property file="${properties}/jpa-config.properties" />
<fail unless="jpa.database" message="Must define property 'jpa.database' in project.properties !" />
<fail unless="targetdb.driver" message="Must define property 'targetdb.driver' in project.properties !" />
<fail unless="targetdb.url" message="Must define property 'targetdb.url' in project.properties !" />
<!-- eclipselink.jdbc.user only used at runtime (read only), but check if exist -->
<fail unless="targetdb.user" message="Must define property 'targetdb.user' in project.properties !" />
<fail unless="targetdb.password" message="Must define property 'targetdb.password' in project.properties !" />
<!-- eclipselink.jdbc.admin used to create/drop tables -->
<fail unless="targetdb.admin" message="Must define property 'targetdb.admin' in project.properties !" />
<fail unless="targetdb.adminpassword" message="Must define property 'targetdb.adminpassword' in project.properties !" />
<!-- tomcat role database -->
<!-- TODO: use eclipselink.* values if tomcat.* values not defined (BUG GERARD) -->
<fail unless="admindb.url" message="Must define property 'admindb.url' in ${input}/project.properties !" />
<!-- admindb.user only used at runtime (read only), but check if exist -->
<fail unless="admindb.user" message="Must define property 'admindb.user' in ${input}/project.properties !" />
<fail unless="admindb.password" message="Must define property 'admindb.password' in ${input}/project.properties !" />
<!-- user used to create/drop tables -->
<fail unless="admindb.admin" message="Must define property 'admindb.admin' in ${input}/project.properties !" />
<fail unless="admindb.adminpassword" message="Must define property 'admindb.adminpassword' in ${input}/project.properties !" />
<!-- sets SQL script directory -->
<condition property="db.vendor" value="postgres/">
<equals arg1="${jpa.database}" arg2="PostgreSQL" trim="true"/>
</condition>
<condition property="db.vendor" value="mssqlserver">
<equals arg1="${jpa.database}" arg2="SQLServer" trim="true"/>
</condition>
<property name="ddl.directory" value="${output}/ddl/${db.vendor}/"/>
<property name="tap.ddl.directory" value="${output}/tap/${db.vendor}/"/>
<!-- no need to check for tap.ddl.directory -->
<condition property="ddl.directory.set">
<isset property="ddl.directory"/>
</condition>
<fail unless="ddl.directory.set" message="unable to define property 'ddl.directory' for the given vendor : ${jpa.database} !" />
<!-- sets SQL separator for CREATE VIEW scrip -->
<condition property="create.view.sep" value=";">
<equals arg1="${jpa.database}" arg2="PostgreSQL" trim="true"/>
</condition>
<condition property="create.view.sep" value="GO">
<equals arg1="${jpa.database}" arg2="SQLServer" trim="true"/>
</condition>
<condition property="create.view.sep.set">
<isset property="create.view.sep"/>
</condition>
<fail unless="create.view.sep.set" message="unable to define property 'create.view.sep' for the given vendor : ${jpa.database} !" />
<echo>JDBC URL : ${targetdb.url}</echo>
<echo>JDBC USER : ${targetdb.admin}</echo>
<echo>DDL HOME : ${ddl.directory}</echo>
</target>
<!-- target checkDB : is database server alive ? -->
<target name="DB-check" depends="DB-initFor" description="check databse properties">
<echo>check target DB : ${targetdb.url} ...</echo>
<echo>admin : ${targetdb.admin}</echo>
<doSqlTarget onerror="abort" print="true">select 1</doSqlTarget>
<echo>check adminDB</echo>
<echo>url : ${admindb.url} ...</echo>
<echo>driver : ${admindb.driver}</echo>
<echo>admin : ${admindb.admin}</echo>
<doSqlAdmindb onerror="abort" print="true">select 1</doSqlAdmindb>
</target>
<target name="DB-clean" depends="DB-retrieveDDLs" >
<echo>cleanDB : drop views then tables ...</echo>
<!-- First retrieve the drop scripts from the database.
This ensures the proper scripts get called. -->
<echo>Executing ${ddl.directory}/backup/dropViews.sql</echo>
<doSqlTarget autocommit="true" onerror="continue" src="${ddl.directory}/backup/dropViews.sql" />
<echo>Executing ${ddl.directory}/backup/dropTables.sql</echo>
<doSqlTarget autocommit="true" onerror="continue" src="${ddl.directory}/backup/dropTables.sql" />
<echo>Executing ${tap.ddl.directory}/${project.name}_drop_tap_schema.sql</echo>
<doSqlTarget autocommit="true" onerror="continue" src="${tap.ddl.directory}/${project.name}_drop_tap_schema.sql" delimiter="${create.view.sep}"/>
<echo>cleanDB : done.</echo>
</target>
<target name="DB-truncate" depends="DB-retrieveDDLs" description="Empty all tables in the database">
<echo>DB-truncate : truncate all model tables ...</echo>
<echo>Executing ${ddl.directory}/backup/truncateTables.sql</echo>
<doSqlTarget autocommit="true" onerror="continue" src="${ddl.directory}/backup/truncateTables.sql" />
<echo>DB-truncate : done.</echo>
</target>
<!-- target createDB : creates tables then views -->
<target name="DB-create" depends="DB-initFor" description="CLEAN first and create database tables / views and TAP_SCHEMA">
<echo>Creating tables then views to ${targetdb.url} ...</echo>
<!-- web user rights -->
<doSqlAdmindb src="./webapp/vo-urp-browser/ddl/${db.vendor}/admindb.sql"/>
<doSqlTarget onerror="abort" src="${ddl.directory}/createTables.sql" />
<doSqlTarget onerror="abort" src="${ddl.directory}/createViews.sql" delimiter="${create.view.sep}"/>
<doSqlTarget onerror="abort" src="${tap.ddl.directory}/${project.name}_create_tap_schema.sql" delimiter="${create.view.sep}"/>
<ant target="DB-insertDDLs"/>
</target>
<!-- copy generated files into meta table -->
<target name="DB-insertDDLs" depends="DB-initFor">
<java classname="AdminDBHandler" dir="${libs}/admindb/bin" fork="true"
failonerror="true" >
<jvmarg value="-Xms32m"/>
<jvmarg value="-Xmx64m"/>
<arg value="I"/>
<arg value="${admindb.driver}"/>
<arg value="${admindb.url}"/>
<arg value="${admindb.admin}"/>
<arg value="${admindb.adminpassword}"/>
<arg value="${output}/${source_intermediate}"/>
<arg value="${ddl.directory}"/>
<classpath>
<pathelement location="${libs}/log4j-1.2.16.jar" />
<fileset dir="${libs}/jdbc/"><include name="*.jar"/></fileset>
<pathelement location="${libs}/admindb/bin/"/>
<!-- use gerard patched 1.5.b1 version (enum problem present) -->
</classpath>
</java>
</target>
<target name="DB-retrieveDDLs" depends="DB-initFor">
<java classname="AdminDBHandler" dir="${libs}/admindb/bin" fork="true"
failonerror="true" >
<jvmarg value="-Xms32m"/>
<jvmarg value="-Xmx64m"/>
<arg value="L"/>
<arg value="${admindb.driver}"/>
<arg value="${admindb.url}"/>
<arg value="${admindb.admin}"/>
<arg value="${admindb.adminpassword}"/>
<arg value="${ddl.directory}/backup"/>
<classpath>
<pathelement location="${libs}/log4j-1.2.16.jar" />
<fileset dir="${libs}/jdbc/"><include name="*.jar"/></fileset>
<pathelement location="${libs}/admindb/bin/"/>
<!-- use gerard patched 1.5.b1 version (enum problem present) -->
</classpath>
</java>
</target>
<!-- end of build_db.xml -->