How to use createInClauseFromList method of org.cerberus.crud.dao.impl.TestCaseDAO class

Best Cerberus-source code snippet using org.cerberus.crud.dao.impl.TestCaseDAO.createInClauseFromList

Source:TestCaseDAO.java Github

copy

Full Screen

...896 query.append("LEFT JOIN testcaselabel tel ON tec.test = tel.test AND tec.testcase = tel.testcase ");897 query.append("LEFT JOIN campaignlabel cpl ON cpl.labelId = tel.labelId ");898 }899 query.append("WHERE 1=1 AND tec.tcactive = 'Y' ");900 query.append(createInClauseFromList(test, "tec.test", "AND ", " "));901 query.append(createInClauseFromList(idProject, "tec.project", "AND ", " "));902 query.append(createInClauseFromList(app, "tec.application", "AND ", " "));903 query.append(createInClauseFromList(creator, "tec.usrCreated", "AND ", " "));904 query.append(createInClauseFromList(implementer, "tec.implementer", "AND ", " "));905 query.append(createInClauseFromList(priority, "tec.priority", "AND ", " "));906 query.append(createInClauseFromList(group, "tec.group", "AND ", " "));907 query.append(createInClauseFromList(status, "tec.status", "AND ", " "));908 query.append(createInClauseFromList(system, "app.system", "AND ", " "));909 query.append(createInClauseFromList(labelid, "tel.labelid", "AND ", " "));910 if (campaign != null) {911 query.append(createInClauseFromList(campaign, "cpl.campaign", " AND (", ") "));912 }913 query.append("GROUP BY tec.test, tec.testcase ");914 if (length != -1) {915 query.append("LIMIT ?");916 }917 // Debug message on SQL.918 if (LOG.isDebugEnabled()) {919 LOG.debug("SQL : " + query.toString());920 }921 Connection connection = this.databaseSpring.connect();922 try {923 PreparedStatement preStat = connection.prepareStatement(query.toString());924 if (length != -1) {925 preStat.setInt(1, length);926 }927 try {928 ResultSet resultSet = preStat.executeQuery();929 try {930 //gets the data931 while (resultSet.next()) {932 testCaseList.add(this.loadFromResultSet(resultSet));933 }934 if (testCaseList.size() >= MAX_ROW_SELECTED) { // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.935 LOG.error("Partial Result in the query.");936 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);937 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));938 answer = new AnswerList(testCaseList, testCaseList.size());939 } else if (testCaseList.size() <= 0) {940 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);941 answer = new AnswerList(testCaseList, testCaseList.size());942 } else {943 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);944 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));945 answer = new AnswerList(testCaseList, testCaseList.size());946 }947 } catch (SQLException exception) {948 LOG.error("Unable to execute query : " + exception.toString());949 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);950 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));951 } finally {952 if (resultSet != null) {953 resultSet.close();954 }955 }956 } catch (SQLException exception) {957 LOG.error("Unable to execute query : " + exception.toString());958 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);959 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));960 } finally {961 if (preStat != null) {962 preStat.close();963 }964 }965 } catch (SQLException exception) {966 LOG.error("Unable to execute query : " + exception.toString());967 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);968 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));969 } finally {970 try {971 if (!this.databaseSpring.isOnTransaction()) {972 if (connection != null) {973 connection.close();974 }975 }976 } catch (SQLException exception) {977 LOG.warn("Unable to close connection : " + exception.toString());978 }979 }980 answer.setResultMessage(msg);981 answer.setDataList(testCaseList);982 return answer;983 }984 @Override985 public List<String> findUniqueDataOfColumn(String column) {986 List<String> list = null;987 final String query = "SELECT DISTINCT tec." + column + " FROM testcase tec LEFT OUTER JOIN application a ON a.application=tec.application ORDER BY tec." + column + " ASC";988 // Debug message on SQL.989 if (LOG.isDebugEnabled()) {990 LOG.debug("SQL : " + query);991 }992 993 try(Connection connection = this.databaseSpring.connect();994 PreparedStatement preStat = connection.prepareStatement(query);995 ResultSet resultSet = preStat.executeQuery();) {996 997 list = new ArrayList<String>();998 while (resultSet.next()){999 list.add(resultSet.getString(1));1000 }1001 } catch (SQLException exception) {1002 LOG.error("Unable to execute query : " + exception.toString());1003 }1004 return list;1005 }1006 @Override1007 public boolean deleteTestCase(TestCase testCase) {1008 boolean bool = false;1009 final String query = "DELETE FROM testcase WHERE test = ? AND testcase = ?";1010 // Debug message on SQL.1011 if (LOG.isDebugEnabled()) {1012 LOG.debug("SQL : " + query);1013 }1014 Connection connection = this.databaseSpring.connect();1015 try {1016 PreparedStatement preStat = connection.prepareStatement(query);1017 try {1018 preStat.setString(1, testCase.getTest());1019 preStat.setString(2, testCase.getTestCase());1020 bool = preStat.executeUpdate() > 0;1021 } catch (SQLException exception) {1022 LOG.error("Unable to execute query : " + exception.toString());1023 } finally {1024 preStat.close();1025 }1026 } catch (SQLException exception) {1027 LOG.error("Unable to execute query : " + exception.toString());1028 } finally {1029 try {1030 if (connection != null) {1031 connection.close();1032 }1033 } catch (SQLException e) {1034 LOG.warn(e.toString());1035 }1036 }1037 return bool;1038 }1039 @Override1040 public void updateTestCase(TestCase testCase) throws CerberusException {1041 final String sql = "UPDATE testcase tc SET tc.Application = ?, tc.Project = ?, tc.BehaviorOrValueExpected = ?, tc.activeQA = ?, tc.activeUAT = ?, tc.activePROD = ?, "1042 + "tc.Priority = ?, tc.Status = ?, tc.TcActive = ?, tc.Description = ?, tc.Group = ?, tc.HowTo = ?, tc.Comment = ?, tc.Ticket = ?, tc.FromBuild = ?, "1043 + "tc.FromRev = ?, tc.ToBuild = ?, tc.ToRev = ?, tc.BugID = ?, tc.TargetBuild = ?, tc.Implementer = ?, tc.UsrModif = ?, tc.TargetRev = ?, tc.`function` = ?,"1044 + " `conditionOper` = ?, `conditionVal1` = ?, `conditionVal2` = ?, `useragent` = ?, `screensize` = ?, `testCaseVersion` = ?, dateModif = CURRENT_TIMESTAMP "1045 + "WHERE tc.Test = ? AND tc.Testcase = ?";1046 // Debug message on SQL.1047 if (LOG.isDebugEnabled()) {1048 LOG.debug("SQL : " + sql);1049 }1050 Connection connection = this.databaseSpring.connect();1051 try {1052 PreparedStatement preStat = connection.prepareStatement(sql);1053 try {1054 int i = 1;1055 preStat.setString(i++, testCase.getApplication());1056 preStat.setString(i++, testCase.getProject());1057 preStat.setString(i++, testCase.getBehaviorOrValueExpected());1058 preStat.setString(i++, testCase.getActiveQA().equals("Y") ? "Y" : "N");1059 preStat.setString(i++, testCase.getActiveUAT().equals("Y") ? "Y" : "N");1060 preStat.setString(i++, testCase.getActivePROD().equals("Y") ? "Y" : "N");1061 preStat.setString(i++, Integer.toString(testCase.getPriority()));1062 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getStatus(), ""));1063 preStat.setString(i++, testCase.getTcActive().equals("Y") ? "Y" : "N");1064 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getDescription(), ""));1065 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getGroup(), ""));1066 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getHowTo(), ""));1067 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getComment(), ""));1068 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTicket(), ""));1069 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getFromBuild(), ""));1070 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getFromRev(), ""));1071 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getToBuild(), ""));1072 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getToRev(), ""));1073 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getBugID(), ""));1074 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTargetBuild(), ""));1075 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getImplementer(), ""));1076 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getUsrModif(), ""));1077 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTargetRev(), ""));1078 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getFunction(), ""));1079 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getConditionOper(), ""));1080 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getConditionVal1(), ""));1081 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getConditionVal2(), ""));1082 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getUserAgent(), ""));1083 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getScreenSize(), ""));1084 preStat.setInt(i++, ParameterParserUtil.parseIntegerParam(testCase.getTestCaseVersion(), 0));1085 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTest(), ""));1086 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTestCase(), ""));1087 preStat.executeUpdate();1088 } catch (SQLException exception) {1089 LOG.error("Unable to execute query : " + exception.toString());1090 } finally {1091 preStat.close();1092 }1093 } catch (SQLException exception) {1094 LOG.error("Unable to execute query : " + exception.toString());1095 } finally {1096 try {1097 if (connection != null) {1098 connection.close();1099 }1100 } catch (SQLException e) {1101 LOG.warn(e.toString());1102 }1103 }1104 }1105 @Override1106 public String getMaxNumberTestCase(String test) {1107 String max = "";1108 final String sql = "SELECT Max( CAST(Testcase AS UNSIGNED) ) as MAXTC FROM testcase where test = ?";1109 // Debug message on SQL.1110 if (LOG.isDebugEnabled()) {1111 LOG.debug("SQL : " + sql);1112 }1113 Connection connection = this.databaseSpring.connect();1114 try {1115 PreparedStatement preStat = connection.prepareStatement(sql);1116 try {1117 preStat.setString(1, test);1118 ResultSet resultSet = preStat.executeQuery();1119 try {1120 if (resultSet.next()) {1121 max = resultSet.getString("MAXTC");1122 }1123 } catch (SQLException exception) {1124 LOG.error("Unable to execute query : " + exception.toString());1125 } finally {1126 resultSet.close();1127 }1128 } catch (SQLException exception) {1129 LOG.error("Unable to execute query : " + exception.toString());1130 } finally {1131 preStat.close();1132 }1133 } catch (SQLException exception) {1134 LOG.error("Unable to execute query : " + exception.toString());1135 } finally {1136 try {1137 if (connection != null) {1138 connection.close();1139 }1140 } catch (SQLException e) {1141 LOG.warn(e.toString());1142 }1143 }1144 return max;1145 }1146 @Override1147 public AnswerItem<List<TestCase>> findTestCaseByCampaignNameAndCountries(String campaign, String[] countries, boolean withLabelOrBattery, String[] status, String[] system, String[] application, String[] priority, String[] group, Integer maxReturn) {1148 List<TestCase> list = null;1149 AnswerItem answer = new AnswerItem();1150 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1151 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));1152 HashMap<String, String[]> tcParameters = new HashMap<String, String[]>();1153 tcParameters.put("status", status);1154 tcParameters.put("system", system);1155 tcParameters.put("application", application);1156 tcParameters.put("priority", priority);1157 tcParameters.put("countries", countries);1158 tcParameters.put("group", group);1159 StringBuilder query = new StringBuilder("SELECT tec.*, app.system FROM testcase tec ");1160 if (withLabelOrBattery) {1161 query.append("LEFT OUTER JOIN application app ON app.application = tec.application ")1162 .append("INNER JOIN testcasecountry tcc ON tcc.Test = tec.Test and tcc.TestCase = tec.TestCase ")1163 .append("LEFT JOIN testcaselabel tel ON tec.test = tel.test AND tec.testcase = tel.testcase ")1164 .append("LEFT JOIN campaignlabel cpl ON cpl.labelId = tel.labelId ")1165 .append("WHERE (cpl.campaign = ? )");1166 } else if (!withLabelOrBattery && (status != null || system != null || application != null || priority != null)) {1167 query.append("LEFT OUTER JOIN application app ON app.application = tec.application ")1168 .append("INNER JOIN testcasecountry tcc ON tcc.Test = tec.Test and tcc.TestCase = tec.TestCase ")1169 .append("WHERE 1=1");1170 } else {1171 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_VALIDATIONS_ERROR);1172 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "You have a problem in your campaign definition"));1173 answer.setResultMessage(msg);1174 return answer;1175 }1176 for (Entry<String, String[]> entry : tcParameters.entrySet()) {1177 String cle = entry.getKey();1178 String[] valeur = entry.getValue();1179 if (valeur != null && valeur.length > 0) {1180 if (!cle.equals("system") && !cle.equals("countries")) {1181 query.append(" AND tec." + cle + " in (?");1182 } else if (cle.equals("system")) {1183 query.append(" AND app.system in (?");1184 } else {1185 query.append(" AND tcc.Country in (?");1186 }1187 if (valeur.length > 1) {1188 for (int i = 0; i < valeur.length - 1; i++) {1189 query.append(",?");1190 }1191 }1192 query.append(")");1193 }1194 }1195 query.append(" GROUP BY tec.test, tec.testcase LIMIT ?");1196 // Debug message on SQL.1197 if (LOG.isDebugEnabled()) {1198 LOG.debug("SQL : " + query.toString());1199 }1200 Connection connection = this.databaseSpring.connect();1201 try {1202 PreparedStatement preStat = connection.prepareStatement(query.toString());1203 try {1204 int i = 1;1205 if (withLabelOrBattery) {1206 preStat.setString(i++, campaign);1207 }1208 for (Entry<String, String[]> entry : tcParameters.entrySet()) {1209 String[] valeur = entry.getValue();1210 if (valeur != null && valeur.length > 0) {1211 for (String c : valeur) {1212 preStat.setString(i++, c);1213 }1214 }1215 }1216 preStat.setInt(i++, maxReturn);1217 ResultSet resultSet = preStat.executeQuery();1218 list = new ArrayList<TestCase>();1219 try {1220 while (resultSet.next()) {1221 list.add(this.loadFromResultSet(resultSet));1222 }1223 if (list.size() >= maxReturn) { // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.1224 LOG.error("Partial Result in the query.");1225 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);1226 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + maxReturn));1227 answer = new AnswerItem(list);1228 } else if (list.size() <= 0) {1229 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);1230 answer = new AnswerItem(list);1231 } else {1232 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1233 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));1234 answer = new AnswerItem(list);1235 }1236 } catch (SQLException exception) {1237 LOG.error("Unable to execute query : " + exception.toString());1238 } finally {1239 answer.setResultMessage(msg);1240 resultSet.close();1241 }1242 } catch (SQLException exception) {1243 LOG.error("Unable to execute query : " + exception.toString());1244 } finally {1245 preStat.close();1246 }1247 } catch (SQLException exception) {1248 LOG.error("Unable to execute query : " + exception.toString());1249 } finally {1250 try {1251 if (connection != null) {1252 connection.close();1253 }1254 } catch (SQLException e) {1255 LOG.warn(e.toString());1256 }1257 }1258 return answer;1259 }1260 @Override1261 public List<TestCase> findTestCaseByTestSystem(String test, String system) {1262 List<TestCase> list = null;1263 StringBuilder sb = new StringBuilder();1264 sb.append("SELECT * FROM testcase tec join application app on tec.application = app.application ");1265 sb.append(" WHERE tec.test = ? and app.system = ? ");1266 // Debug message on SQL.1267 if (LOG.isDebugEnabled()) {1268 LOG.debug("SQL : " + sb.toString());1269 }1270 Connection connection = this.databaseSpring.connect();1271 try {1272 PreparedStatement preStat = connection.prepareStatement(sb.toString());1273 try {1274 preStat.setString(1, test);1275 preStat.setString(2, system);1276 ResultSet resultSet = preStat.executeQuery();1277 try {1278 list = new ArrayList<TestCase>();1279 while (resultSet.next()) {1280 list.add(this.loadFromResultSet(resultSet));1281 }1282 } catch (SQLException exception) {1283 LOG.error("Unable to execute query : " + exception.toString());1284 } finally {1285 resultSet.close();1286 }1287 } catch (SQLException exception) {1288 LOG.error("Unable to execute query : " + exception.toString());1289 } finally {1290 preStat.close();1291 }1292 } catch (SQLException exception) {1293 LOG.error("Unable to execute query : " + exception.toString());1294 } finally {1295 try {1296 if (connection != null) {1297 connection.close();1298 }1299 } catch (SQLException e) {1300 LOG.warn(e.toString());1301 }1302 }1303 return list;1304 }1305 @Override1306 public List<TestCase> findTestCaseByCriteria(String[] test, String[] project, String[] app, String[] active, String[] priority, String[] status, String[] group, String[] targetBuild, String[] targetRev, String[] creator, String[] implementer, String[] function, String[] campaign) {1307 List<TestCase> list = null;1308 StringBuilder sb = new StringBuilder();1309 sb.append("SELECT * FROM testcase tec join application app on tec.application=app.application ");1310 sb.append(" WHERE 1=1 ");1311 sb.append(SqlUtil.createWhereInClause(" AND tec.Test", test == null ? null : Arrays.asList(test), true));1312 sb.append(SqlUtil.createWhereInClause(" AND tec.Project", project == null ? null : Arrays.asList(project), true));1313 sb.append(SqlUtil.createWhereInClause(" AND tec.Application", app == null ? null : Arrays.asList(app), true));1314 sb.append(SqlUtil.createWhereInClause(" AND tec.tcactive", active == null ? null : Arrays.asList(active), true));1315 sb.append(SqlUtil.createWhereInClause(" AND tec.priority", priority == null ? null : Arrays.asList(priority), true));1316 sb.append(SqlUtil.createWhereInClause(" AND tec.status", status == null ? null : Arrays.asList(status), true));1317 sb.append(SqlUtil.createWhereInClause(" AND tec.group", group == null ? null : Arrays.asList(group), true));1318 sb.append(SqlUtil.createWhereInClause(" AND tec.targetBuild", targetBuild == null ? null : Arrays.asList(targetBuild), true));1319 sb.append(SqlUtil.createWhereInClause(" AND tec.targetRev", targetRev == null ? null : Arrays.asList(targetRev), true));1320 sb.append(SqlUtil.createWhereInClause(" AND tec.creator", creator == null ? null : Arrays.asList(creator), true));1321 sb.append(SqlUtil.createWhereInClause(" AND tec.implementer", implementer == null ? null : Arrays.asList(implementer), true));1322 sb.append(SqlUtil.createWhereInClause(" AND tec.funtion", function == null ? null : Arrays.asList(function), true));1323 sb.append(" GROUP BY tec.test, tec.testcase ");1324 // Debug message on SQL.1325 if (LOG.isDebugEnabled()) {1326 LOG.debug("SQL : " + sb.toString());1327 }1328 Connection connection = this.databaseSpring.connect();1329 try {1330 PreparedStatement preStat = connection.prepareStatement(sb.toString());1331 try {1332 ResultSet resultSet = preStat.executeQuery();1333 try {1334 list = new ArrayList<TestCase>();1335 while (resultSet.next()) {1336 list.add(this.loadFromResultSet(resultSet));1337 }1338 } catch (SQLException exception) {1339 LOG.error("Unable to execute query : " + exception.toString());1340 } finally {1341 resultSet.close();1342 }1343 } catch (SQLException exception) {1344 LOG.error("Unable to execute query : " + exception.toString());1345 } finally {1346 preStat.close();1347 }1348 } catch (SQLException exception) {1349 LOG.error("Unable to execute query : " + exception.toString());1350 } finally {1351 try {1352 if (connection != null) {1353 connection.close();1354 }1355 } catch (SQLException e) {1356 LOG.warn(e.toString());1357 }1358 }1359 return list;1360 }1361 @Override1362 public String findSystemOfTestCase(String test, String testcase) throws CerberusException {1363 String result = "";1364 final String sql = "SELECT system from application app join testcase tec on tec.application=app.Application where tec.test= ? and tec.testcase= ?";1365 // Debug message on SQL.1366 if (LOG.isDebugEnabled()) {1367 LOG.debug("SQL : " + sql);1368 }1369 Connection connection = this.databaseSpring.connect();1370 try {1371 PreparedStatement preStat = connection.prepareStatement(sql);1372 try {1373 preStat.setString(1, test);1374 preStat.setString(2, testcase);1375 ResultSet resultSet = preStat.executeQuery();1376 try {1377 if (resultSet.next()) {1378 result = resultSet.getString("app.system");1379 }1380 } catch (SQLException exception) {1381 LOG.error("Unable to execute query : " + exception.toString());1382 } finally {1383 resultSet.close();1384 }1385 } catch (SQLException exception) {1386 LOG.error("Unable to execute query : " + exception.toString());1387 } finally {1388 preStat.close();1389 }1390 } catch (SQLException exception) {1391 LOG.error("Unable to execute query : " + exception.toString());1392 } finally {1393 try {1394 if (connection != null) {1395 connection.close();1396 }1397 } catch (SQLException e) {1398 LOG.warn(e.toString());1399 }1400 }1401 return result;1402 }1403 @Override1404 public AnswerList readTestCaseByStepsInLibrary(String test) {1405 AnswerList response = new AnswerList();1406 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1407 List<TestCase> list = new ArrayList<TestCase>();1408 StringBuilder query = new StringBuilder();1409 query.append("SELECT * FROM testcase tec ");1410 query.append("LEFT OUTER JOIN application app ON app.application=tec.application ");1411 query.append("INNER JOIN testcasestep tcs ON tec.test = tcs.test and tec.testcase = tcs.testcase ");1412 query.append("WHERE tec.test= ? and (tcs.inlibrary = 'Y' or tcs.inlibrary = 'y') ");1413 query.append("GROUP BY tec.testcase order by tec.testcase ");1414 // Debug message on SQL.1415 if (LOG.isDebugEnabled()) {1416 LOG.debug("SQL : " + query.toString());1417 }1418 Connection connection = this.databaseSpring.connect();1419 try {1420 PreparedStatement preStat = connection.prepareStatement(query.toString());1421 try {1422 preStat.setString(1, test);1423 ResultSet resultSet = preStat.executeQuery();1424 try {1425 list = new ArrayList<TestCase>();1426 while (resultSet.next()) {1427 list.add(loadFromResultSet(resultSet));1428 }1429 if (list.size() >= MAX_ROW_SELECTED) { // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.1430 LOG.error("Partial Result in the query.");1431 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);1432 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));1433 response = new AnswerList(list, list.size());1434 } else if (list.size() <= 0) {1435 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);1436 response = new AnswerList(list, list.size());1437 } else {1438 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1439 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));1440 response = new AnswerList(list, list.size());1441 }1442 } catch (SQLException exception) {1443 LOG.error("Unable to execute query : " + exception.toString());1444 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1445 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1446 } finally {1447 if (resultSet != null) {1448 resultSet.close();1449 }1450 }1451 } catch (SQLException exception) {1452 LOG.error("Unable to execute query : " + exception.toString());1453 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1454 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1455 } finally {1456 if (preStat != null) {1457 preStat.close();1458 }1459 }1460 } catch (SQLException exception) {1461 LOG.error("Unable to execute query : " + exception.toString());1462 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1463 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1464 } finally {1465 try {1466 if (connection != null) {1467 connection.close();1468 }1469 } catch (SQLException e) {1470 LOG.warn(e.toString());1471 }1472 }1473 response.setDataList(list);1474 response.setResultMessage(msg);1475 return response;1476 }1477 @Override1478 public AnswerItem readByKey(String test, String testCase) {1479 AnswerItem ans = new AnswerItem();1480 TestCase result = null;1481 final String query = "SELECT * FROM `testcase` tec LEFT OUTER JOIN application app ON app.application=tec.application WHERE tec.`test` = ? AND tec.`testcase` = ?";1482 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1483 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));1484 // Debug message on SQL.1485 if (LOG.isDebugEnabled()) {1486 LOG.debug("SQL : " + query);1487 }1488 Connection connection = this.databaseSpring.connect();1489 try {1490 PreparedStatement preStat = connection.prepareStatement(query);1491 try {1492 preStat.setString(1, test);1493 preStat.setString(2, testCase);1494 ResultSet resultSet = preStat.executeQuery();1495 try {1496 if (resultSet.first()) {1497 result = loadFromResultSet(resultSet);1498 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1499 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));1500 ans.setItem(result);1501 } else {1502 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);1503 }1504 } catch (SQLException exception) {1505 LOG.error("Unable to execute query : " + exception.toString());1506 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1507 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1508 } finally {1509 resultSet.close();1510 }1511 } catch (SQLException exception) {1512 LOG.error("Unable to execute query : " + exception.toString());1513 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1514 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1515 } finally {1516 preStat.close();1517 }1518 } catch (SQLException exception) {1519 LOG.error("Unable to execute query : " + exception.toString());1520 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1521 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1522 } finally {1523 try {1524 if (connection != null) {1525 connection.close();1526 }1527 } catch (SQLException exception) {1528 LOG.warn("Unable to close connection : " + exception.toString());1529 }1530 }1531 //sets the message1532 ans.setResultMessage(msg);1533 return ans;1534 }1535 @Override1536 public AnswerList<List<String>> readDistinctValuesByCriteria(String system, String test, String searchTerm, Map<String, List<String>> individualSearch, String columnName) {1537 AnswerList answer = new AnswerList();1538 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1539 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));1540 List<String> distinctValues = new ArrayList<>();1541 StringBuilder searchSQL = new StringBuilder();1542 List<String> individalColumnSearchValues = new ArrayList<String>();1543 StringBuilder query = new StringBuilder();1544 query.append("SELECT distinct ");1545 query.append(columnName);1546 query.append(" as distinctValues FROM testcase tec ");1547 query.append(" LEFT OUTER JOIN testcaselabel tel on tec.test = tel.test AND tec.testcase = tel.testcase ");1548 query.append(" LEFT OUTER JOIN label lab on tel.labelId = lab.id ");1549 query.append(" LEFT OUTER JOIN application app on app.application = tec.application ");1550 searchSQL.append("WHERE 1=1");1551 if (!StringUtil.isNullOrEmpty(system)) {1552 searchSQL.append(" AND app.`system` = ? ");1553 }1554 if (!StringUtil.isNullOrEmpty(test)) {1555 searchSQL.append(" AND tec.`test` = ?");1556 }1557 if (!StringUtil.isNullOrEmpty(searchTerm)) {1558 searchSQL.append(" and (tec.`testcase` like ?");1559 searchSQL.append(" or tec.`test` like ?");1560 searchSQL.append(" or tec.`application` like ?");1561 searchSQL.append(" or tec.`project` like ?");1562 searchSQL.append(" or tec.`usrCreated` like ?");1563 searchSQL.append(" or tec.`usrModif` like ?");1564 searchSQL.append(" or tec.`tcactive` like ?");1565 searchSQL.append(" or tec.`status` like ?");1566 searchSQL.append(" or tec.`group` like ?");1567 searchSQL.append(" or tec.`priority` like ?");1568 searchSQL.append(" or tec.`dateCreated` like ?");1569 searchSQL.append(" or lab.`label` like ?");1570 searchSQL.append(" or tec.`description` like ?)");1571 }1572 if (individualSearch != null && !individualSearch.isEmpty()) {1573 searchSQL.append(" and ( 1=1 ");1574 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {1575 searchSQL.append(" and ");1576 searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));1577 individalColumnSearchValues.addAll(entry.getValue());1578 }1579 searchSQL.append(" )");1580 }1581 query.append(searchSQL);1582 query.append(" order by ").append(columnName).append(" asc");1583 // Debug message on SQL.1584 if (LOG.isDebugEnabled()) {1585 LOG.debug("SQL : " + query.toString());1586 }1587 try (Connection connection = databaseSpring.connect();1588 PreparedStatement preStat = connection.prepareStatement(query.toString());1589 Statement stm = connection.createStatement();) {1590 int i = 1;1591 if (!StringUtil.isNullOrEmpty(system)) {1592 preStat.setString(i++, system);1593 }1594 if (!StringUtil.isNullOrEmpty(test)) {1595 preStat.setString(i++, test);1596 }1597 if (!Strings.isNullOrEmpty(searchTerm)) {1598 preStat.setString(i++, "%" + searchTerm + "%");1599 preStat.setString(i++, "%" + searchTerm + "%");1600 preStat.setString(i++, "%" + searchTerm + "%");1601 preStat.setString(i++, "%" + searchTerm + "%");1602 preStat.setString(i++, "%" + searchTerm + "%");1603 preStat.setString(i++, "%" + searchTerm + "%");1604 preStat.setString(i++, "%" + searchTerm + "%");1605 preStat.setString(i++, "%" + searchTerm + "%");1606 preStat.setString(i++, "%" + searchTerm + "%");1607 preStat.setString(i++, "%" + searchTerm + "%");1608 preStat.setString(i++, "%" + searchTerm + "%");1609 preStat.setString(i++, "%" + searchTerm + "%");1610 }1611 for (String individualColumnSearchValue : individalColumnSearchValues) {1612 preStat.setString(i++, individualColumnSearchValue);1613 }1614 try(ResultSet resultSet = preStat.executeQuery();1615 ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()");) {1616 //gets the data1617 while (resultSet.next()) {1618 distinctValues.add(resultSet.getString("distinctValues") == null ? "" : resultSet.getString("distinctValues"));1619 }1620 //get the total number of rows1621 int nrTotalRows = 0;1622 if (rowSet != null && rowSet.next()) {1623 nrTotalRows = rowSet.getInt(1);1624 }1625 if (distinctValues.size() >= MAX_ROW_SELECTED) { // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.1626 LOG.error("Partial Result in the query.");1627 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);1628 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));1629 answer = new AnswerList(distinctValues, nrTotalRows);1630 } else if (distinctValues.size() <= 0) {1631 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);1632 answer = new AnswerList(distinctValues, nrTotalRows);1633 } else {1634 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1635 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));1636 answer = new AnswerList(distinctValues, nrTotalRows);1637 }1638 }catch (SQLException exception) {1639 LOG.error("Unable to execute query : " + exception.toString());1640 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1641 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1642 } 1643 1644 } catch (Exception e) {1645 LOG.warn("Unable to execute query : " + e.toString());1646 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",1647 e.toString());1648 } finally {1649 // We always set the result message1650 answer.setResultMessage(msg);1651 }1652 answer.setResultMessage(msg);1653 answer.setDataList(distinctValues);1654 return answer;1655 }1656 @Override1657 public Answer update(String keyTest, String keyTestCase, TestCase tc) {1658 MessageEvent msg = null;1659 StringBuilder query = new StringBuilder("UPDATE testcase SET");1660 query.append(" test = ?,");1661 query.append(" testcase = ?,");1662 query.append(" implementer = ?,");1663 query.append(" project = ?,");1664 query.append(" ticket = ?,");1665 query.append(" application = ?,");1666 query.append(" activeQA = ?,");1667 query.append(" activeUAT = ?,");1668 query.append(" activeProd = ?,");1669 query.append(" status = ?,");1670 query.append(" description = ?,");1671 query.append(" behaviorOrValueExpected = ?,");1672 query.append(" howTo = ?,");1673 query.append(" tcactive = ?,");1674 query.append(" fromBuild = ?,");1675 query.append(" fromRev = ?,");1676 query.append(" toBuild = ?,");1677 query.append(" toRev = ?,");1678 query.append(" bugId = ?,");1679 query.append(" targetBuild = ?,");1680 query.append(" targetRev = ?,");1681 query.append(" comment = ?,");1682 query.append(" function = ?,");1683 query.append(" priority = ?,");1684 query.append(" `group` = ?,");1685 query.append(" `origine` = ?,");1686 query.append(" `userAgent` = ?,");1687 query.append(" `screenSize` = ?,");1688 query.append(" UsrModif = ?,");1689 query.append(" conditionOper = ?,");1690 query.append(" conditionVal1 = ?,");1691 query.append(" conditionVal2 = ?,");1692 query.append(" testCaseVersion = ?,");1693 query.append(" DateModif = CURRENT_TIMESTAMP");1694 query.append(" WHERE test = ? AND testcase = ?;");1695 // Debug message on SQL.1696 if (LOG.isDebugEnabled()) {1697 LOG.debug("SQL : " + query.toString());1698 }1699 Connection connection = this.databaseSpring.connect();1700 try {1701 PreparedStatement preStat = connection.prepareStatement(query.toString());1702 try {1703 int i = 1;1704 preStat.setString(i++, tc.getTest());1705 preStat.setString(i++, tc.getTestCase());1706 preStat.setString(i++, tc.getImplementer());1707 preStat.setString(i++, tc.getProject());1708 preStat.setString(i++, tc.getTicket());1709 preStat.setString(i++, tc.getApplication());1710 preStat.setString(i++, tc.getActiveQA());1711 preStat.setString(i++, tc.getActiveUAT());1712 preStat.setString(i++, tc.getActivePROD());1713 preStat.setString(i++, tc.getStatus());1714 preStat.setString(i++, tc.getDescription());1715 preStat.setString(i++, tc.getBehaviorOrValueExpected());1716 preStat.setString(i++, tc.getHowTo());1717 preStat.setString(i++, tc.getTcActive());1718 preStat.setString(i++, tc.getFromBuild());1719 preStat.setString(i++, tc.getFromRev());1720 preStat.setString(i++, tc.getToBuild());1721 preStat.setString(i++, tc.getToRev());1722 preStat.setString(i++, tc.getBugID());1723 preStat.setString(i++, tc.getTargetBuild());1724 preStat.setString(i++, tc.getTargetRev());1725 preStat.setString(i++, tc.getComment());1726 preStat.setString(i++, tc.getFunction());1727 preStat.setString(i++, Integer.toString(tc.getPriority()));1728 preStat.setString(i++, tc.getGroup());1729 preStat.setString(i++, tc.getOrigine());1730 preStat.setString(i++, tc.getUserAgent());1731 preStat.setString(i++, tc.getScreenSize());1732 preStat.setString(i++, tc.getUsrModif());1733 preStat.setString(i++, tc.getConditionOper());1734 preStat.setString(i++, tc.getConditionVal1());1735 preStat.setString(i++, tc.getConditionVal2());1736 preStat.setInt(i++, tc.getTestCaseVersion());1737 preStat.setString(i++, keyTest);1738 preStat.setString(i++, keyTestCase);1739 preStat.executeUpdate();1740 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1741 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));1742 } catch (SQLException exception) {1743 LOG.error("Unable to execute query : " + exception.toString());1744 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1745 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1746 } finally {1747 preStat.close();1748 }1749 } catch (SQLException exception) {1750 LOG.error("Unable to execute query : " + exception.toString());1751 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1752 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1753 } finally {1754 try {1755 if (connection != null) {1756 connection.close();1757 }1758 } catch (SQLException exception) {1759 LOG.warn("Unable to close connection : " + exception.toString());1760 }1761 }1762 return new Answer(msg);1763 }1764 @Override1765 public Answer create(TestCase testCase) {1766 MessageEvent msg = null;1767 final StringBuffer sql = new StringBuffer("INSERT INTO `testcase` ")1768 .append(" ( `Test`, `TestCase`, `Application`, `Project`, `Ticket`, ")1769 .append("`Description`, `BehaviorOrValueExpected`, ")1770 .append("`Priority`, `Status`, `TcActive`, ")1771 .append("`Group`, `Origine`, `RefOrigine`, `HowTo`, `Comment`, ")1772 .append("`FromBuild`, `FromRev`, `ToBuild`, `ToRev`, ")1773 .append("`BugID`, `TargetBuild`, `TargetRev`, `UsrCreated`, ")1774 .append("`Implementer`, `function`, `activeQA`, `activeUAT`, `activePROD`, `useragent`, `screenSize`, `conditionOper`, `conditionVal1`, `conditionVal2`, `testCaseVersion`) ")1775 .append("VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ")1776 .append("?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ); ");1777 // Debug message on SQL.1778 if (LOG.isDebugEnabled()) {1779 LOG.debug("SQL : " + sql.toString());1780 }1781 Connection connection = this.databaseSpring.connect();1782 try {1783 PreparedStatement preStat = connection.prepareStatement(sql.toString());1784 try {1785 int i = 1;1786 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTest(), ""));1787 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTestCase(), ""));1788 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getApplication(), ""));1789 preStat.setString(i++, testCase.getProject());1790 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTicket(), ""));1791 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getDescription(), ""));1792 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getBehaviorOrValueExpected(), ""));1793 preStat.setString(i++, Integer.toString(testCase.getPriority()));1794 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getStatus(), ""));1795 preStat.setString(i++, testCase.getTcActive() != null && !testCase.getTcActive().equals("Y") ? "N" : "Y");1796 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getGroup(), ""));1797 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getOrigine(), ""));1798 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getRefOrigine(), ""));1799 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getHowTo(), ""));1800 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getComment(), ""));1801 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getFromBuild(), ""));1802 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getFromRev(), ""));1803 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getToBuild(), ""));1804 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getToRev(), ""));1805 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getBugID(), ""));1806 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTargetBuild(), ""));1807 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTargetRev(), ""));1808 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getUsrCreated(), ""));1809 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getImplementer(), ""));1810 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getFunction(), ""));1811 preStat.setString(i++, testCase.getActiveQA() != null && !testCase.getActiveQA().equals("Y") ? "N" : "Y");1812 preStat.setString(i++, testCase.getActiveUAT() != null && !testCase.getActiveUAT().equals("Y") ? "N" : "Y");1813 preStat.setString(i++, testCase.getActivePROD() != null && !testCase.getActivePROD().equals("N") ? "Y" : "N");1814 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getUserAgent(), ""));1815 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getScreenSize(), ""));1816 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getConditionOper(), ""));1817 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getConditionVal1(), ""));1818 preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getConditionVal2(), ""));1819 preStat.setInt(i++, ParameterParserUtil.parseIntegerParam(testCase.getTestCaseVersion(),0));1820 preStat.executeUpdate();1821 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1822 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));1823 } catch (SQLException exception) {1824 LOG.error("Unable to execute query : " + exception.toString(), exception);1825 if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) { //23000 is the sql state for duplicate entries1826 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);1827 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));1828 } else {1829 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1830 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1831 }1832 } finally {1833 preStat.close();1834 }1835 } catch (SQLException exception) {1836 LOG.error("Unable to execute query : " + exception.toString());1837 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1838 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1839 } finally {1840 try {1841 if (connection != null) {1842 connection.close();1843 }1844 } catch (SQLException exception) {1845 LOG.warn("Unable to close connection : " + exception.toString());1846 }1847 }1848 return new Answer(msg);1849 }1850 @Override1851 public Answer delete(TestCase testCase) {1852 MessageEvent msg = null;1853 final String query = "DELETE FROM testcase WHERE test = ? AND testcase = ?";1854 // Debug message on SQL.1855 if (LOG.isDebugEnabled()) {1856 LOG.debug("SQL : " + query);1857 }1858 Connection connection = this.databaseSpring.connect();1859 try {1860 PreparedStatement preStat = connection.prepareStatement(query);1861 try {1862 preStat.setString(1, testCase.getTest());1863 preStat.setString(2, testCase.getTestCase());1864 preStat.executeUpdate();1865 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1866 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "DELETE"));1867 } catch (SQLException exception) {1868 LOG.error("Unable to execute query : " + exception.toString());1869 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1870 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1871 } finally {1872 preStat.close();1873 }1874 } catch (SQLException exception) {1875 LOG.error("Unable to execute query : " + exception.toString());1876 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1877 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1878 } finally {1879 try {1880 if (connection != null) {1881 connection.close();1882 }1883 } catch (SQLException exception) {1884 LOG.warn("Unable to close connection : " + exception.toString());1885 }1886 }1887 return new Answer(msg);1888 }1889 /**1890 * Uses data of ResultSet to create object {@link TestCase}1891 *1892 * @param resultSet ResultSet relative to select from table TestCase1893 * @return object {@link TestCase}1894 * @throws SQLException when trying to get value from1895 * {@link java.sql.ResultSet#getString(String)}1896 * @see FactoryTestCase1897 */1898 @Override1899 public TestCase loadFromResultSet(ResultSet resultSet) throws SQLException {1900 String test = resultSet.getString("tec.Test");1901 String testCase = resultSet.getString("tec.TestCase");1902 String tcapplication = resultSet.getString("tec.Application");1903 String project = resultSet.getString("tec.Project");1904 String ticket = resultSet.getString("tec.Ticket");1905 String description = resultSet.getString("tec.Description");1906 String behavior = resultSet.getString("tec.BehaviorOrValueExpected");1907 int priority = resultSet.getInt("tec.Priority");1908 int testCaseVersion = resultSet.getInt("tec.TestCaseVersion");1909 String status = resultSet.getString("tec.Status");1910 String tcactive = resultSet.getString("tec.TcActive");1911 String conditionOper = resultSet.getString("tec.ConditionOper");1912 String conditionVal1 = resultSet.getString("tec.ConditionVal1");1913 String conditionVal2 = resultSet.getString("tec.ConditionVal2");1914 String group = resultSet.getString("tec.Group");1915 String origin = resultSet.getString("tec.Origine");1916 String refOrigin = resultSet.getString("tec.RefOrigine");1917 String howTo = resultSet.getString("tec.HowTo");1918 String comment = resultSet.getString("tec.Comment");1919 String fromSprint = resultSet.getString("tec.FromBuild");1920 String fromRevision = resultSet.getString("tec.FromRev");1921 String toSprint = resultSet.getString("tec.ToBuild");1922 String toRevision = resultSet.getString("tec.ToRev");1923 String bugID = resultSet.getString("tec.BugID");1924 String targetSprint = resultSet.getString("tec.TargetBuild");1925 String targetRevision = resultSet.getString("tec.TargetRev");1926 String implementer = resultSet.getString("tec.Implementer");1927 String runQA = resultSet.getString("tec.activeQA");1928 String runUAT = resultSet.getString("tec.activeUAT");1929 String runPROD = resultSet.getString("tec.activePROD");1930 String function = resultSet.getString("tec.function");1931 String usrCreated = resultSet.getString("tec.UsrCreated");1932 String dateCreated = resultSet.getString("tec.DateCreated");1933 String usrModif = resultSet.getString("tec.UsrModif");1934 Timestamp dateModif = resultSet.getTimestamp("tec.DateModif");1935 String userAgent = resultSet.getString("tec.useragent");1936 String screenSize = resultSet.getString("tec.screensize");1937 String system = null;1938 try {1939 system = resultSet.getString("app.system");1940 } catch (SQLException e) {1941 LOG.debug("Column system does not Exist.");1942 }1943 TestCase newTestCase = new TestCase();1944 newTestCase = factoryTestCase.create(test, testCase, origin, refOrigin, usrCreated, implementer,1945 usrModif, project, ticket, function, tcapplication, runQA, runUAT, runPROD, priority, group,1946 status, description, behavior, howTo, tcactive, conditionOper, conditionVal1, conditionVal2, fromSprint, fromRevision, toSprint,1947 toRevision, status, bugID, targetSprint, targetRevision, comment, dateCreated, userAgent, screenSize, dateModif, testCaseVersion);1948 newTestCase.setSystem(system);1949 return newTestCase;1950 }1951 private String createInClauseFromList(String[] list, String column, String preString, String postString) {1952 StringBuilder query = new StringBuilder();1953 if (list != null) {1954 query.append(preString);1955 query.append(column);1956 query.append(" IN (");1957 int i = 0;1958 while (i < list.length - 1) {1959 query.append("'");1960 query.append(list[i]);1961 query.append("',");1962 i++;1963 }1964 query.append("'");1965 query.append(list[i]);...

