KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > test > internal > performance > db > SQL


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.test.internal.performance.db;
12
13 import java.math.BigDecimal JavaDoc;
14 import java.sql.Connection JavaDoc;
15 import java.sql.PreparedStatement JavaDoc;
16 import java.sql.ResultSet JavaDoc;
17 import java.sql.SQLException JavaDoc;
18 import java.sql.Statement JavaDoc;
19 import java.sql.Timestamp JavaDoc;
20
21 /*
22  * Any SQL should only be used here.
23  */

24 public class SQL {
25
26     private boolean fCompatibility= false;
27
28     private Connection JavaDoc fConnection;
29
30     private PreparedStatement JavaDoc fInsertVariation, fInsertScenario, fInsertSample, fInsertDataPoint, fInsertScalar;
31     private PreparedStatement JavaDoc fQueryComment, fInsertComment, fQueryComment2;
32     private PreparedStatement JavaDoc fQueryVariation, fQueryVariations, fQueryScenario, fQueryAllScenarios, fQueryDatapoints,
33             fQueryScalars;
34     private PreparedStatement JavaDoc fInsertSummaryEntry, fUpdateScenarioShortName, fQuerySummaryEntry, fQueryGlobalSummaryEntries,
35             fQuerySummaryEntries;
36     private PreparedStatement JavaDoc fInsertFailure, fQueryFailure;
37
38     SQL(Connection JavaDoc con) throws SQLException JavaDoc {
39         fConnection= con;
40
41         boolean needsUpgrade= true;
42         boolean needsInitialization= true;
43         boolean needsFailures= true;
44         boolean needsComments= true;
45
46         Statement JavaDoc statement= fConnection.createStatement();
47         ResultSet JavaDoc rs= statement.executeQuery("select SYS.SYSTABLES.TABLENAME from SYS.SYSTABLES where SYS.SYSTABLES.TABLENAME not like 'SYS%'"); //$NON-NLS-1$
48
while (rs.next()) {
49             String JavaDoc tablename= rs.getString(1);
50             if ("SUMMARYENTRY".equals(tablename)) //$NON-NLS-1$
51
needsUpgrade= false;
52             else if ("CONFIG_ORG".equals(tablename)) //$NON-NLS-1$
53
fCompatibility= true;
54             else if ("VARIATION".equals(tablename)) //$NON-NLS-1$
55
needsInitialization= false;
56             else if ("FAILURE".equals(tablename)) //$NON-NLS-1$
57
needsFailures= false;
58             else if ("COMMENT".equals(tablename)) //$NON-NLS-1$
59
needsComments= false;
60         }
61         if (!fCompatibility) {
62             // check whether table SAMPLE still has the CONFIG_ID column
63
rs= statement.executeQuery("select count(*) from SYS.SYSTABLES, SYS.SYSCOLUMNS where SYS.SYSTABLES.TABLENAME = 'SAMPLE' and " + //$NON-NLS-1$
64
"SYS.SYSTABLES.TABLEID = SYS.SYSCOLUMNS.REFERENCEID and SYS.SYSCOLUMNS.COLUMNNAME = 'CONFIG_ID' "); //$NON-NLS-1$
65
if (rs.next() && rs.getInt(1) == 1)
66                 fCompatibility= true;
67         }
68
69         if (needsInitialization)
70             initialize();
71         else {
72             if (needsUpgrade)
73                 upgradeDB();
74             else if (needsFailures)
75                 addFailureTable();
76             if (needsComments)
77                 addCommentTable();
78         }
79     }
80
81     public void dispose() throws SQLException JavaDoc {
82         if (fInsertVariation != null)
83             fInsertVariation.close();
84         if (fInsertScenario != null)
85             fInsertScenario.close();
86         if (fInsertSample != null)
87             fInsertSample.close();
88         if (fInsertDataPoint != null)
89             fInsertDataPoint.close();
90         if (fInsertScalar != null)
91             fInsertScalar.close();
92         if (fInsertSummaryEntry != null)
93             fInsertSummaryEntry.close();
94         if (fInsertFailure != null)
95             fInsertFailure.close();
96         if (fInsertComment != null)
97             fInsertComment.close();
98         if (fUpdateScenarioShortName != null)
99             fUpdateScenarioShortName.close();
100         if (fQueryDatapoints != null)
101             fQueryDatapoints.close();
102         if (fQueryScalars != null)
103             fQueryScalars.close();
104         if (fQueryVariation != null)
105             fQueryVariation.close();
106         if (fQueryScenario != null)
107             fQueryScenario.close();
108         if (fQueryAllScenarios != null)
109             fQueryAllScenarios.close();
110         if (fQueryVariations != null)
111             fQueryVariations.close();
112         if (fQueryGlobalSummaryEntries != null)
113             fQueryGlobalSummaryEntries.close();
114         if (fQuerySummaryEntries != null)
115             fQuerySummaryEntries.close();
116         if (fQueryFailure != null)
117             fQueryFailure.close();
118         if (fQueryComment != null)
119             fQueryComment.close();
120         if (fQueryComment2 != null)
121             fQueryComment2.close();
122     }
123
124     private void initialize() throws SQLException JavaDoc {
125         Statement JavaDoc stmt= null;
126         try {
127             stmt= fConnection.createStatement();
128             stmt.executeUpdate("create table VARIATION (" + //$NON-NLS-1$
129
"ID int unique not null GENERATED ALWAYS AS IDENTITY," + //$NON-NLS-1$
130
"KEYVALPAIRS varchar(10000) not null " + //$NON-NLS-1$
131
")" //$NON-NLS-1$
132
);
133             stmt.executeUpdate("create table SCENARIO (" + //$NON-NLS-1$
134
"ID int unique not null GENERATED ALWAYS AS IDENTITY," + //$NON-NLS-1$
135
"NAME varchar(256) not null," + //$NON-NLS-1$
136
"SHORT_NAME varchar(40)" + //$NON-NLS-1$
137
")" //$NON-NLS-1$
138
);
139             stmt.executeUpdate("create table SAMPLE (" + //$NON-NLS-1$
140
"ID int not null GENERATED ALWAYS AS IDENTITY," + //$NON-NLS-1$
141
"VARIATION_ID int not null," + //$NON-NLS-1$
142
"SCENARIO_ID int not null," + //$NON-NLS-1$
143
"STARTTIME timestamp" + //$NON-NLS-1$
144
")" //$NON-NLS-1$
145
);
146             stmt.executeUpdate("create table DATAPOINT (" + //$NON-NLS-1$
147
"ID int not null GENERATED ALWAYS AS IDENTITY," + //$NON-NLS-1$
148
"SAMPLE_ID int not null," + //$NON-NLS-1$
149
"SEQ int," + //$NON-NLS-1$
150
"STEP int" + //$NON-NLS-1$
151
")" //$NON-NLS-1$
152
);
153             stmt.executeUpdate("create table SCALAR (" + //$NON-NLS-1$
154
"DATAPOINT_ID int not null," + //$NON-NLS-1$
155
"DIM_ID int not null," + //$NON-NLS-1$
156
"VALUE bigint" + //$NON-NLS-1$
157
")" //$NON-NLS-1$
158
);
159             stmt.executeUpdate("create table SUMMARYENTRY (" + //$NON-NLS-1$
160
"VARIATION_ID int not null," + //$NON-NLS-1$
161
"SCENARIO_ID int not null," + //$NON-NLS-1$
162
"DIM_ID int not null," + //$NON-NLS-1$
163
"IS_GLOBAL smallint not null," + //$NON-NLS-1$
164
"COMMENT_ID int not null" + //$NON-NLS-1$
165
")" //$NON-NLS-1$
166
);
167             stmt.executeUpdate("create table FAILURE (" + //$NON-NLS-1$
168
"VARIATION_ID int not null," + //$NON-NLS-1$
169
"SCENARIO_ID int not null," + //$NON-NLS-1$
170
"MESSAGE varchar(1000) not null" + //$NON-NLS-1$
171
")" //$NON-NLS-1$
172
);
173             stmt.executeUpdate("create table COMMENT (" + //$NON-NLS-1$
174
"ID int unique not null GENERATED ALWAYS AS IDENTITY," + //$NON-NLS-1$
175
"KIND int not null," + //$NON-NLS-1$
176
"TEXT varchar(400) not null" + //$NON-NLS-1$
177
")" //$NON-NLS-1$
178
);
179             
180             // Primary/unique
181
stmt.executeUpdate("alter table VARIATION add constraint VA_KVP primary key (KEYVALPAIRS)"); //$NON-NLS-1$
182
stmt.executeUpdate("alter table SCENARIO add constraint SC_NAME primary key (NAME)"); //$NON-NLS-1$
183
stmt.executeUpdate("alter table SAMPLE add constraint SA_ID primary key (ID)"); //$NON-NLS-1$
184
stmt.executeUpdate("alter table DATAPOINT add constraint DP_ID primary key (ID)"); //$NON-NLS-1$
185

186             // Foreign
187
stmt.executeUpdate("alter table SAMPLE add constraint SAMPLE_CONSTRAINT " + //$NON-NLS-1$
188
"foreign key (VARIATION_ID) references VARIATION (ID)"); //$NON-NLS-1$
189
stmt.executeUpdate("alter table SAMPLE add constraint SAMPLE_CONSTRAINT2 " + //$NON-NLS-1$
190
"foreign key (SCENARIO_ID) references SCENARIO (ID)"); //$NON-NLS-1$
191
stmt.executeUpdate("alter table DATAPOINT add constraint DP_CONSTRAINT " + //$NON-NLS-1$
192
"foreign key (SAMPLE_ID) references SAMPLE (ID)"); //$NON-NLS-1$
193
stmt.executeUpdate("alter table SCALAR add constraint SCALAR_CONSTRAINT " + //$NON-NLS-1$
194
"foreign key (DATAPOINT_ID) references DATAPOINT (ID)"); //$NON-NLS-1$
195

196             stmt.executeUpdate("alter table SUMMARYENTRY add constraint FP_CONSTRAINT " + //$NON-NLS-1$
197
"foreign key (VARIATION_ID) references VARIATION (ID)"); //$NON-NLS-1$
198
stmt.executeUpdate("alter table SUMMARYENTRY add constraint FP_CONSTRAINT2 " + //$NON-NLS-1$
199
"foreign key (SCENARIO_ID) references SCENARIO (ID)"); //$NON-NLS-1$
200

201             stmt.executeUpdate("alter table FAILURE add constraint FA_CONSTRAINT " + //$NON-NLS-1$
202
"foreign key (VARIATION_ID) references VARIATION (ID)"); //$NON-NLS-1$
203
stmt.executeUpdate("alter table FAILURE add constraint FA_CONSTRAINT2 " + //$NON-NLS-1$
204
"foreign key (SCENARIO_ID) references SCENARIO (ID)"); //$NON-NLS-1$
205

206             fConnection.commit();
207
208         } finally {
209             if (stmt != null)
210                 stmt.close();
211         }
212     }
213
214     private void upgradeDB() throws SQLException JavaDoc {
215         Statement JavaDoc stmt= null;
216         try {
217             stmt= fConnection.createStatement();
218
219             stmt.executeUpdate("create table SUMMARYENTRY (" + //$NON-NLS-1$
220
"VARIATION_ID int not null," + //$NON-NLS-1$
221
"SCENARIO_ID int not null," + //$NON-NLS-1$
222
"DIM_ID int not null," + //$NON-NLS-1$
223
"IS_GLOBAL smallint not null," + //$NON-NLS-1$
224
"COMMENT_ID int not null" + //$NON-NLS-1$
225
")" //$NON-NLS-1$
226
);
227             stmt.executeUpdate("alter table SUMMARYENTRY add constraint FP_CONSTRAINT " + //$NON-NLS-1$
228
"foreign key (VARIATION_ID) references VARIATION (ID)"); //$NON-NLS-1$
229
stmt.executeUpdate("alter table SUMMARYENTRY add constraint FP_CONSTRAINT2 " + //$NON-NLS-1$
230
"foreign key (SCENARIO_ID) references SCENARIO (ID)"); //$NON-NLS-1$
231

232             stmt.executeUpdate("alter table SCENARIO add column SHORT_NAME varchar(40)"); //$NON-NLS-1$
233

234             fConnection.commit();
235
236         } finally {
237             if (stmt != null)
238                 stmt.close();
239         }
240     }
241
242     private void addCommentTable() throws SQLException JavaDoc {
243         Statement JavaDoc stmt= null;
244         try {
245             stmt= fConnection.createStatement();
246
247             stmt.executeUpdate("create table COMMENT (" + //$NON-NLS-1$
248
"ID int unique not null GENERATED ALWAYS AS IDENTITY," + //$NON-NLS-1$
249
"KIND int not null," + //$NON-NLS-1$
250
"TEXT varchar(400) not null" + //$NON-NLS-1$
251
")" //$NON-NLS-1$
252
);
253
254             stmt.executeUpdate("alter table SUMMARYENTRY add column COMMENT_ID int not null default 0"); //$NON-NLS-1$
255

256             fConnection.commit();
257
258         } finally {
259             if (stmt != null)
260                 stmt.close();
261         }
262     }
263
264     private void addFailureTable() throws SQLException JavaDoc {
265         Statement JavaDoc stmt= null;
266         try {
267             stmt= fConnection.createStatement();
268
269             stmt.executeUpdate("create table FAILURE (" + //$NON-NLS-1$
270
"VARIATION_ID int not null," + //$NON-NLS-1$
271
"SCENARIO_ID int not null," + //$NON-NLS-1$
272
"MESSAGE varchar(1000) not null" + //$NON-NLS-1$
273
")" //$NON-NLS-1$
274
);
275
276             stmt.executeUpdate("alter table FAILURE add constraint FA_CONSTRAINT " + //$NON-NLS-1$
277
"foreign key (VARIATION_ID) references VARIATION (ID)"); //$NON-NLS-1$
278
stmt.executeUpdate("alter table FAILURE add constraint FA_CONSTRAINT2 " + //$NON-NLS-1$
279
"foreign key (SCENARIO_ID) references SCENARIO (ID)"); //$NON-NLS-1$
280

281             fConnection.commit();
282
283         } finally {
284             if (stmt != null)
285                 stmt.close();
286         }
287     }
288
289     static int create(PreparedStatement JavaDoc stmt) throws SQLException JavaDoc {
290         stmt.executeUpdate();
291         ResultSet JavaDoc rs= stmt.getGeneratedKeys();
292         if (rs != null) {
293             try {
294                 if (rs.next()) {
295                     BigDecimal JavaDoc idColVar= rs.getBigDecimal(1);
296                     return idColVar.intValue();
297                 }
298             } finally {
299                 rs.close();
300             }
301         }
302         return 0;
303     }
304
305     int getScenario(String JavaDoc scenarioPattern) throws SQLException JavaDoc {
306         if (fQueryScenario == null)
307             fQueryScenario= fConnection.prepareStatement("select ID from SCENARIO where NAME = ?"); //$NON-NLS-1$
308
fQueryScenario.setString(1, scenarioPattern);
309         ResultSet JavaDoc result= fQueryScenario.executeQuery();
310         while (result.next())
311             return result.getInt(1);
312
313         if (fInsertScenario == null)
314             fInsertScenario= fConnection.prepareStatement("insert into SCENARIO (NAME) values (?)", Statement.RETURN_GENERATED_KEYS); //$NON-NLS-1$
315
fInsertScenario.setString(1, scenarioPattern);
316         return create(fInsertScenario);
317     }
318
319     int getVariations(Variations variations) throws SQLException JavaDoc {
320         if (fQueryVariation == null)
321             fQueryVariation= fConnection.prepareStatement("select ID from VARIATION where KEYVALPAIRS = ?"); //$NON-NLS-1$
322
String JavaDoc exactMatchString= variations.toExactMatchString();
323         fQueryVariation.setString(1, exactMatchString);
324         ResultSet JavaDoc result= fQueryVariation.executeQuery();
325         while (result.next())
326             return result.getInt(1);
327
328         if (fInsertVariation == null)
329             fInsertVariation= fConnection.prepareStatement("insert into VARIATION (KEYVALPAIRS) values (?)", Statement.RETURN_GENERATED_KEYS); //$NON-NLS-1$
330
fInsertVariation.setString(1, exactMatchString);
331         return create(fInsertVariation);
332     }
333
334     int createSample(int variation_id, int scenario_id, Timestamp JavaDoc starttime) throws SQLException JavaDoc {
335         if (fInsertSample == null) {
336             if (fCompatibility) {
337                 // since we cannot remove table columns in cloudscape we have to
338
// provide a non-null value for CONFIG_ID
339
fInsertSample= fConnection.prepareStatement("insert into SAMPLE (VARIATION_ID, SCENARIO_ID, STARTTIME, CONFIG_ID) values (?, ?, ?, 0)", Statement.RETURN_GENERATED_KEYS); //$NON-NLS-1$
340
} else {
341                 fInsertSample= fConnection.prepareStatement("insert into SAMPLE (VARIATION_ID, SCENARIO_ID, STARTTIME) values (?, ?, ?)", Statement.RETURN_GENERATED_KEYS); //$NON-NLS-1$
342
}
343         }
344         fInsertSample.setInt(1, variation_id);
345         fInsertSample.setInt(2, scenario_id);
346         fInsertSample.setTimestamp(3, starttime);
347         return create(fInsertSample);
348     }
349
350     int createDataPoint(int sample_id, int seq, int step) throws SQLException JavaDoc {
351         if (fInsertDataPoint == null)
352             fInsertDataPoint= fConnection.prepareStatement("insert into DATAPOINT (SAMPLE_ID, SEQ, STEP) values (?, ?, ?)", Statement.RETURN_GENERATED_KEYS); //$NON-NLS-1$
353
fInsertDataPoint.setInt(1, sample_id);
354         fInsertDataPoint.setInt(2, seq);
355         fInsertDataPoint.setInt(3, step);
356         return create(fInsertDataPoint);
357     }
358
359     void insertScalar(int datapoint_id, int dim_id, long value) throws SQLException JavaDoc {
360         if (fInsertScalar == null)
361             fInsertScalar= fConnection.prepareStatement("insert into SCALAR values (?, ?, ?)"); //$NON-NLS-1$
362
fInsertScalar.setInt(1, datapoint_id);
363         fInsertScalar.setInt(2, dim_id);
364         fInsertScalar.setLong(3, value);
365         fInsertScalar.executeUpdate();
366     }
367
368     ResultSet JavaDoc queryDataPoints(Variations variations, String JavaDoc scenarioName) throws SQLException JavaDoc {
369         if (fQueryDatapoints == null)
370             fQueryDatapoints= fConnection.prepareStatement("select DATAPOINT.ID, DATAPOINT.STEP from VARIATION, SCENARIO, SAMPLE, DATAPOINT " + //$NON-NLS-1$
371
"where " + //$NON-NLS-1$
372
"SAMPLE.VARIATION_ID = VARIATION.ID and VARIATION.KEYVALPAIRS = ? and " + //$NON-NLS-1$
373
"SAMPLE.SCENARIO_ID = SCENARIO.ID and SCENARIO.NAME LIKE ? and " + //$NON-NLS-1$
374
"DATAPOINT.SAMPLE_ID = SAMPLE.ID " //$NON-NLS-1$
375
);
376         fQueryDatapoints.setString(1, variations.toExactMatchString());
377         fQueryDatapoints.setString(2, scenarioName);
378         return fQueryDatapoints.executeQuery();
379     }
380
381     ResultSet JavaDoc queryScalars(int datapointId) throws SQLException JavaDoc {
382         if (fQueryScalars == null)
383             fQueryScalars= fConnection.prepareStatement("select SCALAR.DIM_ID, SCALAR.VALUE from SCALAR where SCALAR.DATAPOINT_ID = ?"); //$NON-NLS-1$
384
fQueryScalars.setInt(1, datapointId);
385         return fQueryScalars.executeQuery();
386     }
387
388     /*
389      * Returns SCENARIO.NAME
390      */

391     ResultSet JavaDoc queryScenarios(Variations variations, String JavaDoc scenarioPattern) throws SQLException JavaDoc {
392         if (fQueryAllScenarios == null)
393             fQueryAllScenarios= fConnection.prepareStatement("select distinct SCENARIO.NAME from SCENARIO, SAMPLE, VARIATION where " + //$NON-NLS-1$
394
"SAMPLE.VARIATION_ID = VARIATION.ID and VARIATION.KEYVALPAIRS LIKE ? and " + //$NON-NLS-1$
395
"SAMPLE.SCENARIO_ID = SCENARIO.ID and SCENARIO.NAME LIKE ?" //$NON-NLS-1$
396
);
397         fQueryAllScenarios.setString(1, variations.toQueryPattern());
398         fQueryAllScenarios.setString(2, scenarioPattern);
399         return fQueryAllScenarios.executeQuery();
400     }
401
402     /*
403      * Returns VARIATION.KEYVALPAIRS
404      */

405     ResultSet JavaDoc queryVariations(String JavaDoc variations, String JavaDoc scenarioPattern) throws SQLException JavaDoc {
406         if (fQueryVariations == null)
407             fQueryVariations= fConnection.prepareStatement("select distinct VARIATION.KEYVALPAIRS from VARIATION, SAMPLE, SCENARIO where " + //$NON-NLS-1$
408
"SAMPLE.VARIATION_ID = VARIATION.ID and VARIATION.KEYVALPAIRS LIKE ? and " + //$NON-NLS-1$
409
"SAMPLE.SCENARIO_ID = SCENARIO.ID and SCENARIO.NAME LIKE ?" //$NON-NLS-1$
410
);
411         fQueryVariations.setString(1, variations);
412         fQueryVariations.setString(2, scenarioPattern);
413         return fQueryVariations.executeQuery();
414     }
415
416     void createSummaryEntry(int variation_id, int scenario_id, int dim_id, boolean isGlobal, int comment_id) throws SQLException JavaDoc {
417         if (fQuerySummaryEntry == null)
418             fQuerySummaryEntry= fConnection.prepareStatement(
419                     "select count(*) from SUMMARYENTRY where VARIATION_ID = ? and SCENARIO_ID = ? and DIM_ID = ? and IS_GLOBAL = ? and COMMENT_ID = ?"); //$NON-NLS-1$
420
fQuerySummaryEntry.setInt(1, variation_id);
421         fQuerySummaryEntry.setInt(2, scenario_id);
422         fQuerySummaryEntry.setInt(3, dim_id);
423         fQuerySummaryEntry.setShort(4, (short) (isGlobal ? 1 : 0));
424         fQuerySummaryEntry.setInt(5, comment_id);
425         ResultSet JavaDoc result= fQuerySummaryEntry.executeQuery();
426         if (result.next() && result.getInt(1) > 0)
427             return;
428
429         if (fInsertSummaryEntry == null)
430             fInsertSummaryEntry= fConnection.prepareStatement("insert into SUMMARYENTRY (VARIATION_ID, SCENARIO_ID, DIM_ID, IS_GLOBAL, COMMENT_ID) values (?, ?, ?, ?, ?)"); //$NON-NLS-1$
431
fInsertSummaryEntry.setInt(1, variation_id);
432         fInsertSummaryEntry.setInt(2, scenario_id);
433         fInsertSummaryEntry.setInt(3, dim_id);
434         fInsertSummaryEntry.setShort(4, (short) (isGlobal ? 1 : 0));
435         fInsertSummaryEntry.setInt(5, comment_id);
436         fInsertSummaryEntry.executeUpdate();
437     }
438
439     public void setScenarioShortName(int scenario_id, String JavaDoc shortName) throws SQLException JavaDoc {
440         if (shortName.length() >= 40)
441             shortName= shortName.substring(0, 40);
442         if (fUpdateScenarioShortName == null)
443             fUpdateScenarioShortName= fConnection.prepareStatement("update SCENARIO set SHORT_NAME = ? where SCENARIO.ID = ?"); //$NON-NLS-1$
444
fUpdateScenarioShortName.setString(1, shortName);
445         fUpdateScenarioShortName.setInt(2, scenario_id);
446         fUpdateScenarioShortName.executeUpdate();
447     }
448
449     ResultSet JavaDoc queryGlobalSummaryEntries(Variations variations) throws SQLException JavaDoc {
450         if (fQueryGlobalSummaryEntries == null)
451             fQueryGlobalSummaryEntries= fConnection.prepareStatement(
452                     "select distinct SCENARIO.NAME, SCENARIO.SHORT_NAME, SUMMARYENTRY.DIM_ID, SUMMARYENTRY.IS_GLOBAL, SUMMARYENTRY.COMMENT_ID " + //$NON-NLS-1$
453
"from VARIATION, SCENARIO, SUMMARYENTRY " + //$NON-NLS-1$
454
"where SUMMARYENTRY.VARIATION_ID = VARIATION.ID " + //$NON-NLS-1$
455
"and VARIATION.KEYVALPAIRS LIKE ? " + //$NON-NLS-1$
456
"and SUMMARYENTRY.SCENARIO_ID = SCENARIO.ID " + //$NON-NLS-1$
457
"and SUMMARYENTRY.IS_GLOBAL = 1 " + //$NON-NLS-1$
458
"order by SCENARIO.NAME" //$NON-NLS-1$
459
);
460         fQueryGlobalSummaryEntries.setString(1, variations.toExactMatchString());
461         return fQueryGlobalSummaryEntries.executeQuery();
462     }
463
464     ResultSet JavaDoc querySummaryEntries(Variations variations, String JavaDoc scenarioPattern) throws SQLException JavaDoc {
465         if (fQuerySummaryEntries == null)
466             fQuerySummaryEntries= fConnection.prepareStatement(
467                     "select distinct SCENARIO.NAME, SCENARIO.SHORT_NAME, SUMMARYENTRY.DIM_ID, SUMMARYENTRY.IS_GLOBAL, SUMMARYENTRY.COMMENT_ID " + //$NON-NLS-1$
468
"from VARIATION, SCENARIO, SUMMARYENTRY " + //$NON-NLS-1$
469
"where SUMMARYENTRY.VARIATION_ID = VARIATION.ID " + //$NON-NLS-1$
470
"and VARIATION.KEYVALPAIRS LIKE ? " + //$NON-NLS-1$
471
"and SUMMARYENTRY.SCENARIO_ID = SCENARIO.ID " + //$NON-NLS-1$
472
"and SCENARIO.NAME like ? " + //$NON-NLS-1$
473
"order by SCENARIO.NAME" //$NON-NLS-1$
474
);
475         fQuerySummaryEntries.setString(1, variations.toExactMatchString());
476         fQuerySummaryEntries.setString(2, scenarioPattern);
477         return fQuerySummaryEntries.executeQuery();
478     }
479
480     void insertFailure(int variation_id, int scenario_id, String JavaDoc message) throws SQLException JavaDoc {
481         if (fInsertFailure == null)
482             fInsertFailure= fConnection.prepareStatement("insert into FAILURE values (?, ?, ?)"); //$NON-NLS-1$
483
fInsertFailure.setInt(1, variation_id);
484         fInsertFailure.setInt(2, scenario_id);
485         fInsertFailure.setString(3, message);
486         fInsertFailure.executeUpdate();
487     }
488
489     public ResultSet JavaDoc queryFailure(Variations variations, String JavaDoc scenarioPattern) throws SQLException JavaDoc {
490         if (fQueryFailure == null)
491             fQueryFailure= fConnection.prepareStatement("select SCENARIO.NAME, FAILURE.MESSAGE from FAILURE, VARIATION, SCENARIO where " + //$NON-NLS-1$
492
"FAILURE.VARIATION_ID = VARIATION.ID and VARIATION.KEYVALPAIRS LIKE ? and " + //$NON-NLS-1$
493
"FAILURE.SCENARIO_ID = SCENARIO.ID and SCENARIO.NAME LIKE ?" //$NON-NLS-1$
494
);
495         fQueryFailure.setString(1, variations.toExactMatchString());
496         fQueryFailure.setString(2, scenarioPattern);
497         return fQueryFailure.executeQuery();
498     }
499     
500     int getCommentId(int commentKind, String JavaDoc comment) throws SQLException JavaDoc {
501         if (comment.length() > 400)
502             comment= comment.substring(0, 400);
503         if (fQueryComment == null)
504             fQueryComment= fConnection.prepareStatement("select ID from COMMENT where KIND = ? and TEXT = ?"); //$NON-NLS-1$
505
fQueryComment.setInt(1, commentKind);
506         fQueryComment.setString(2, comment);
507         ResultSet JavaDoc result= fQueryComment.executeQuery();
508         while (result.next())
509             return result.getInt(1);
510
511         if (fInsertComment == null)
512             fInsertComment= fConnection.prepareStatement("insert into COMMENT (KIND, TEXT) values (?, ?)", Statement.RETURN_GENERATED_KEYS); //$NON-NLS-1$
513
fInsertComment.setInt(1, commentKind);
514         fInsertComment.setString(2, comment);
515         return create(fInsertComment);
516     }
517
518     public ResultSet JavaDoc getComment(int comment_id) throws SQLException JavaDoc {
519         if (fQueryComment2 == null)
520             fQueryComment2= fConnection.prepareStatement("select KIND, TEXT from COMMENT where ID = ?"); //$NON-NLS-1$
521
fQueryComment2.setInt(1, comment_id);
522         return fQueryComment2.executeQuery();
523     }
524 }
525
Popular Tags