Project

General

Profile

build_db.xml

Igor Skornyakov, 01/05/2021 08:30 AM

Download (9.74 KB)

 
1
<project name="hotel" default="dist" basedir=".">
2

    
3
   <description>Tasks to manage the databases (import, export, drop, create). Always called via build.xml</description>
4
   
5
   <property name="sql.url.h2" value="jdbc:h2:${db.home}/${db.name};MV_STORE=FALSE;LOG=0;CACHE_SIZE=65536;LOCK_MODE=0;UNDO_LOG=0" />
6
   <property name="sql.url.pg" value="jdbc:postgresql://${db.host}:${db.port}/${db.name}" />
7

    
8
   <tstamp>
9
      <format property="LOG_STAMP" pattern="yyyyMMdd_HHmmss" />
10
   </tstamp>
11

    
12
   <condition property="p2jpl.jar.path" value="${deploy.home.abs}/lib/p2jpl.jar" else="/usr/share/java/p2jpl.jar">
13
      <isset property="isWindows"  />
14
   </condition>
15

    
16
   <!-- drop the H2 database by deleting the ${db.home} directory -->
17
   <target name="clean.db.h2" description="Remove generated database directory." if="${db.h2}">
18
      <delete failonerror="false">
19
         <fileset dir="${db.home}" includes="${db.name}.*" />
20
      </delete>
21
      <delete includeemptydirs="true" failonerror="false"> 
22
         <fileset dir="${db.home}" excludes="**/*" /> 
23
      </delete> 
24
   </target>
25

    
26
   <target name="create.db.h2"
27
           description="Creates an empty H2 database instance using the DDL generated during conversion."
28
           if="${db.h2}">
29
      <record name="create_db_h2_${db.name}_${LOG_STAMP}.log" action="start"/>
30
      <java classname="org.h2.tools.RunScript"
31
            fork="true"
32
            failonerror="true"
33
            dir="${basedir}" >
34
         <jvmarg value="-Xmx1g"/>
35
         <jvmarg value="-Dfile.encoding=UTF-8"/>
36
         <arg value ="-url"/>
37
         <arg value ="${sql.url.h2}"/>
38
         <arg value ="-user"/>
39
         <arg value="${sql.user}"/>
40
         <arg value ="-password"/>
41
         <arg value="${sql.user.pass}"/>
42
         <arg value ="-script"/>
43
         <arg value = "ddl/schema_table_${db.name}_h2.sql"/>
44
         <arg value ="-continueOnError"/>
45
         <classpath refid="app.classpath"/>
46
      </java>
47
      <record name="create_db_h2_${db.name}_${LOG_STAMP}.log" action="stop"/>
48
   </target>
49
   
50
   <target name="import.db.h2"
51
           description="Import data (.d files) into database."
52
           if="${db.h2}">
53
      <record name="import_db_h2_${db.name}_${LOG_STAMP}.log" action="start"/>
54
      <java classname="com.goldencode.p2j.pattern.PatternEngine"
55
            fork="true"
56
            failonerror="true"
57
            dir="${basedir}" >
58
         <jvmarg value="-Xmx1g"/>
59
         <jvmarg value="-Djava.system.class.loader=com.goldencode.asm.AsmClassLoader"/>
60
         <jvmarg value="-Dfile.encoding=UTF-8"/>
61
         <arg value ="-d"/>
62
         <arg value ="2"/>
63
         <arg value ="dbName=${escaped.quotes}${db.name}${escaped.quotes}"/>
64
         <arg value ="targetDb=${escaped.quotes}h2${escaped.quotes}"/>
65
         <arg value ="url=${escaped.quotes}${sql.url.h2}${escaped.quotes}"/>
66
         <arg value ="uid=${escaped.quotes}${sql.user}${escaped.quotes}"/>
67
         <arg value ="pw=${escaped.quotes}${sql.user.pass}${escaped.quotes}"/>
68
         <arg value ="maxThreads=4"/>
69
         <arg value ="schema/import"/>
70
         <arg value ="data/namespace/"/>
71
         <arg value ="${db.name}.p2o"/>