Full Screen

Full Screen

createInClauseFromList

Using AI Code Generation

copy

Full Screen

1List<String> list = new ArrayList<>();2list.add("TC1");3list.add("TC2");4list.add("TC3");5TestCaseDAO testCaseDAO = new TestCaseDAO();6String sql = testCaseDAO.createInClauseFromList("test", list);7System.out.println(sql);8List<String> list = new ArrayList<>();9list.add("TD1");10list.add("TD2");11list.add("TD3");12TestDataLibDAO testDataLibDAO = new TestDataLibDAO();13String sql = testDataLibDAO.createInClauseFromList("test", list);14System.out.println(sql);15List<String> list = new ArrayList<>();16list.add("TS1");17list.add("TS2");18list.add("TS3");19TestCaseStepDAO testCaseStepDAO = new TestCaseStepDAO();20String sql = testCaseStepDAO.createInClauseFromList("test", list);21System.out.println(sql);22List<String> list = new ArrayList<>();23list.add("TCEQ1");24list.add("TCEQ2");25list.add("TCEQ3");26TestCaseExecutionQueueDAO testCaseExecutionQueueDAO = new TestCaseExecutionQueueDAO();27String sql = testCaseExecutionQueueDAO.createInClauseFromList("test", list);28System.out.println(sql);29List<String> list = new ArrayList<>();30list.add("TCE1");31list.add("TCE2");32list.add("TCE3");33TestCaseExecutionDAO testCaseExecutionDAO = new TestCaseExecutionDAO();34String sql = testCaseExecutionDAO.createInClauseFromList("test", list);35System.out.println(sql);

