@@ -185,59 +185,26 @@ public AnswerItem<TestCaseExecutionQueue> readByKey(long queueid) {
185
185
}
186
186
187
187
@ Override
188
- public AnswerList <TestCaseExecutionQueue > readByTagByCriteria (String tag , int start , int amount , String sort , String searchTerm , Map < String , List < String >> individualSearch ) throws CerberusException {
188
+ public AnswerList <Long > readMaxIdListByTag (String tag ) throws CerberusException {
189
189
MessageEvent msg = new MessageEvent (MessageEventEnum .DATA_OPERATION_OK );
190
- AnswerList <TestCaseExecutionQueue > answer = new AnswerList <>();
191
- List <String > individalColumnSearchValues = new ArrayList <>();
192
-
190
+ AnswerList <Long > answer = new AnswerList <>();
193
191
final StringBuilder query = new StringBuilder ();
194
192
195
- query .append ("SELECT * FROM testcaseexecutionqueue exq " );
196
- query .append ("left join testcase tec on exq.Test = tec.Test and exq.TestCase = tec.TestCase " );
197
- query .append ("left join application app on tec.application = app.application " );
198
- query .append ("where exq.ID IN " );
199
- query .append ("(select MAX(exq.ID) from testcaseexecutionqueue exq " );
200
-
193
+ query .append ("SELECT MAX(exq.ID) from testcaseexecutionqueue exq " );
201
194
query .append ("where 1=1 " );
202
195
if (!StringUtil .isEmptyOrNull (tag )) {
203
196
query .append ("and exq.tag = ? " );
204
197
}
205
-
206
- query .append ("group by exq.test, exq.testcase, exq.Environment, exq.Browser, exq.Country) " );
207
- if (!StringUtil .isEmptyOrNull (searchTerm )) {
208
- query .append ("and (exq.`test` like ? " );
209
- query .append (" or exq.`testCase` like ? " );
210
- query .append (" or tec.`application` like ? " );
211
- query .append (" or tec.`bugs` like ? " );
212
- query .append (" or tec.`priority` like ? " );
213
- query .append (" or tec.`description` like ? )" );
214
- }
215
- if (individualSearch != null && !individualSearch .isEmpty ()) {
216
- query .append (" and ( 1=1 " );
217
- for (Map .Entry <String , List <String >> entry : individualSearch .entrySet ()) {
218
- query .append (" and " );
219
- query .append (SqlUtil .getInSQLClauseForPreparedStatement (entry .getKey (), entry .getValue ()));
220
- individalColumnSearchValues .addAll (entry .getValue ());
221
- }
222
- query .append (" ) " );
223
- }
224
-
225
- if (!StringUtil .isEmptyOrNull (sort )) {
226
- query .append (" order by " ).append (sort );
227
- }
228
-
229
- if ((amount <= 0 ) || (amount >= MAX_ROW_SELECTED )) {
230
- query .append (" limit " ).append (start ).append (" , " ).append (MAX_ROW_SELECTED );
231
- } else {
232
- query .append (" limit " ).append (start ).append (" , " ).append (amount );
233
- }
198
+ query .append ("group by exq.test, exq.testcase, exq.Environment, exq.Browser, exq.Country " );
199
+ query .append (" limit " ).append (MAX_ROW_SELECTED );
234
200
235
201
// Debug message on SQL.
236
202
if (LOG .isDebugEnabled ()) {
237
203
LOG .debug ("SQL : " + query .toString ());
204
+ LOG .debug ("SQL.param.tag : " + tag );
238
205
}
239
206
240
- List <TestCaseExecutionQueue > testCaseExecutionInQueueList = new ArrayList <>();
207
+ List <Long > testCaseExecutionInQueueList = new ArrayList <>();
241
208
Connection connection = this .databaseSpring .connect ();
242
209
try {
243
210
PreparedStatement preStat = connection .prepareStatement (query .toString ());
@@ -246,17 +213,75 @@ public AnswerList<TestCaseExecutionQueue> readByTagByCriteria(String tag, int st
246
213
if (!StringUtil .isEmptyOrNull (tag )) {
247
214
preStat .setString (i ++, tag );
248
215
}
249
- if (!StringUtil .isEmptyOrNull (searchTerm )) {
250
- preStat .setString (i ++, "%" + searchTerm + "%" );
251
- preStat .setString (i ++, "%" + searchTerm + "%" );
252
- preStat .setString (i ++, "%" + searchTerm + "%" );
253
- preStat .setString (i ++, "%" + searchTerm + "%" );
254
- preStat .setString (i ++, "%" + searchTerm + "%" );
255
- preStat .setString (i ++, "%" + searchTerm + "%" );
216
+
217
+ try {
218
+ ResultSet resultSet = preStat .executeQuery ();
219
+ try {
220
+ while (resultSet .next ()) {
221
+ testCaseExecutionInQueueList .add (resultSet .getLong (1 ));
222
+ }
223
+ msg .setDescription (msg .getDescription ().replace ("%ITEM%" , "TestCaseExecutionInQueue" ).replace ("%OPERATION%" , "SELECT" ));
224
+ answer .setDataList (testCaseExecutionInQueueList );
225
+ } catch (SQLException exception ) {
226
+ LOG .error ("Unable to execute query : " + exception .toString ());
227
+ msg = new MessageEvent (MessageEventEnum .DATA_OPERATION_ERROR_UNEXPECTED );
228
+ msg .setDescription (msg .getDescription ().replace ("%DESCRIPTION%" , "Unable to retrieve the list of entries!" ));
229
+ testCaseExecutionInQueueList = null ;
230
+ } finally {
231
+ resultSet .close ();
232
+ }
233
+ } catch (SQLException exception ) {
234
+ LOG .error ("Unable to execute query : " + exception .toString ());
235
+ msg = new MessageEvent (MessageEventEnum .DATA_OPERATION_ERROR_UNEXPECTED );
236
+ msg .setDescription (msg .getDescription ().replace ("%DESCRIPTION%" , "Unable to retrieve the list of entries!" ));
237
+ testCaseExecutionInQueueList = null ;
238
+ } finally {
239
+ preStat .close ();
256
240
}
257
- for (String individualColumnSearchValue : individalColumnSearchValues ) {
258
- preStat .setString (i ++, individualColumnSearchValue );
241
+ } catch (SQLException exception ) {
242
+ LOG .error ("Unable to execute query : " + exception .toString ());
243
+ msg = new MessageEvent (MessageEventEnum .DATA_OPERATION_ERROR_UNEXPECTED );
244
+ msg .setDescription (msg .getDescription ().replace ("%DESCRIPTION%" , "Unable to retrieve the list of entries!" ));
245
+ testCaseExecutionInQueueList = null ;
246
+ } finally {
247
+ try {
248
+ if (connection != null ) {
249
+ connection .close ();
250
+ }
251
+ } catch (SQLException e ) {
252
+ LOG .warn (e .toString ());
253
+ msg = new MessageEvent (MessageEventEnum .DATA_OPERATION_ERROR_UNEXPECTED );
254
+ msg .setDescription (msg .getDescription ().replace ("%DESCRIPTION%" , "Unable to retrieve the list of entries!" ));
259
255
}
256
+ }
257
+ answer .setResultMessage (msg );
258
+ return answer ;
259
+ }
260
+
261
+ @ Override
262
+ public AnswerList <TestCaseExecutionQueue > readByQueueIdList (List <Long > queueIDList ) throws CerberusException {
263
+ MessageEvent msg = new MessageEvent (MessageEventEnum .DATA_OPERATION_OK );
264
+ AnswerList <TestCaseExecutionQueue > answer = new AnswerList <>();
265
+
266
+ final StringBuilder query = new StringBuilder ();
267
+
268
+ query .append ("SELECT * FROM testcaseexecutionqueue exq " );
269
+ query .append ("left join testcase tec on exq.Test = tec.Test and exq.TestCase = tec.TestCase " );
270
+ query .append ("left join application app on tec.application = app.application " );
271
+ query .append ("where " );
272
+ query .append (SqlUtil .createWhereInClauseLong ("exq.ID" , queueIDList , "" , "" ));
273
+ query .append (" limit 10000" );
274
+
275
+ // Debug message on SQL.
276
+ if (LOG .isDebugEnabled ()) {
277
+ LOG .debug ("SQL : " + query .toString ());
278
+ }
279
+
280
+ List <TestCaseExecutionQueue > testCaseExecutionInQueueList = new ArrayList <>();
281
+ Connection connection = this .databaseSpring .connect ();
282
+
283
+ try {
284
+ PreparedStatement preStat = connection .prepareStatement (query .toString ());
260
285
261
286
try {
262
287
ResultSet resultSet = preStat .executeQuery ();
0 commit comments