72
         <classpath refid="app.classpath"/>
73
      </java>
74
      <record name="import_db_h2_${db.name}_${LOG_STAMP}.log" action="stop"/>
75
      <record name="word_tables_h2_${db.name}_${LOG_STAMP}.log" action="start"/>
76
       <java classname="org.h2.tools.RunScript"
77
            fork="true"
78
            failonerror="true"
79
            dir="${basedir}" >
80
         <jvmarg value="-Xmx1g"/>
81
         <jvmarg value="-Dfile.encoding=UTF-8"/>
82
         <arg value ="-url"/>
83
         <arg value ="${sql.url.h2}"/>
84
         <arg value ="-user"/>
85
         <arg value="${sql.user}"/>
86
         <arg value ="-password"/>
87
         <arg value="${sql.user.pass}"/>
88
         <arg value ="-script"/>
89
         <arg value = "ddl/schema_word_tables_${db.name}_h2.sql"/>
90
         <arg value ="-continueOnError"/>
91
         <classpath refid="app.classpath"/>
92
      </java>
93
      <record name="word_tables_h2_${db.name}_${LOG_STAMP}.log" action="stop"/>
94
   </target>
95
   
96
   <!-- drop the PostgreSQL database -->
97
   <target name="clean.db.pg" description="Drop PostgreSQL database." if="${db.postgresql}">
98
      <record name="clean_db_pg_${db.name}_${LOG_STAMP}.log" action="start"/>
99
      <exec executable="dropdb">
100
         <env key="PGPASSWORD" value="${sql.admin.pass}" />
101
         <arg value="-U" />
102
         <arg value="${sql.admin}" />
103
         <arg value="-h" />
104
         <arg value="${db.host}" />
105
         <arg value="-p" />
106
         <arg value="${db.port}" />
107
         <arg value="${db.name}" />
108
      </exec>
109
      <record name="clean_db_pg_${db.name}_${LOG_STAMP}.log" action="stop"/>
110
   </target>
111
   
112
   <target name="create.db.pg"
113
           description="Create an empty PostgreSQL database instance using the DDL generated during conversion."
114
           if="${db.postgresql}">
115
      <record name="create_db_pg_${db.name}_${LOG_STAMP}.log" action="start"/>
116
      <!-- create an empty database -->
117
      <exec executable="createdb">
118
         <env key="PGPASSWORD" value="${sql.admin.pass}" />
119
         <arg value="-U" />
120
         <arg value="${sql.admin}" />
121
         <arg value="-h" />
122
         <arg value="${db.host}" />
123
         <arg value="-p" />
124
         <arg value="${db.port}" />
125
         <arg value="${db.name}" />
126
      </exec>
127
      <!-- apply the schema to it -->
128
      <exec executable="psql">
129
         <env key="PGPASSWORD" value="${sql.user.pass}" />
130
         <arg value="-U" />
131
         <arg value="${sql.user}" />
132
         <arg value="-h" />
133
         <arg value="${db.host}" />
134
         <arg value="-p" />
135
         <arg value="${db.port}" />
136
         <arg value="-f" />
137
         <arg value="ddl/schema_table_${db.name}_postgresql.sql" />
138
         <arg value="${db.name}" />
139
      </exec>
140
      <!-- enable Java as a procedure language -->
141
      <exec executable="psql">
142
         <env key="PGPASSWORD" value="${sql.admin.pass}" />
143
         <arg value="-U" />
144
         <arg value="${sql.admin}" />
145
         <arg value="-h" />
146
         <arg value="${db.host}" />
147
         <arg value="-p" />
148
         <arg value="${db.port}" />
149
         <arg value="-c" />
150
         <arg value="create extension pljava" />
151
         <arg value="${db.name}" />
152
      </exec>
153
      <!-- grant permission for public to use sqlj schema (PL/Java) -->
154
      <exec executable="psql">
155
         <env key="PGPASSWORD" value="${sql.admin.pass}" />
156
         <arg value="-U" />
157
         <arg value="${sql.admin}" />
158
         <arg value="-h" />
159
         <arg value="${db.host}" />
160
         <arg value="-p" />
161
         <arg value="${db.port}" />
162
         <arg value="-c" />
163
         <arg value="grant usage on schema sqlj to public" />
164
         <arg value="${db.name}" />
165
      </exec>
166
      <!-- load the FWD UDF library into the database -->
167
      <exec executable="psql">
168
         <env key="PGPASSWORD" value="${sql.admin.pass}" />
169
         <arg value="-U" />
170
         <arg value="${sql.admin}" />
171
         <arg value="-h" />
172
         <arg value="${db.host}" />
173
         <arg value="-p" />
174
         <arg value="${db.port}" />
175
         <arg value="-c" />
176
         <arg value="select sqlj.install_jar('file://${p2jpl.jar.path}', 'p2j', true)" />
177
         <arg value="${db.name}" />
178
      </exec>
179
      <!-- set classpath for FWD UDF library -->
180
      <exec executable="psql">
181
         <env key="PGPASSWORD" value="${sql.admin.pass}" />
182
         <arg value="-U" />
183
         <arg value="${sql.admin}" />
184
         <arg value="-h" />
185
         <arg value="${db.host}" />
186
         <arg value="-p" />
187
         <arg value="${db.port}" />
188
         <arg value="-c" />
189
         <arg value="select sqlj.set_classpath('public', 'p2j')" />
190
         <arg value="${db.name}" />
191
      </exec>
192
      <record name="create_db_pg_${db.name}_${LOG_STAMP}.log" action="stop"/>
193
   </target>
194
   
195
   <target name="import.db.pg"
196
           description="Import data (.d files) into PostgreSQL database."
197
           if="${db.postgresql}">
198
      <record name="import_db_pg_${db.name}_${LOG_STAMP}.log" action="start"/>
199
      <java classname="com.goldencode.p2j.pattern.PatternEngine"
200
            fork="true"
201
            failonerror="true"
202
            dir="${basedir}" >
203
         <jvmarg value="-Xmx1g"/>
204
         <jvmarg value="-Djava.system.class.loader=com.goldencode.asm.AsmClassLoader"/>
205
         <jvmarg value="-Dfile.encoding=UTF-8"/>
206
         <jvmarg value="-Djava.util.logging.config.file=${p2j.home}/cfg/logging.properties"/>
207
         <jvmarg value="-Xrunjdwp:transport=dt_socket,address=2080,server=y,suspend=n"/>
208
         <arg value ="-d"/>
209
         <arg value ="2"/>
210
         <arg value ="dbName=${escaped.quotes}${db.name}${escaped.quotes}"/>
211
         <arg value ="targetDb=${escaped.quotes}postgresql${escaped.quotes}"/>
212
         <arg value ="url=${escaped.quotes}${sql.url.pg}${escaped.quotes}"/>
213
         <arg value ="uid=${escaped.quotes}${sql.user}${escaped.quotes}"/>
214
         <arg value ="pw=${escaped.quotes}${sql.user.pass}${escaped.quotes}"/>
215
         <arg value ="maxThreads=1"/>
216
         <arg value ="schema/import"/>
217
         <arg value ="data/namespace/"/>
218
         <arg value ="${db.name}.p2o"/>
219
         <classpath refid="app.classpath"/>
220
      </java>
221
      <record name="import_db_pg_${db.name}_${LOG_STAMP}.log" action="stop"/>
222
      <record name="word_tables_pg_${db.name}_${LOG_STAMP}.log" action="start"/>
223
      <exec executable="psql">
224
         <env key="PGPASSWORD" value="${sql.user.pass}" />
225
         <arg value="-U" />
226
         <arg value="${sql.user}" />
227
         <arg value="-h" />
228
         <arg value="${db.host}" />
229
         <arg value="-p" />
230
         <arg value="${db.port}" />
231
         <arg value="-f" />
232
         <arg value="ddl/schema_word_tables_${db.name}_postgresql.sql" />
233
         <arg value="${db.name}" />
234
      </exec>
235
      <record name="word_tables_pg_${db.name}_${LOG_STAMP}.log" action="stop"/>
236
   </target>
237
   
238
</project>