Full Screen

Full Screen

createInClauseFromList

Using AI Code Generation

copy

Full Screen

1List<String> testCaseList = new ArrayList<String>();2testCaseList.add("TC0001");3testCaseList.add("TC0002");4testCaseList.add("TC0003");5testCaseList.add("TC0004");6testCaseList.add("TC0005");7testCaseList.add("TC0006");8testCaseList.add("TC0007");9testCaseList.add("TC0008");10testCaseList.add("TC0009");11testCaseList.add("TC0010");12testCaseList.add("TC0011");13testCaseList.add("TC0012");14testCaseList.add("TC0013");15testCaseList.add("TC0014");16testCaseList.add("TC0015");17testCaseList.add("TC0016");18testCaseList.add("TC0017");19testCaseList.add("TC0018");20testCaseList.add("TC0019");21testCaseList.add("TC0020");22testCaseList.add("TC0021");23testCaseList.add("TC0022");24testCaseList.add("TC0023");25testCaseList.add("TC0024");26testCaseList.add("TC0025");27testCaseList.add("TC0026");28testCaseList.add("TC0027");29testCaseList.add("TC0028");30testCaseList.add("TC0029");31testCaseList.add("TC0030");32testCaseList.add("TC0031");33testCaseList.add("TC0032");34testCaseList.add("TC0033");35testCaseList.add("TC0034");36testCaseList.add("TC0035");37testCaseList.add("TC0036");38testCaseList.add("TC0037");39testCaseList.add("TC0038");40testCaseList.add("TC0039");41testCaseList.add("TC0040");42testCaseList.add("TC0041");43testCaseList.add("TC0042");44testCaseList.add("TC0043");45testCaseList.add("TC0044");46testCaseList.add("TC0045");47testCaseList.add("TC0046");48testCaseList.add("TC0047");49testCaseList.add("TC0048");50testCaseList.add("TC0049");51testCaseList.add("TC0050");52testCaseList.add("TC0051");53testCaseList.add("TC0052");54testCaseList.add("TC0053");55testCaseList.add("TC0054");56testCaseList.add("TC0055");57testCaseList.add("TC0056");58testCaseList.add("TC0057");59testCaseList.add("TC0058");60testCaseList.add("TC005

Full Screen

Full Screen

createInClauseFromList

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.dao.impl.TestCaseDAO;2import org.cerberus.crud.entity.TestCase;3import org.cerberus.crud.factory.IFactoryTestCase;4import org.cerberus.crud.factory.impl.FactoryTestCase;5import org.cerberus.util.SqlUtil;6import org.cerberus.util.StringUtil;7import org.springframework.context.ApplicationContext;8import org.springframework.context.support.FileSystemXmlApplicationContext;9ApplicationContext appContext = new FileSystemXmlApplicationContext("src/main/webapp/WEB-INF/applicationContext.xml");10IFactoryTestCase factoryTestCase = appContext.getBean(FactoryTestCase.class);11TestCaseDAO testCaseDAO = appContext.getBean(TestCaseDAO.class);

Full Screen

Full Screen

createInClauseFromList

Using AI Code Generation

copy

Full Screen

1String[] countries = new String[]{"AU","US"};2String[] applications = new String[]{"MyApp","MyOtherApp"};3String[] environments = new String[]{"QA","DEV"};4String[] testCases = new String[]{"TC1","TC2","TC3"};5String[] inClauseCountries = testcaseDAO.createInClauseFromList(countries);6String[] inClauseApplications = testcaseDAO.createInClauseFromList(applications);7String[] inClauseEnvironments = testcaseDAO.createInClauseFromList(environments);8String[] inClauseTestCases = testcaseDAO.createInClauseFromList(testCases);9String query = "SELECT * FROM testcase tc WHERE tc.country IN " + inClauseCountries[0] + " AND tc.application IN " + inClauseApplications[0] + " AND tc.environment IN " + inClauseEnvironments[0] + " AND tc.test IN " + inClauseTestCases[0];10String[] countries = new String[]{"AU","US"};11String[] applications = new String[]{"MyApp","MyOtherApp"};12String[] environments = new String[]{"QA","DEV"};13String[] testCases = new String[]{"TC1","TC2","TC3"};14String[] inClauseCountries = testCaseExecutionService.createInClauseFromList(countries);15String[] inClauseApplications = testCaseExecutionService.createInClauseFromList(applications);16String[] inClauseEnvironments = testCaseExecutionService.createInClauseFromList(environments);17String[] inClauseTestCases = testCaseExecutionService.createInClauseFromList(testCases);18String query = "SELECT * FROM testcaseexecution tce WHERE tce.country IN " + inClauseCountries[0] + " AND tce.application IN " + inClauseApplications[0] + " AND tce.environment IN " + inClauseEnvironments[0] + " AND tce.test IN " + inClauseTestCases[0];

Full Screen

Full Screen

createInClauseFromList

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.dao.ITestCaseDAO;2import org.cerberus.crud.entity.TestCase;3import org.springframework.beans.factory.annotation.Autowired;4import java.util.HashMap;5import java.util.List;6import java.util.Map;7public class CreateInClauseFromList {8 ITestCaseDAO testCaseDAO;9 public List<TestCase> createInClauseFromList(List<String> list) {10 Map<String, List<String>> parameters = new HashMap<String, List<String>>();11 parameters.put("id", list);12 return testCaseDAO.findTestCaseByCriteria(parameters);13 }14}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful