How to use loadFromResultSet method of org.cerberus.crud.dao.impl.TestCaseExecutionQueueDepDAO class

Best Cerberus-source code snippet using org.cerberus.crud.dao.impl.TestCaseExecutionQueueDepDAO.loadFromResultSet

Source:TestCaseExecutionQueueDepDAO.java Github

copy

Full Screen

...68 preStat.setLong(1, id);69 ResultSet rs = preStat.executeQuery();70 try {71 while (rs.next()) {72 ao = loadFromResultSet(rs);73 }74 ans.setItem(ao);75 // Set the final message76 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME)77 .resolveDescription("OPERATION", "READ_BY_KEY");78 } catch (Exception e) {79 LOG.warn("Unable to execute query : " + e.toString());80 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",81 e.toString());82 } finally {83 if (rs != null) {84 rs.close();85 }86 }87 } catch (Exception e) {88 LOG.warn("Unable to read by key: " + e.getMessage());89 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",90 e.toString());91 } finally {92 ans.setResultMessage(msg);93 }94 return ans;95 }96 @Override97 public AnswerList<TestCaseExecutionQueueDep> readByExeId(long exeId) {98 AnswerList<TestCaseExecutionQueueDep> ans = new AnswerList<>();99 MessageEvent msg = null;100 try (Connection connection = databaseSpring.connect();101 PreparedStatement preStat = connection.prepareStatement("SELECT * FROM `testcaseexecutionqueuedep` WHERE `ExeID` = ?")) {102 // Prepare and execute query103 preStat.setLong(1, exeId);104 ResultSet rs = preStat.executeQuery();105 try {106 List<TestCaseExecutionQueueDep> al = new ArrayList<>();107 while (rs.next()) {108 al.add(loadFromResultSet(rs));109 }110 ans.setDataList(al);111 // Set the final message112 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME)113 .resolveDescription("OPERATION", "READ_BY_APP");114 } catch (Exception e) {115 LOG.warn("Unable to execute query : " + e.toString());116 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",117 e.toString());118 } finally {119 if (rs != null) {120 rs.close();121 }122 }123 } catch (Exception e) {124 LOG.warn("Unable to read by app: " + e.getMessage());125 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",126 e.toString());127 } finally {128 ans.setResultMessage(msg);129 }130 return ans;131 }132 @Override133 public AnswerItem<Integer> readNbWaitingByExeQueueId(long exeQueueId) {134 AnswerItem<Integer> ans = new AnswerItem<>();135 MessageEvent msg = null;136 final String query = "SELECT ID FROM testcaseexecutionqueuedep WHERE `ExeQueueID` = ? and Status = 'WAITING';";137 // Debug message on SQL.138 if (LOG.isDebugEnabled()) {139 LOG.debug("SQL : " + query);140 LOG.debug("SQL.param.exeQueueId : " + exeQueueId);141 }142 try (Connection connection = databaseSpring.connect();143 PreparedStatement preStat = connection.prepareStatement(query)) {144 // Prepare and execute query145 preStat.setLong(1, exeQueueId);146 ResultSet rs = preStat.executeQuery();147 try {148 List<Long> al = new ArrayList<>();149 int nbRow = 0;150 while (rs.next()) {151 nbRow++;152 }153 ans.setItem(nbRow);154 // Set the final message155 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "SELECT");156 } catch (Exception e) {157 LOG.error("Unable to execute query : " + e.toString());158 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());159 } finally {160 if (rs != null) {161 rs.close();162 }163 }164 } catch (Exception e) {165 LOG.error("Unable to read by exeId : " + e.getMessage());166 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());167 } finally {168 ans.setResultMessage(msg);169 }170 return ans;171 }172 @Override173 public AnswerItem<Integer> readNbReleasedWithNOKByExeQueueId(long exeQueueId) {174 AnswerItem<Integer> ans = new AnswerItem<>();175 MessageEvent msg = null;176 final String query = "SELECT tce.controlstatus FROM testcaseexecutionqueuedep tcd LEFT OUTER JOIN testcaseexecution tce ON tcd.exeid=tce.id WHERE tcd.`ExeQueueID` = ? and tcd.Status = 'RELEASED' and (tce.controlstatus is null or tce.controlstatus != 'OK');";177 // Debug message on SQL.178 if (LOG.isDebugEnabled()) {179 LOG.debug("SQL : " + query);180 LOG.debug("SQL.param.exeQueueId : " + exeQueueId);181 }182 try (Connection connection = databaseSpring.connect();183 PreparedStatement preStat = connection.prepareStatement(query)) {184 // Prepare and execute query185 preStat.setLong(1, exeQueueId);186 ResultSet rs = preStat.executeQuery();187 try {188 List<Long> al = new ArrayList<>();189 int nbRow = 0;190 while (rs.next()) {191 nbRow++;192 }193 ans.setItem(nbRow);194 // Set the final message195 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "SELECT");196 } catch (Exception e) {197 LOG.error("Unable to execute query : " + e.toString());198 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());199 } finally {200 if (rs != null) {201 rs.close();202 }203 }204 } catch (Exception e) {205 LOG.error("Unable to read by exeId : " + e.getMessage());206 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());207 } finally {208 ans.setResultMessage(msg);209 }210 return ans;211 }212 @Override213 public AnswerList<Long> readExeQueueIdByExeId(long exeId) {214 AnswerList<Long> ans = new AnswerList<>();215 MessageEvent msg = null;216 final String query = "SELECT DISTINCT ExeQueueID FROM testcaseexecutionqueuedep WHERE `ExeID` = ?";217 // Debug message on SQL.218 if (LOG.isDebugEnabled()) {219 LOG.debug("SQL : " + query);220 LOG.debug("SQL.param.exeId : " + exeId);221 }222 try (Connection connection = databaseSpring.connect();223 PreparedStatement preStat = connection.prepareStatement(query)) {224 // Prepare and execute query225 preStat.setLong(1, exeId);226 ResultSet rs = preStat.executeQuery();227 try {228 List<Long> al = new ArrayList<>();229 while (rs.next()) {230 al.add(rs.getLong("ExeQueueID"));231 }232 ans.setDataList(al);233 // Set the final message234 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "SELECT");235 } catch (Exception e) {236 LOG.error("Unable to execute query : " + e.toString());237 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());238 } finally {239 if (rs != null) {240 rs.close();241 }242 }243 } catch (Exception e) {244 LOG.error("Unable to read by exeId : " + e.getMessage());245 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());246 } finally {247 ans.setResultMessage(msg);248 }249 return ans;250 }251 @Override252 public AnswerList<Long> readExeQueueIdByQueueId(long queueId) {253 AnswerList<Long> ans = new AnswerList<>();254 MessageEvent msg = null;255 final String query = "SELECT DISTINCT ExeQueueID FROM testcaseexecutionqueuedep WHERE `QueueID` = ?";256 // Debug message on SQL.257 if (LOG.isDebugEnabled()) {258 LOG.debug("SQL : " + query);259 LOG.debug("SQL.param.queueId : " + queueId);260 }261 try (Connection connection = databaseSpring.connect();262 PreparedStatement preStat = connection.prepareStatement(query)) {263 // Prepare and execute query264 preStat.setLong(1, queueId);265 ResultSet rs = preStat.executeQuery();266 try {267 List<Long> al = new ArrayList<>();268 while (rs.next()) {269 al.add(rs.getLong("ExeQueueID"));270 }271 ans.setDataList(al);272 // Set the final message273 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "SELECT");274 } catch (Exception e) {275 LOG.error("Unable to execute query : " + e.toString());276 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());277 } finally {278 if (rs != null) {279 rs.close();280 }281 }282 } catch (Exception e) {283 LOG.error("Unable to read by exeId : " + e.getMessage());284 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());285 } finally {286 ans.setResultMessage(msg);287 }288 return ans;289 }290 @Override291 public AnswerList<TestCaseExecutionQueueDep> readByExeQueueId(long exeQueueId) {292 AnswerList<TestCaseExecutionQueueDep> ans = new AnswerList<>();293 MessageEvent msg = null;294 final String query = "SELECT * FROM testcaseexecutionqueuedep WHERE `ExeQueueID` = ?";295 // Debug message on SQL.296 if (LOG.isDebugEnabled()) {297 LOG.debug("SQL : " + query);298 LOG.debug("SQL.param.queueId : " + exeQueueId);299 }300 try (Connection connection = databaseSpring.connect();301 PreparedStatement preStat = connection.prepareStatement(query)) {302 // Prepare and execute query303 preStat.setLong(1, exeQueueId);304 ResultSet rs = preStat.executeQuery();305 try {306 List<TestCaseExecutionQueueDep> al = new ArrayList<>();307 while (rs.next()) {308 al.add(loadFromResultSet(rs));309 }310 ans.setDataList(al);311 // Set the final message312 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "SELECT");313 } catch (Exception e) {314 LOG.error("Unable to execute query : " + e.toString());315 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());316 } finally {317 if (rs != null) {318 rs.close();319 }320 }321 } catch (Exception e) {322 LOG.error("Unable to read by exeId : " + e.getMessage());323 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());324 } finally {325 ans.setResultMessage(msg);326 }327 return ans;328 }329 @Override330 public AnswerList<TestCaseExecutionQueueDep> readByCriteria(int start, int amount, String column, String dir, String searchTerm, Map<String, List<String>> individualSearch) {331 AnswerList<TestCaseExecutionQueueDep> response = new AnswerList<>();332 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);333 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));334 List<TestCaseExecutionQueueDep> objectList = new ArrayList<>();335 StringBuilder searchSQL = new StringBuilder();336 List<String> individalColumnSearchValues = new ArrayList<>();337 StringBuilder query = new StringBuilder();338 //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that339 //were applied -- used for pagination p340 query.append("SELECT SQL_CALC_FOUND_ROWS * FROM testcaseexecutionqueuedep ");341 searchSQL.append(" where 1=1 ");342 if (!StringUtil.isNullOrEmpty(searchTerm)) {343 searchSQL.append(" and (`Application` like ?");344 searchSQL.append(" or `Object` like ?");345 searchSQL.append(" or `Value` like ?");346 searchSQL.append(" or `ScreenshotFileName` like ?");347 searchSQL.append(" or `UsrCreated` like ?");348 searchSQL.append(" or `DateCreated` like ?");349 searchSQL.append(" or `UsrModif` like ?");350 searchSQL.append(" or `DateModif` like ?)");351 }352 if (individualSearch != null && !individualSearch.isEmpty()) {353 searchSQL.append(" and ( 1=1 ");354 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {355 searchSQL.append(" and ");356 searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));357 individalColumnSearchValues.addAll(entry.getValue());358 }359 searchSQL.append(" )");360 }361 query.append(searchSQL);362 if (!StringUtil.isNullOrEmpty(column)) {363 query.append(" order by `").append(column).append("` ").append(dir);364 }365 if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {366 query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);367 } else {368 query.append(" limit ").append(start).append(" , ").append(amount);369 }370 // Debug message on SQL.371 if (LOG.isDebugEnabled()) {372 LOG.debug("SQL : " + query.toString());373 }374 try (Connection connection = this.databaseSpring.connect();375 PreparedStatement preStat = connection.prepareStatement(query.toString());376 Statement stm = connection.createStatement();) {377 int i = 1;378 if (!StringUtil.isNullOrEmpty(searchTerm)) {379 preStat.setString(i++, "%" + searchTerm + "%");380 preStat.setString(i++, "%" + searchTerm + "%");381 preStat.setString(i++, "%" + searchTerm + "%");382 preStat.setString(i++, "%" + searchTerm + "%");383 preStat.setString(i++, "%" + searchTerm + "%");384 preStat.setString(i++, "%" + searchTerm + "%");385 preStat.setString(i++, "%" + searchTerm + "%");386 preStat.setString(i++, "%" + searchTerm + "%");387 }388 for (String individualColumnSearchValue : individalColumnSearchValues) {389 preStat.setString(i++, individualColumnSearchValue);390 }391 try (ResultSet resultSet = preStat.executeQuery();392 ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()");) {393 //gets the data394 while (resultSet.next()) {395 objectList.add(this.loadFromResultSet(resultSet));396 }397 //get the total number of rows398 int nrTotalRows = 0;399 if (rowSet != null && rowSet.next()) {400 nrTotalRows = rowSet.getInt(1);401 }402 if (objectList.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.403 LOG.error("Partial Result in the query.");404 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);405 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));406 response = new AnswerList<>(objectList, nrTotalRows);407 } else if (objectList.size() <= 0) {408 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);409 response = new AnswerList<>(objectList, nrTotalRows);410 } else {411 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);412 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));413 response = new AnswerList<>(objectList, nrTotalRows);414 }415 } catch (SQLException exception) {416 LOG.error("Unable to execute query : " + exception.toString());417 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);418 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));419 }420 } catch (SQLException exception) {421 LOG.error("Unable to execute query : " + exception.toString());422 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);423 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));424 }425 response.setResultMessage(msg);426 response.setDataList(objectList);427 return response;428 }429 @Override430 public AnswerItem<Integer> insertFromTestCaseDep(long queueId, String env, String country, String tag, String test, String testcase) {431 AnswerItem<Integer> ans = new AnswerItem<>();432 MessageEvent msg = null;433 final String query = "INSERT INTO testcaseexecutionqueuedep(ExeQueueID, Environment, Country, Tag, Type, DepTest, DepTestCase, DepEvent, Status) "434 + "SELECT ?, ?, ?, ?, Type, DepTest, DepTestCase, DepEvent, 'WAITING' FROM testcasedep "435 + "WHERE Test=? and TestCase=? and active='Y';";436 // Debug message on SQL.437 if (LOG.isDebugEnabled()) {438 LOG.debug("SQL : " + query);439 LOG.debug("SQL.param.test : " + test);440 LOG.debug("SQL.param.testcase : " + testcase);441 }442 try (Connection connection = databaseSpring.connect();443 PreparedStatement preStat = connection.prepareStatement(query)) {444 TestCaseExecutionQueueDep ao = null;445 // Prepare and execute query446 int i = 1;447 preStat.setLong(i++, queueId);448 preStat.setString(i++, env);449 preStat.setString(i++, country);450 preStat.setString(i++, tag);451 preStat.setString(i++, test);452 preStat.setString(i++, testcase);453 try {454 int rs = preStat.executeUpdate();455 ans.setItem(rs);456 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "READ_BY_KEY");457 // Set the final message458 } catch (Exception e) {459 LOG.error("Unable to execute query : " + e.toString());460 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());461 }462 } catch (Exception e) {463 LOG.error("Unable to insert from table: " + e.getMessage());464 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());465 } finally {466 ans.setResultMessage(msg);467 }468 return ans;469 }470 @Override471 public AnswerItem<Integer> insertFromExeQueueIdDep(long queueId, long fromExeQueueId) {472 AnswerItem<Integer> ans = new AnswerItem<>();473 MessageEvent msg = null;474 final String query = "INSERT INTO testcaseexecutionqueuedep(ExeQueueID, Environment, Country, Tag, Type, DepTest, DepTestCase, DepEvent, Status, ReleaseDate, Comment, ExeId, QueueId) "475 + "SELECT ?, Environment, Country, Tag, Type, DepTest, DepTestCase, DepEvent, Status, ReleaseDate, Comment, ExeId, QueueId FROM testcaseexecutionqueuedep "476 + "WHERE ExeQueueID=?;";477 // Debug message on SQL.478 if (LOG.isDebugEnabled()) {479 LOG.debug("SQL : " + query);480 LOG.debug("SQL.param.test : " + fromExeQueueId);481 }482 try (Connection connection = databaseSpring.connect();483 PreparedStatement preStat = connection.prepareStatement(query)) {484 TestCaseExecutionQueueDep ao = null;485 // Prepare and execute query486 int i = 1;487 preStat.setLong(i++, queueId);488 preStat.setLong(i++, fromExeQueueId);489 try {490 int rs = preStat.executeUpdate();491 ans.setItem(rs);492 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "READ_BY_KEY");493 // Set the final message494 } catch (Exception e) {495 LOG.error("Unable to execute query : " + e.toString());496 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());497 }498 } catch (Exception e) {499 LOG.error("Unable to insert from table: " + e.getMessage());500 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());501 } finally {502 ans.setResultMessage(msg);503 }504 return ans;505 }506 @Override507 public AnswerItem<Integer> updateStatusToRelease(String env, String Country, String tag, String type, String test, String testCase, String comment, long exeId, long queueId) {508 AnswerItem<Integer> ans = new AnswerItem<>();509 MessageEvent msg = null;510 String query = "UPDATE `testcaseexecutionqueuedep` SET `Status` = 'RELEASED', `Comment` = ? , `ExeId` = ?, `QueueId` = ?, ReleaseDate = NOW(), DateModif = NOW() "511 + " WHERE `Status` = 'WAITING' and `Type` = ? and `DepTest` = ? and `DepTestCase` = ? and `Tag` = ? and `Environment` = ? and `Country` = ? ";512 // Debug message on SQL.513 if (LOG.isDebugEnabled()) {514 LOG.debug("SQL : " + query);515 }516 try (Connection connection = databaseSpring.connect();517 PreparedStatement preStat = connection.prepareStatement(query)) {518 // Prepare and execute query519 int i = 1;520 preStat.setString(i++, comment);521 preStat.setLong(i++, exeId);522 preStat.setLong(i++, queueId);523 preStat.setString(i++, type);524 preStat.setString(i++, test);525 preStat.setString(i++, testCase);526 preStat.setString(i++, tag);527 preStat.setString(i++, env);528 preStat.setString(i++, Country);529 Integer resnb = preStat.executeUpdate();530 ans.setItem(resnb);531 // Set the final message532 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "UPDATE");533 } catch (Exception e) {534 LOG.error("Unable to update object: " + e.getMessage());535 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());536 } finally {537 ans.setResultMessage(msg);538 }539 return ans;540 }541 @Override542 public AnswerList<String> readDistinctValuesByCriteria(String searchTerm, Map<String, List<String>> individualSearch, String columnName) {543 AnswerList<String> answer = new AnswerList<>();544 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);545 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));546 List<String> distinctValues = new ArrayList<>();547 StringBuilder searchSQL = new StringBuilder();548 List<String> individalColumnSearchValues = new ArrayList<String>();549 StringBuilder query = new StringBuilder();550 query.append("SELECT distinct `");551 query.append(columnName);552 query.append("` as distinctValues FROM testcaseexecutionqueuedep ");553 searchSQL.append("WHERE 1=1 ");554 if (!StringUtil.isNullOrEmpty(searchTerm)) {555 searchSQL.append(" and (`Application` like ?");556 searchSQL.append(" or `Object` like ?");557 searchSQL.append(" or `Value` like ?");558 searchSQL.append(" or `ScreenshotFileName` like ?");559 searchSQL.append(" or `UsrCreated` like ?");560 searchSQL.append(" or `DateCreated` like ?");561 searchSQL.append(" or `UsrModif` like ?");562 searchSQL.append(" or `DateModif` like ?)");563 }564 if (individualSearch != null && !individualSearch.isEmpty()) {565 searchSQL.append(" and ( 1=1 ");566 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {567 searchSQL.append(" and ");568 searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));569 individalColumnSearchValues.addAll(entry.getValue());570 }571 searchSQL.append(" )");572 }573 query.append(searchSQL);574 query.append(" order by `").append(columnName).append("` asc");575 // Debug message on SQL.576 if (LOG.isDebugEnabled()) {577 LOG.debug("SQL : " + query.toString());578 }579 try (Connection connection = databaseSpring.connect();580 PreparedStatement preStat = connection.prepareStatement(query.toString());581 Statement stm = connection.createStatement();) {582 int i = 1;583 if (!StringUtil.isNullOrEmpty(searchTerm)) {584 preStat.setString(i++, "%" + searchTerm + "%");585 preStat.setString(i++, "%" + searchTerm + "%");586 preStat.setString(i++, "%" + searchTerm + "%");587 preStat.setString(i++, "%" + searchTerm + "%");588 preStat.setString(i++, "%" + searchTerm + "%");589 preStat.setString(i++, "%" + searchTerm + "%");590 preStat.setString(i++, "%" + searchTerm + "%");591 preStat.setString(i++, "%" + searchTerm + "%");592 }593 for (String individualColumnSearchValue : individalColumnSearchValues) {594 preStat.setString(i++, individualColumnSearchValue);595 }596 try (ResultSet resultSet = preStat.executeQuery();597 ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()");) {598 //gets the data599 while (resultSet.next()) {600 distinctValues.add(resultSet.getString("distinctValues") == null ? "" : resultSet.getString("distinctValues"));601 }602 //get the total number of rows603 int nrTotalRows = 0;604 if (rowSet != null && rowSet.next()) {605 nrTotalRows = rowSet.getInt(1);606 }607 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.608 LOG.error("Partial Result in the query.");609 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);610 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));611 answer = new AnswerList<>(distinctValues, nrTotalRows);612 } else if (distinctValues.size() <= 0) {613 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);614 answer = new AnswerList<>(distinctValues, nrTotalRows);615 } else {616 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);617 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));618 answer = new AnswerList<>(distinctValues, nrTotalRows);619 }620 } catch (SQLException exception) {621 LOG.error("Unable to execute query : " + exception.toString());622 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);623 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));624 }625 } catch (Exception e) {626 LOG.warn("Unable to execute query : " + e.toString());627 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",628 e.toString());629 } finally {630 // We always set the result message631 answer.setResultMessage(msg);632 }633 answer.setResultMessage(msg);634 answer.setDataList(distinctValues);635 return answer;636 }637 @Override638 public HashMap<TestCaseExecution, List<TestCaseExecutionQueueDep>> readDependenciesByTestCaseExecution(List<TestCaseExecution> testCaseExecutions) throws CerberusException {639 HashMap<TestCaseExecution, List<TestCaseExecutionQueueDep>> hashMap = new HashMap<>();640 if (CollectionUtils.isEmpty(testCaseExecutions)) {641 return hashMap;642 }643 StringBuilder query = new StringBuilder(644 "SELECT * FROM testcaseexecutionqueuedep "645 + "where exeQueueID in (");646 testCaseExecutions.forEach(tc -> query.append("?,"));647 query.setLength(query.length() - 1);648 query.append(")");649 List<TestCaseExecutionQueueDep> lst = RequestDbUtils.executeQueryList(databaseSpring, query.toString(),650 ps -> {651 int idx = 1;652 for (TestCaseExecution tc : testCaseExecutions) {653 ps.setLong(idx++, tc.getQueueID());654 }655 },656 rs -> loadFromResultSet(rs));657 Map<Long, TestCaseExecution> hashMapTC = testCaseExecutions.stream().collect(Collectors.toMap(tce -> tce.getQueueID(), tce -> tce));658 for (TestCaseExecutionQueueDep tce : lst) {659 hashMap660 .computeIfAbsent(661 hashMapTC.get(tce.getExeQueueId()),662 k -> new ArrayList<>())663 .add(tce);664 }665 return hashMap;666 }667 private TestCaseExecutionQueueDep loadFromResultSet(ResultSet rs) throws SQLException {668 Long id = ParameterParserUtil.parseLongParam(rs.getString("id"), -1);669 Long exeQueueID = ParameterParserUtil.parseLongParam(rs.getString("ExeQueueID"), -1);670 String environment = ParameterParserUtil.parseStringParam(rs.getString("Environment"), "");671 String country = ParameterParserUtil.parseStringParam(rs.getString("Country"), "");672 String tag = ParameterParserUtil.parseStringParam(rs.getString("Tag"), "");673 String type = ParameterParserUtil.parseStringParam(rs.getString("Type"), "");674 String depTest = ParameterParserUtil.parseStringParam(rs.getString("DepTest"), "");675 String depEvent = ParameterParserUtil.parseStringParam(rs.getString("DepEvent"), "");676 String depTestCase = ParameterParserUtil.parseStringParam(rs.getString("DepTestCase"), "");677 String status = ParameterParserUtil.parseStringParam(rs.getString("Status"), "");678 Timestamp releaseDate = rs.getTimestamp("ReleaseDate");679 String comment = ParameterParserUtil.parseStringParam(rs.getString("Comment"), "");680 Long exeID = ParameterParserUtil.parseLongParam(rs.getString("ExeID"), -1);681 Long queueID = ParameterParserUtil.parseLongParam(rs.getString("QueueID"), -1);...

Full Screen

Full Screen

loadFromResultSet

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestCaseExecutionQueueDep;2import org.cerberus.crud.dao.impl.TestCaseExecutionQueueDepDAO;3TestCaseExecutionQueueDepDAO testCaseExecutionQueueDepDAO = new TestCaseExecutionQueueDepDAO();4TestCaseExecutionQueueDep tceqd = new TestCaseExecutionQueueDep();5tceqd = testCaseExecutionQueueDepDAO.loadFromResultSet(rs);6import org.cerberus.crud.entity.TestCaseExecutionQueueDep;7import org.cerberus.crud.dao.impl.TestCaseExecutionQueueDepDAO;8TestCaseExecutionQueueDepDAO testCaseExecutionQueueDepDAO = new TestCaseExecutionQueueDepDAO();9TestCaseExecutionQueueDep tceqd = new TestCaseExecutionQueueDep();10tceqd = testCaseExecutionQueueDepDAO.loadFromResultSet(rs);11import org.cerberus.crud.entity.TestCaseExecutionQueueDep;12import org.cerberus.crud.dao.impl.TestCaseExecutionQueueDepDAO;13TestCaseExecutionQueueDepDAO testCaseExecutionQueueDepDAO = new TestCaseExecutionQueueDepDAO();14TestCaseExecutionQueueDep tceqd = new TestCaseExecutionQueueDep();15tceqd = testCaseExecutionQueueDepDAO.loadFromResultSet(rs);16import org.cerberus.crud.entity.TestCaseExecutionQueueDep;17import org.cerberus.crud.dao.impl.TestCaseExecutionQueueDepDAO;18TestCaseExecutionQueueDepDAO testCaseExecutionQueueDepDAO = new TestCaseExecutionQueueDepDAO();19TestCaseExecutionQueueDep tceqd = new TestCaseExecutionQueueDep();20tceqd = testCaseExecutionQueueDepDAO.loadFromResultSet(rs);21import org.cerberus.crud.entity.TestCaseExecutionQueueDep;22import org.cerberus.crud.dao.impl.TestCaseExecutionQueueDepDAO;23TestCaseExecutionQueueDepDAO testCaseExecutionQueueDepDAO = new TestCaseExecutionQueueDepDAO();24TestCaseExecutionQueueDep tceqd = new TestCaseExecutionQueueDep();25tceqd = testCaseExecutionQueueDepDAO.loadFromResultSet(rs);

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