Best Cerberus-source code snippet using org.cerberus.crud.dao.impl.ApplicationDAO.loadFromResultSet
Source:TestCaseExecutionDAO.java
...317 }318 ResultSet resultSet = preStat.executeQuery();319 try {320 if (resultSet.first()) {321 result = loadFromResultSet(resultSet);322 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);323 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));324 ans.setItem(result);325 } else {326 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);327 }328 } catch (SQLException exception) {329 LOG.error("Unable to execute query : " + exception.toString());330 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);331 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));332 } finally {333 resultSet.close();334 }335 } catch (SQLException exception) {336 LOG.error("Unable to execute query : " + exception.toString());337 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);338 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));339 } finally {340 preStat.close();341 }342 } catch (SQLException exception) {343 LOG.error("Unable to execute query : " + exception.toString());344 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);345 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));346 } finally {347 try {348 if (connection != null) {349 connection.close();350 }351 } catch (SQLException exception) {352 LOG.warn("Unable to close connection : " + exception.toString());353 }354 }355 //sets the message356 ans.setResultMessage(msg);357 return ans;358 }359 @Override360 public TestCaseExecution findLastTCExecutionByCriteria(String test, String testcase, String environment, String country,361 String build, String revision) throws CerberusException {362 TestCaseExecution result = null;363 final String query = new StringBuffer("SELECT exe.* FROM testcaseexecution exe ")364 .append("WHERE exe.test = ? AND exe.testcase = ? AND exe.environment = ? ")365 .append("AND exe.country = ? AND exe.build = ? AND exe.revision = ? ")366 .append("ORDER BY exe.id DESC").toString();367 try (Connection connection = this.databaseSpring.connect();368 PreparedStatement preStat = connection.prepareStatement(query);) {369 preStat.setString(1, test);370 preStat.setString(2, testcase);371 preStat.setString(3, environment);372 preStat.setString(4, country);373 preStat.setString(5, build);374 preStat.setString(6, revision);375 try (ResultSet resultSet = preStat.executeQuery();) {376 if (resultSet.first()) {377 result = this.loadFromResultSet(resultSet);378 } else {379 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));380 }381 } catch (SQLException exception) {382 LOG.error("Unable to execute query : " + exception.toString());383 }384 } catch (SQLException exception) {385 LOG.error("Unable to execute query : " + exception.toString());386 }387 return result;388 }389 @Override390 public TestCaseExecution findLastTCExecutionByCriteria(String test, String testCase, String environment, String country,391 String build, String revision, String browser, String browserVersion,392 String ip, String port, String tag) {393 TestCaseExecution result = null;394 final String query = new StringBuffer("SELECT exe.* FROM testcaseexecution exe ")395 .append("WHERE exe.test = ? AND exe.testcase = ? ")396 .append("AND exe.environment LIKE ? AND exe.country = ? AND exe.build LIKE ? ")397 .append("AND exe.revision LIKE ? AND exe.browser = ? AND exe.browserfullversion LIKE ? ")398 .append("AND exe.ip LIKE ? AND exe.port LIKE ? AND exe.tag LIKE ? ")399 .append("ORDER BY exe.id DESC").toString();400 try (Connection connection = this.databaseSpring.connect();401 PreparedStatement preStat = connection.prepareStatement(query);) {402 preStat.setString(1, test);403 preStat.setString(2, testCase);404 preStat.setString(3, ParameterParserUtil.wildcardIfEmpty(environment));405 preStat.setString(4, country);406 preStat.setString(5, ParameterParserUtil.wildcardIfEmpty(build));407 preStat.setString(6, ParameterParserUtil.wildcardIfEmpty(revision));408 preStat.setString(7, browser);409 preStat.setString(8, ParameterParserUtil.wildcardIfEmpty(browserVersion));410 preStat.setString(9, ParameterParserUtil.wildcardIfEmpty(ip));411 preStat.setString(10, ParameterParserUtil.wildcardIfEmpty(port));412 preStat.setString(11, ParameterParserUtil.wildcardIfEmpty(tag));413 try (ResultSet resultSet = preStat.executeQuery();) {414 if (resultSet.first()) {415 result = this.loadFromResultSet(resultSet);416 }417 } catch (SQLException exception) {418 LOG.error("Unable to execute query : " + exception.toString());419 }420 } catch (SQLException exception) {421 LOG.error("Unable to execute query : " + exception.toString());422 }423 return result;424 }425 @Override426 public List<TestCaseExecution> findExecutionbyCriteria1(String dateLimit, String test, String testCase, String application, String country, String environment, String controlStatus, String status) throws CerberusException {427 List<TestCaseExecution> myTestCaseExecutions = null;428 TestCaseExecution Execution;429 boolean throwException = false;430 final String query = new StringBuffer("SELECT exe.*, tec.*, app.* FROM testcaseexecution exe ")431 .append("LEFT JOIN testcase tec ON exe.test = tec.test AND exe.testcase = tec.testcase ")432 .append("LEFT JOIN application app ON exe.application = app.application ")433 .append("WHERE exe.start > ? AND exe.test LIKE ? AND exe.testcase LIKE ? AND exe.environment LIKE ? ")434 .append("AND exe.country LIKE ? AND exe.application LIKE ? AND exe.controlstatus LIKE ? ")435 .append("AND exe.status LIKE ?").toString();436 try (Connection connection = this.databaseSpring.connect();437 PreparedStatement preStat = connection.prepareStatement(query);) {438 preStat.setString(1, dateLimit);439 preStat.setString(2, test);440 preStat.setString(3, testCase);441 preStat.setString(4, environment);442 preStat.setString(5, country);443 preStat.setString(6, application);444 preStat.setString(7, controlStatus);445 preStat.setString(8, status);446 try (ResultSet resultSet = preStat.executeQuery();) {447 if (!(resultSet.first())) {448 throwException = true;449 } else {450 myTestCaseExecutions = new ArrayList<TestCaseExecution>();451 do {452 Execution = this.loadWithDependenciesFromResultSet(resultSet);453 myTestCaseExecutions.add(Execution);454 } while (resultSet.next());455 }456 } catch (SQLException exception) {457 LOG.error("Unable to execute query : " + exception.toString());458 }459 } catch (Exception exception) {460 LOG.error("Unable to execute query : " + exception.toString());461 }462 if (throwException) {463 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA));464 }465 return myTestCaseExecutions;466 }467 @Override468 public TestCaseExecution findTCExecutionByKey(long id) throws CerberusException {469 TestCaseExecution result = null;470 final String query = "SELECT * FROM testcaseexecution exe, application app WHERE exe.application = app.application AND ID = ?";471 // Debug message on SQL.472 if (LOG.isDebugEnabled()) {473 LOG.debug("SQL : " + query);474 }475 try (Connection connection = this.databaseSpring.connect();476 PreparedStatement preStat = connection.prepareStatement(query);) {477 preStat.setLong(1, id);478 try (ResultSet resultSet = preStat.executeQuery();) {479 if (resultSet.first()) {480 result = this.loadTestCaseExecutionAndApplicationFromResultSet(resultSet);481 }482 } catch (SQLException exception) {483 LOG.error("Unable to execute query : " + exception.toString());484 }485 } catch (SQLException exception) {486 LOG.error("Unable to execute query : " + exception.toString());487 }488 return result;489 }490 @Override491 public TestCaseExecution findLastTestCaseExecutionNotPE(String test, String testCase) throws CerberusException {492 TestCaseExecution result = null;493 StringBuilder query = new StringBuilder();494 query.append("SELECT exe.* FROM `testcaseexecution` exe ");495 query.append(" WHERE Test = ? and TestCase= ? and ID = ");496 query.append(" (SELECT MAX(ID) from `testcaseexecution` ");497 query.append("WHERE Test= ? and TestCase= ? and ControlStatus!='PE')");498 try (Connection connection = this.databaseSpring.connect();499 PreparedStatement preStat = connection.prepareStatement(query.toString());) {500 preStat.setString(1, test);501 preStat.setString(2, testCase);502 preStat.setString(3, test);503 preStat.setString(4, testCase);504 try (ResultSet resultSet = preStat.executeQuery();) {505 if (resultSet.first()) {506 result = loadFromResultSet(resultSet);507 }508 } catch (SQLException exception) {509 LOG.error("Unable to execute query : " + exception.toString());510 }511 } catch (SQLException exception) {512 LOG.error("Unable to execute query : " + exception.toString());513 }514 return result;515 }516 @Override517 public TestCaseExecution findLastTCExecutionInGroup(String test, String testCase, String environment, String country,518 String build, String revision, String browser, String browserVersion,519 String ip, String port, String tag) {520 TestCaseExecution result = null;521 StringBuilder query = new StringBuilder();522 query.append("SELECT exe.* FROM testcaseexecution exe ")523 .append("WHERE exe.test = ? AND exe.testcase = ? AND exe.country = ? AND exe.browser = ? ");524 if (!StringUtil.isNull(environment)) {525 query.append("AND exe.environment IN (");526 query.append(environment);527 query.append(") ");528 }529 if (!StringUtil.isNull(build)) {530 query.append("AND exe.build IN (");531 query.append(build);532 query.append(") ");533 }534 if (!StringUtil.isNull(revision)) {535 query.append("AND exe.revision IN (");536 query.append(revision);537 query.append(") ");538 }539 if (!StringUtil.isNull(browserVersion)) {540 query.append("AND exe.browserfullversion LIKE ? ");541 }542 if (!StringUtil.isNull(ip)) {543 query.append("AND exe.ip LIKE ? ");544 }545 if (!StringUtil.isNull(port)) {546 query.append("AND exe.port LIKE ? ");547 }548 if (!StringUtil.isNull(tag)) {549 query.append("AND exe.tag LIKE ? ");550 }551 query.append("ORDER BY exe.id DESC");552 try (Connection connection = this.databaseSpring.connect();553 PreparedStatement preStat = connection.prepareStatement(query.toString());) {554 preStat.setString(1, test);555 preStat.setString(2, testCase);556 preStat.setString(3, country);557 preStat.setString(4, browser);558 int i = 5;559 if (!StringUtil.isNull(browserVersion)) {560 preStat.setString(i, browserVersion);561 i++;562 }563 if (!StringUtil.isNull(ip)) {564 preStat.setString(i, ip);565 i++;566 }567 if (!StringUtil.isNull(port)) {568 preStat.setString(i, port);569 i++;570 }571 if (!StringUtil.isNull(tag)) {572 preStat.setString(i, tag);573 }574 try (ResultSet resultSet = preStat.executeQuery();) {575 if (resultSet.first()) {576 result = this.loadFromResultSet(resultSet);577 }578 } catch (SQLException exception) {579 LOG.error("Unable to execute query : " + exception.toString());580 }581 } catch (SQLException exception) {582 LOG.error("Unable to execute query : " + exception.toString());583 }584 return result;585 }586 @Override587 public List<String> findDistinctTag(boolean withUUIDTag) throws CerberusException {588 List<String> list = null;589 StringBuilder query = new StringBuilder();590 query.append("select distinct tag from testcaseexecution exe ")591 .append("where tag != '' ");592 if (!withUUIDTag) {593 query.append(" and length(tag) != length('c3888898-c65a-11e3-9b3e-0000004047e0')");594 }595 query.append(" UNION select distinct tag from testcaseexecutionqueue where tag !='' ");596 Connection connection = this.databaseSpring.connect();597 try {598 PreparedStatement preStat = connection.prepareStatement(query.toString());599 try {600 ResultSet resultSet = preStat.executeQuery();601 try {602 list = new ArrayList<String>();603 while (resultSet.next()) {604 list.add(resultSet.getString("tag"));605 }606 } catch (SQLException exception) {607 LOG.error("Unable to execute query : " + exception.toString());608 } finally {609 resultSet.close();610 }611 } catch (SQLException exception) {612 LOG.error("Unable to execute query : " + exception.toString());613 } finally {614 preStat.close();615 }616 } catch (SQLException exception) {617 LOG.error("Unable to execute query : " + exception.toString());618 } finally {619 try {620 if (connection != null) {621 connection.close();622 }623 } catch (SQLException e) {624 LOG.warn(e.toString());625 }626 }627 return list;628 }629 @Override630 public void setTagToExecution(long id, String tag) throws CerberusException {631 boolean throwEx = false;632 final String query = "UPDATE testcaseexecution exe SET exe.tag = ? WHERE exe.id = ?";633 Connection connection = this.databaseSpring.connect();634 try {635 PreparedStatement preStat = connection.prepareStatement(query);636 try {637 preStat.setString(1, tag);638 preStat.setLong(2, id);639 preStat.executeUpdate();640 } catch (SQLException exception) {641 LOG.error("Unable to execute query : " + exception.toString());642 throwEx = true;643 } finally {644 preStat.close();645 }646 } catch (SQLException exception) {647 LOG.error("Unable to execute query : " + exception.toString());648 } finally {649 try {650 if (connection != null) {651 connection.close();652 }653 } catch (SQLException e) {654 LOG.warn(e.toString());655 }656 }657 if (throwEx) {658 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));659 }660 }661 @Override662 public List<TestCaseExecution> readByTagByCriteria(String tag, int start, int amount, String sort, String searchTerm, Map<String, List<String>> individualSearch) throws CerberusException {663 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);664 List<String> individalColumnSearchValues = new ArrayList<>();665 final StringBuffer query = new StringBuffer();666 query.append("SELECT * FROM testcaseexecution exe ");667 query.append("left join testcase tec on exe.Test = tec.Test and exe.TestCase = tec.TestCase ");668 query.append("left join application app on tec.application = app.application ");669 query.append("where exe.ID IN ");670 query.append("(select MAX(exe.ID) from testcaseexecution exe ");671 query.append("where 1=1 ");672 if (!StringUtil.isNullOrEmpty(tag)) {673 query.append("and exe.tag = ? ");674 }675 query.append("group by exe.test, exe.testcase, exe.Environment, exe.Browser, exe.Country) ");676 if (!StringUtil.isNullOrEmpty(searchTerm)) {677 query.append("and (exe.`test` like ? ");678 query.append(" or exe.`testCase` like ? ");679 query.append(" or exe.`application` like ? ");680 query.append(" or tec.`bugid` like ? ");681 query.append(" or tec.`priority` like ? ");682 query.append(" or tec.`description` like ? )");683 }684 if (individualSearch != null && !individualSearch.isEmpty()) {685 query.append(" and ( 1=1 ");686 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {687 query.append(" and ");688 query.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));689 individalColumnSearchValues.addAll(entry.getValue());690 }691 query.append(" ) ");692 }693 if (!StringUtil.isNullOrEmpty(sort)) {694 query.append(" order by ").append(sort);695 }696 if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {697 query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);698 } else {699 query.append(" limit ").append(start).append(" , ").append(amount);700 }701 // Debug message on SQL.702 if (LOG.isDebugEnabled()) {703 LOG.debug("SQL : " + query.toString());704 LOG.debug("SQL.param.tag : " + tag);705 }706 return RequestDbUtils.executeQueryList(databaseSpring, query.toString(),707 preStat -> {708 int i = 1;709 if (!StringUtil.isNullOrEmpty(tag)) {710 preStat.setString(i++, tag);711 }712 if (!Strings.isNullOrEmpty(searchTerm)) {713 preStat.setString(i++, "%" + searchTerm + "%");714 preStat.setString(i++, "%" + searchTerm + "%");715 preStat.setString(i++, "%" + searchTerm + "%");716 preStat.setString(i++, "%" + searchTerm + "%");717 preStat.setString(i++, "%" + searchTerm + "%");718 preStat.setString(i++, "%" + searchTerm + "%");719 }720 for (String individualColumnSearchValue : individalColumnSearchValues) {721 preStat.setString(i++, individualColumnSearchValue);722 }723 },724 rs -> loadWithDependenciesFromResultSet(rs)725 );726 }727 @Override728 public AnswerList<TestCaseExecution> readByTag(String tag) throws CerberusException {729 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);730 AnswerList<TestCaseExecution> answer = new AnswerList<>();731 final StringBuffer query = new StringBuffer();732 query.append("SELECT * FROM testcaseexecution exe ");733 query.append("left join testcase tec on exe.Test = tec.Test and exe.TestCase = tec.TestCase ");734 query.append("left join application as app on tec.application = app.application ");735 query.append("where 1=1 and exe.tag = ? ");736 // Debug message on SQL.737 if (LOG.isDebugEnabled()) {738 LOG.debug("SQL : " + query.toString());739 LOG.debug("SQL.param.tag : " + tag);740 }741 List<TestCaseExecution> testCaseExecutionList = new ArrayList<>();742 Connection connection = this.databaseSpring.connect();743 try {744 PreparedStatement preStat = connection.prepareStatement(query.toString());745 preStat.setString(1, tag);746 try {747 ResultSet resultSet = preStat.executeQuery();748 try {749 while (resultSet.next()) {750 testCaseExecutionList.add(this.loadWithDependenciesFromResultSet(resultSet));751 }752 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));753 answer.setTotalRows(testCaseExecutionList.size());754 } catch (SQLException exception) {755 LOG.warn("Unable to execute query : " + exception.toString());756 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);757 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));758 testCaseExecutionList = null;759 } finally {760 resultSet.close();761 }762 } catch (SQLException exception) {763 LOG.warn("Unable to execute query : " + exception.toString());764 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);765 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));766 testCaseExecutionList = null;767 } finally {768 preStat.close();769 }770 } catch (SQLException exception) {771 LOG.warn("Unable to execute query : " + exception.toString());772 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);773 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));774 testCaseExecutionList = null;775 } finally {776 try {777 if (connection != null) {778 connection.close();779 }780 } catch (SQLException e) {781 LOG.warn(e.toString());782 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);783 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));784 }785 }786 answer.setResultMessage(msg);787 answer.setDataList(testCaseExecutionList);788 return answer;789 }790 @Override791 public Integer readNbByTag(String tag) throws CerberusException {792 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);793 Integer result = 0;794 final StringBuffer query = new StringBuffer();795 query.append("SELECT count(*) FROM testcaseexecution exe ");796 query.append("where 1=1 and exe.tag = ? ");797 // Debug message on SQL.798 if (LOG.isDebugEnabled()) {799 LOG.debug("SQL : " + query.toString());800 LOG.debug("SQL.param.tag : " + tag);801 }802 Connection connection = this.databaseSpring.connect();803 try {804 PreparedStatement preStat = connection.prepareStatement(query.toString());805 preStat.setString(1, tag);806 try {807 ResultSet resultSet = preStat.executeQuery();808 try {809 while (resultSet.next()) {810 result = resultSet.getInt(1);811 }812 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));813 } catch (SQLException exception) {814 LOG.warn("Unable to execute query : " + exception.toString());815 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);816 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));817 } finally {818 resultSet.close();819 }820 } catch (SQLException exception) {821 LOG.warn("Unable to execute query : " + exception.toString());822 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);823 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));824 } finally {825 preStat.close();826 }827 } catch (SQLException exception) {828 LOG.warn("Unable to execute query : " + exception.toString());829 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);830 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));831 } finally {832 try {833 if (connection != null) {834 connection.close();835 }836 } catch (SQLException e) {837 LOG.warn(e.toString());838 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);839 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));840 }841 }842 return result;843 }844 @Override845 public AnswerList<TestCaseExecution> readByCriteria(int start, int amount, String sort, String searchTerm, Map<String, List<String>> individualSearch, List<String> individualLike, List<String> system) throws CerberusException {846 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);847 AnswerList<TestCaseExecution> response = new AnswerList<>();848 List<String> individalColumnSearchValues = new ArrayList<>();849 List<TestCaseExecution> objectList = new ArrayList<>();850 final StringBuffer query = new StringBuffer();851 query.append("SELECT SQL_CALC_FOUND_ROWS * FROM testcaseexecution exe ");852 query.append("where 1=1 ");853 if (!StringUtil.isNullOrEmpty(searchTerm)) {854 query.append("and (exe.`id` like ? ");855 query.append(" or exe.`test` like ? ");856 query.append(" or exe.`testCase` like ? ");857 query.append(" or exe.`build` like ? ");858 query.append(" or exe.`revision` like ? ");859 query.append(" or exe.`environment` like ? ");860 query.append(" or exe.`country` like ? ");861 query.append(" or exe.`browser` like ? ");862 query.append(" or exe.`version` like ? ");863 query.append(" or exe.`platform` like ? ");864 query.append(" or exe.`browserfullversion` like ? ");865 query.append(" or exe.`start` like ? ");866 query.append(" or exe.`end` like ? ");867 query.append(" or exe.`controlstatus` like ? ");868 query.append(" or exe.`controlmessage` like ? ");869 query.append(" or exe.`application` like ? ");870 query.append(" or exe.`url` like ? ");871 query.append(" or exe.`robot` like ? ");872 query.append(" or exe.`robotexecutor` like ? ");873 query.append(" or exe.`robothost` like ? ");874 query.append(" or exe.`robotport` like ? ");875 query.append(" or exe.`tag` like ? ");876 query.append(" or exe.`end` like ? ");877 query.append(" or exe.`status` like ? ");878 query.append(" or exe.`crbversion` like ? ");879 query.append(" or exe.`executor` like ? ");880 query.append(" or exe.`screensize` like ? ");881 query.append(" or exe.`userAgent` like ? )");882 }883 if (individualSearch != null && !individualSearch.isEmpty()) {884 query.append(" and ( 1=1 ");885 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {886 query.append(" and ");887 query.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));888 individalColumnSearchValues.addAll(entry.getValue());889 }890 query.append(" ) ");891 }892 if (system != null && !system.isEmpty()) {893 query.append(" and " + SqlUtil.generateInClause("exe.system", system) + " ");894 }895 query.append(" AND " + UserSecurity.getSystemAllowForSQL("exe.system"));896 if (!StringUtil.isNullOrEmpty(sort)) {897 query.append(" order by ").append(sort);898 }899 if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {900 query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);901 } else {902 query.append(" limit ").append(start).append(" , ").append(amount);903 }904 // Debug message on SQL.905 if (LOG.isDebugEnabled()) {906 LOG.debug("SQL : " + query.toString());907 }908 Connection connection = this.databaseSpring.connect();909 try {910 PreparedStatement preStat = connection.prepareStatement(query.toString());911 try {912 int i = 1;913 if (!Strings.isNullOrEmpty(searchTerm)) {914 preStat.setString(i++, "%" + searchTerm + "%");915 preStat.setString(i++, "%" + searchTerm + "%");916 preStat.setString(i++, "%" + searchTerm + "%");917 preStat.setString(i++, "%" + searchTerm + "%");918 preStat.setString(i++, "%" + searchTerm + "%");919 preStat.setString(i++, "%" + searchTerm + "%");920 preStat.setString(i++, "%" + searchTerm + "%");921 preStat.setString(i++, "%" + searchTerm + "%");922 preStat.setString(i++, "%" + searchTerm + "%");923 preStat.setString(i++, "%" + searchTerm + "%");924 preStat.setString(i++, "%" + searchTerm + "%");925 preStat.setString(i++, "%" + searchTerm + "%");926 preStat.setString(i++, "%" + searchTerm + "%");927 preStat.setString(i++, "%" + searchTerm + "%");928 preStat.setString(i++, "%" + searchTerm + "%");929 preStat.setString(i++, "%" + searchTerm + "%");930 preStat.setString(i++, "%" + searchTerm + "%");931 preStat.setString(i++, "%" + searchTerm + "%");932 preStat.setString(i++, "%" + searchTerm + "%");933 preStat.setString(i++, "%" + searchTerm + "%");934 preStat.setString(i++, "%" + searchTerm + "%");935 preStat.setString(i++, "%" + searchTerm + "%");936 preStat.setString(i++, "%" + searchTerm + "%");937 preStat.setString(i++, "%" + searchTerm + "%");938 preStat.setString(i++, "%" + searchTerm + "%");939 preStat.setString(i++, "%" + searchTerm + "%");940 preStat.setString(i++, "%" + searchTerm + "%");941 preStat.setString(i++, "%" + searchTerm + "%");942 }943 for (String individualColumnSearchValue : individalColumnSearchValues) {944 preStat.setString(i++, individualColumnSearchValue);945 }946 if (system != null && !system.isEmpty()) {947 for (String sys : system) {948 preStat.setString(i++, sys);949 }950 }951 ResultSet resultSet = preStat.executeQuery();952 try {953 //gets the data954 while (resultSet.next()) {955 objectList.add(this.loadFromResultSet(resultSet));956 }957 //get the total number of rows958 resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");959 int nrTotalRows = 0;960 if (resultSet != null && resultSet.next()) {961 nrTotalRows = resultSet.getInt(1);962 }963 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.964 LOG.error("Partial Result in the query.");965 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);966 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));967 response = new AnswerList<>(objectList, nrTotalRows);968 } else if (objectList.size() <= 0) {969 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);970 response = new AnswerList<>(objectList, nrTotalRows);971 } else {972 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);973 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));974 response = new AnswerList<>(objectList, nrTotalRows);975 }976 } catch (SQLException exception) {977 LOG.error("Unable to execute query : " + exception.toString(), exception);978 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);979 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));980 } finally {981 if (resultSet != null) {982 resultSet.close();983 }984 }985 } catch (SQLException exception) {986 LOG.error("Unable to execute query : " + exception.toString(), exception);987 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);988 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));989 } finally {990 if (preStat != null) {991 preStat.close();992 }993 }994 } catch (SQLException exception) {995 LOG.error("Unable to execute query : " + exception.toString(), exception);996 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);997 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));998 } finally {999 try {1000 if (!this.databaseSpring.isOnTransaction()) {1001 if (connection != null) {1002 connection.close();1003 }1004 }1005 } catch (SQLException exception) {1006 LOG.warn("Unable to close connection : " + exception.toString());1007 }1008 }1009 response.setResultMessage(msg);1010 response.setDataList(objectList);1011 return response;1012 }1013 @Override1014 public AnswerList<TestCaseExecution> readDistinctEnvCoutnryBrowserByTag(String tag) {1015 AnswerList<TestCaseExecution> answer = new AnswerList<>();1016 StringBuilder query = new StringBuilder();1017 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1018 query.append("SELECT exe.* FROM testcaseexecution exe WHERE exe.tag = ? GROUP BY exe.Environment, exe.Country, exe.Browser, exe.ControlStatus");1019 Connection connection = this.databaseSpring.connect();1020 List<TestCaseExecution> testCaseExecutionList = new ArrayList<TestCaseExecution>();1021 try {1022 PreparedStatement preStat = connection.prepareStatement(query.toString());1023 preStat.setString(1, tag);1024 try {1025 ResultSet resultSet = preStat.executeQuery();1026 try {1027 while (resultSet.next()) {1028 testCaseExecutionList.add(this.loadFromResultSet(resultSet));1029 }1030 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));1031 answer = new AnswerList<>(testCaseExecutionList, testCaseExecutionList.size());1032 } catch (SQLException exception) {1033 LOG.warn("Unable to execute query : " + exception.toString());1034 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1035 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1036 testCaseExecutionList = null;1037 } finally {1038 if (resultSet != null) {1039 resultSet.close();1040 }1041 }1042 } catch (SQLException ex) {1043 LOG.warn("Unable to execute query : " + ex.toString());1044 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1045 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1046 testCaseExecutionList = null;1047 } finally {1048 if (preStat != null) {1049 preStat.close();1050 }1051 }1052 } catch (SQLException ex) {1053 LOG.warn(ex.toString());1054 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1055 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1056 } finally {1057 try {1058 if (connection != null) {1059 connection.close();1060 }1061 } catch (SQLException ex) {1062 LOG.warn("Unable to execute query : " + ex.toString());1063 }1064 }1065 answer.setResultMessage(msg);1066 return answer;1067 }1068 @Override1069 public AnswerList<TestCaseExecution> readDistinctColumnByTag(String tag, boolean env, boolean country, boolean browser, boolean app) {1070 AnswerList<TestCaseExecution> answer = new AnswerList<>();1071 StringBuilder query = new StringBuilder();1072 StringBuilder distinct = new StringBuilder();1073 int prev = 0;1074 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1075 if (!(!env && !country && !app && !browser)) {1076 if (env) {1077 distinct.append("Environment");1078 prev++;1079 }1080 if (country) {1081 if (prev != 0) {1082 prev = 0;1083 distinct.append(",");1084 }1085 distinct.append("Country");1086 prev++;1087 }1088 if (browser) {1089 if (prev != 0) {1090 prev = 0;1091 distinct.append(",");1092 }1093 distinct.append("Browser");1094 prev++;1095 }1096 if (app) {1097 if (prev != 0) {1098 prev = 0;1099 distinct.append(",");1100 }1101 distinct.append("Application");1102 }1103 query.append("SELECT ");1104 query.append(distinct.toString());1105 query.append(" FROM testcaseexecution exe WHERE exe.tag = ? GROUP BY ");1106 query.append(distinct.toString());1107 } else {1108 //If there is no distinct, select nothing1109 query.append("SELECT * FROM testcaseexecution exe WHERE 1 = 0 AND exe.tag = ?");1110 }1111 Connection connection = this.databaseSpring.connect();1112 List<TestCaseExecution> column = new ArrayList<TestCaseExecution>();1113 try {1114 PreparedStatement preStat = connection.prepareStatement(query.toString());1115 preStat.setString(1, tag);1116 try {1117 ResultSet resultSet = preStat.executeQuery();1118 try {1119 while (resultSet.next()) {1120 TestCaseExecution tmp = new TestCaseExecution();1121 if (env) {1122 tmp.setEnvironment(resultSet.getString("Environment"));1123 } else {1124 tmp.setEnvironment("");1125 }1126 if (country) {1127 tmp.setCountry(resultSet.getString("Country"));1128 } else {1129 tmp.setCountry("");1130 }1131 if (browser) {1132 tmp.setBrowser(resultSet.getString("Browser"));1133 } else {1134 tmp.setBrowser("");1135 }1136 if (app) {1137 tmp.setApplication(resultSet.getString("Application"));1138 } else {1139 tmp.setApplication("");1140 }1141 column.add(tmp);1142 }1143 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));1144 answer = new AnswerList<>(column, column.size());1145 } catch (SQLException exception) {1146 LOG.warn("Unable to execute query : " + exception.toString());1147 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1148 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1149 column = null;1150 } finally {1151 if (resultSet != null) {1152 resultSet.close();1153 }1154 }1155 } catch (SQLException ex) {1156 LOG.warn("Unable to execute query : " + ex.toString());1157 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1158 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1159 column = null;1160 } finally {1161 if (preStat != null) {1162 preStat.close();1163 }1164 }1165 } catch (SQLException ex) {1166 LOG.warn(ex.toString());1167 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1168 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));1169 } finally {1170 try {1171 if (connection != null) {1172 connection.close();1173 }1174 } catch (SQLException ex) {1175 LOG.warn("Unable to execute query : " + ex.toString());1176 }1177 }1178 answer.setResultMessage(msg);1179 return answer;1180 }1181 @Override1182 public AnswerItem<TestCaseExecution> readByKey(long executionId) {1183 AnswerItem<TestCaseExecution> ans = new AnswerItem<>();1184 TestCaseExecution result = null;1185 final String query = "SELECT * FROM `testcaseexecution` exe WHERE exe.`id` = ?";1186 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1187 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));1188 Connection connection = this.databaseSpring.connect();1189 try {1190 PreparedStatement preStat = connection.prepareStatement(query);1191 try {1192 preStat.setLong(1, executionId);1193 ResultSet resultSet = preStat.executeQuery();1194 try {1195 if (resultSet.first()) {1196 result = loadFromResultSet(resultSet);1197 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1198 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));1199 ans.setItem(result);1200 } else {1201 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);1202 }1203 } catch (SQLException exception) {1204 LOG.error("Unable to execute query : " + exception.toString());1205 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1206 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1207 } finally {1208 resultSet.close();1209 }1210 } catch (SQLException exception) {1211 LOG.error("Unable to execute query : " + exception.toString());1212 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1213 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1214 } finally {1215 preStat.close();1216 }1217 } catch (SQLException exception) {1218 LOG.error("Unable to execute query : " + exception.toString());1219 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1220 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1221 } finally {1222 try {1223 if (connection != null) {1224 connection.close();1225 }1226 } catch (SQLException exception) {1227 LOG.warn("Unable to close connection : " + exception.toString());1228 }1229 }1230 //sets the message1231 ans.setResultMessage(msg);1232 return ans;1233 }1234 @Override1235 public TestCaseExecution loadFromResultSet(ResultSet resultSet) throws SQLException {1236 long id = ParameterParserUtil.parseLongParam(resultSet.getString("exe.ID"), 0);1237 String test = ParameterParserUtil.parseStringParam(resultSet.getString("exe.test"), "");1238 String testcase = ParameterParserUtil.parseStringParam(resultSet.getString("exe.testcase"), "");1239 String description = ParameterParserUtil.parseStringParam(resultSet.getString("exe.description"), "");1240 String build = ParameterParserUtil.parseStringParam(resultSet.getString("exe.build"), "");1241 String revision = ParameterParserUtil.parseStringParam(resultSet.getString("exe.revision"), "");1242 String environment = ParameterParserUtil.parseStringParam(resultSet.getString("exe.environment"), "");1243 String environmentData = ParameterParserUtil.parseStringParam(resultSet.getString("exe.environmentData"), "");1244 String country = ParameterParserUtil.parseStringParam(resultSet.getString("exe.country"), "");1245 String robot = ParameterParserUtil.parseStringParam(resultSet.getString("exe.robot"), ""); // Host the Selenium IP1246 String robotExecutor = ParameterParserUtil.parseStringParam(resultSet.getString("exe.robotExecutor"), ""); // Host the Selenium IP1247 String robotHost = ParameterParserUtil.parseStringParam(resultSet.getString("exe.robotHost"), ""); // Host the Selenium IP1248 String robotPort = ParameterParserUtil.parseStringParam(resultSet.getString("exe.robotPort"), ""); // host the Selenium Port1249 String robotDecli = ParameterParserUtil.parseStringParam(resultSet.getString("exe.robotdecli"), "");1250 String browser = ParameterParserUtil.parseStringParam(resultSet.getString("exe.browser"), "");1251 String version = ParameterParserUtil.parseStringParam(resultSet.getString("exe.version"), "");1252 String platform = ParameterParserUtil.parseStringParam(resultSet.getString("exe.platform"), "");1253 long start = ParameterParserUtil.parseLongParam(String.valueOf(resultSet.getTimestamp("exe.start").getTime()), 0);1254 long end = ParameterParserUtil.parseLongParam(String.valueOf(resultSet.getTimestamp("exe.end").getTime()), 0);1255 String controlStatus = ParameterParserUtil.parseStringParam(resultSet.getString("exe.controlStatus"), "");1256 String controlMessage = ParameterParserUtil.parseStringParam(resultSet.getString("exe.controlMessage"), "");1257 String application = ParameterParserUtil.parseStringParam(resultSet.getString("exe.application"), "");1258 String url = ParameterParserUtil.parseStringParam(resultSet.getString("exe.url"), "");1259 String tag = ParameterParserUtil.parseStringParam(resultSet.getString("exe.tag"), "");1260 String status = ParameterParserUtil.parseStringParam(resultSet.getString("exe.status"), "");1261 String crbVersion = ParameterParserUtil.parseStringParam(resultSet.getString("exe.crbVersion"), "");1262 String executor = ParameterParserUtil.parseStringParam(resultSet.getString("exe.executor"), "");1263 String screenSize = ParameterParserUtil.parseStringParam(resultSet.getString("exe.screensize"), "");1264 String conditionOper = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionOper"), "");1265 String conditionVal1 = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal1"), "");1266 String conditionVal1Init = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal1Init"), "");1267 String conditionVal2 = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal2"), "");1268 String conditionVal2Init = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal2Init"), "");1269 String conditionVal3 = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal3"), "");1270 String conditionVal3Init = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal3Init"), "");1271 String manualExecution = ParameterParserUtil.parseStringParam(resultSet.getString("exe.manualExecution"), "N");1272 String userAgent = ParameterParserUtil.parseStringParam(resultSet.getString("exe.userAgent"), "");1273 String system = ParameterParserUtil.parseStringParam(resultSet.getString("exe.system"), "");1274 long queueId = ParameterParserUtil.parseLongParam(resultSet.getString("exe.queueId"), 0);1275 int testCaseVersion = ParameterParserUtil.parseIntegerParam(resultSet.getInt("exe.testCaseVersion"), 0);1276 int testCasePriority = ParameterParserUtil.parseIntegerParam(resultSet.getInt("exe.testCasePriority"), 0);1277 String robotProvider = ParameterParserUtil.parseStringParam(resultSet.getString("exe.robotProvider"), "");1278 String robotSessionId = ParameterParserUtil.parseStringParam(resultSet.getString("exe.robotSessionId"), "");1279 String usrModif = ParameterParserUtil.parseStringParam(resultSet.getString("exe.UsrModif"), "");1280 String usrCreated = ParameterParserUtil.parseStringParam(resultSet.getString("exe.UsrCreated"), "");1281 Timestamp dateCreated = resultSet.getTimestamp("exe.DateCreated");1282 Timestamp dateModif = resultSet.getTimestamp("exe.DateModif");1283 TestCaseExecution result = factoryTCExecution.create(id, test, testcase, description, build, revision, environment,1284 country, robot, robotExecutor, robotHost, robotPort, robotDecli, browser, version, platform, start, end, controlStatus, controlMessage, application, null, url,1285 tag, 0, 0, 0, 0, true, "", "", status, crbVersion, null, null, null,1286 false, null, null, null, environmentData, null, null, null, null, executor, 0, screenSize, null, robotProvider, robotSessionId,1287 conditionOper, conditionVal1Init, conditionVal2Init, conditionVal3Init, conditionVal1, conditionVal2, conditionVal3, manualExecution, userAgent, testCaseVersion, testCasePriority, system,1288 usrCreated, dateCreated, usrModif, dateModif);1289 result.setQueueID(queueId);1290 return result;1291 }1292 private TestCaseExecution loadWithDependenciesFromResultSet(ResultSet resultSet) throws SQLException {1293 TestCaseExecution testCaseExecution = new TestCaseExecution();1294 testCaseExecution = this.loadFromResultSet(resultSet);1295 testCaseExecution.setTestCaseObj(testCaseDAO.loadFromResultSet(resultSet));1296 testCaseExecution.setApplicationObj(applicationDAO.loadFromResultSet(resultSet));1297 return testCaseExecution;1298 }1299 private TestCaseExecution loadWithTestCaseFromResultSet(ResultSet resultSet) throws SQLException {1300 TestCaseExecution testCaseExecution = new TestCaseExecution();1301 testCaseExecution = this.loadFromResultSet(resultSet);1302 testCaseExecution.setTestCaseObj(testCaseDAO.loadFromResultSet(resultSet));1303 return testCaseExecution;1304 }1305 private TestCaseExecution loadTestCaseExecutionAndApplicationFromResultSet(ResultSet resultSet) throws SQLException {1306 TestCaseExecution testCaseExecution = new TestCaseExecution();1307 testCaseExecution = this.loadFromResultSet(resultSet);1308 testCaseExecution.setApplicationObj(applicationDAO.loadFromResultSet(resultSet));1309 return testCaseExecution;1310 }1311 @Override1312 public AnswerList<String> readDistinctValuesByCriteria(List<String> system, String test, String searchParameter, Map<String, List<String>> individualSearch, String columnName) {1313 AnswerList<String> answer = new AnswerList<>();1314 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1315 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));1316 List<String> distinctValues = new ArrayList<>();1317 List<String> individalColumnSearchValues = new ArrayList<>();1318 final StringBuffer query = new StringBuffer();1319 query.append("SELECT distinct ");1320 query.append(columnName);1321 query.append(" as distinctValues FROM testcaseexecution exe ");1322 query.append("where 1=1 ");...
Source:ApplicationDAO.java
...81 preStat.setString(1, application);82 ResultSet resultSet = preStat.executeQuery();83 try {84 if (resultSet.first()) {85 result = loadFromResultSet(resultSet);86 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);87 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));88 ans.setItem(result);89 } else {90 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);91 }92 } catch (SQLException exception) {93 LOG.error("Unable to execute query : " + exception.toString());94 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);95 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));96 } finally {97 resultSet.close();98 }99 } catch (SQLException exception) {100 LOG.error("Unable to execute query : " + exception.toString());101 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);102 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));103 } finally {104 preStat.close();105 }106 } catch (SQLException exception) {107 LOG.error("Unable to execute query : " + exception.toString());108 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);109 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));110 } finally {111 try {112 if (connection != null) {113 connection.close();114 }115 } catch (SQLException exception) {116 LOG.warn("Unable to close connection : " + exception.toString());117 }118 }119 //sets the message120 ans.setResultMessage(msg);121 return ans;122 }123 @Override124 public AnswerList<Application> readBySystemByCriteria(String system, int start, int amount, String column, String dir, String searchTerm, Map<String, List<String>> individualSearch) {125 AnswerList response = new AnswerList();126 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);127 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));128 List<Application> objectList = new ArrayList<Application>();129 StringBuilder searchSQL = new StringBuilder();130 List<String> individalColumnSearchValues = new ArrayList<String>();131 StringBuilder query = new StringBuilder();132 //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that 133 //were applied -- used for pagination p134 query.append("SELECT SQL_CALC_FOUND_ROWS * FROM application app ");135 searchSQL.append(" where 1=1 ");136 if (!StringUtil.isNullOrEmpty(searchTerm)) {137 searchSQL.append(" and (app.`application` like ?");138 searchSQL.append(" or app.`description` like ?");139 searchSQL.append(" or app.`sort` like ?");140 searchSQL.append(" or app.`type` like ?");141 searchSQL.append(" or app.`System` like ?");142 searchSQL.append(" or app.`Subsystem` like ?");143 searchSQL.append(" or app.`svnURL` like ?");144 searchSQL.append(" or app.`bugtrackerurl` like ?");145 searchSQL.append(" or app.`bugtrackernewurl` like ?");146 searchSQL.append(" or app.`deploytype` like ?");147 searchSQL.append(" or app.`mavengroupid` like ?)");148 }149 if (individualSearch != null && !individualSearch.isEmpty()) {150 searchSQL.append(" and ( 1=1 ");151 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {152 searchSQL.append(" and ");153 searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));154 individalColumnSearchValues.addAll(entry.getValue());155 }156 searchSQL.append(" )");157 }158 if (!StringUtil.isNullOrEmpty(system)) {159 searchSQL.append(" and (`System` = ? )");160 }161 query.append(searchSQL);162 if (!StringUtil.isNullOrEmpty(column)) {163 query.append(" order by `").append(column).append("` ").append(dir);164 }165 if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {166 query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);167 } else {168 query.append(" limit ").append(start).append(" , ").append(amount);169 }170 // Debug message on SQL.171 if (LOG.isDebugEnabled()) {172 LOG.debug("SQL : " + query.toString());173 }174 Connection connection = this.databaseSpring.connect();175 try {176 PreparedStatement preStat = connection.prepareStatement(query.toString());177 try {178 int i = 1;179 if (!StringUtil.isNullOrEmpty(searchTerm)) {180 preStat.setString(i++, "%" + searchTerm + "%");181 preStat.setString(i++, "%" + searchTerm + "%");182 preStat.setString(i++, "%" + searchTerm + "%");183 preStat.setString(i++, "%" + searchTerm + "%");184 preStat.setString(i++, "%" + searchTerm + "%");185 preStat.setString(i++, "%" + searchTerm + "%");186 preStat.setString(i++, "%" + searchTerm + "%");187 preStat.setString(i++, "%" + searchTerm + "%");188 preStat.setString(i++, "%" + searchTerm + "%");189 preStat.setString(i++, "%" + searchTerm + "%");190 preStat.setString(i++, "%" + searchTerm + "%");191 }192 for (String individualColumnSearchValue : individalColumnSearchValues) {193 preStat.setString(i++, individualColumnSearchValue);194 }195 if (!StringUtil.isNullOrEmpty(system)) {196 preStat.setString(i++, system);197 }198 ResultSet resultSet = preStat.executeQuery();199 try {200 //gets the data201 while (resultSet.next()) {202 objectList.add(this.loadFromResultSet(resultSet));203 }204 //get the total number of rows205 resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");206 int nrTotalRows = 0;207 if (resultSet != null && resultSet.next()) {208 nrTotalRows = resultSet.getInt(1);209 }210 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.211 LOG.error("Partial Result in the query.");212 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);213 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));214 response = new AnswerList(objectList, nrTotalRows);215 } else if (objectList.size() <= 0) {216 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);217 response = new AnswerList(objectList, nrTotalRows);218 } else {219 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);220 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));221 response = new AnswerList(objectList, nrTotalRows);222 }223 } catch (SQLException exception) {224 LOG.error("Unable to execute query : " + exception.toString());225 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);226 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));227 } finally {228 if (resultSet != null) {229 resultSet.close();230 }231 }232 } catch (SQLException exception) {233 LOG.error("Unable to execute query : " + exception.toString());234 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);235 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));236 } finally {237 if (preStat != null) {238 preStat.close();239 }240 }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%", exception.toString()));245 } finally {246 try {247 if (!this.databaseSpring.isOnTransaction()) {248 if (connection != null) {249 connection.close();250 }251 }252 } catch (SQLException exception) {253 LOG.warn("Unable to close connection : " + exception.toString());254 }255 }256 response.setResultMessage(msg);257 response.setDataList(objectList);258 return response;259 }260 @Override261 public AnswerItem<HashMap<String, HashMap<String, Integer>>> readTestCaseCountersBySystemByStatus(String system) {262 AnswerItem response = new AnswerItem();263 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);264 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));265 StringBuilder query = new StringBuilder();266 query.append("SELECT a.application as ApplicationName, inv.`value` as `Status`, count(inv.`value`) as CountStatus ");267 query.append("FROM application a ");268 query.append("inner join testcase tc on a.application = tc.application ");269 query.append("inner join invariant inv on tc.`Status` = inv.`value` ");270 query.append("where a.system = ? ");271 query.append("and inv.idname='TCSTATUS' and inv.gp1='Y' ");272 query.append("group by a.application, inv.`value` ");273 HashMap<String, HashMap<String, Integer>> result = new HashMap<String, HashMap<String, Integer>>();274 // Debug message on SQL.275 if (LOG.isDebugEnabled()) {276 LOG.debug("SQL : " + query.toString());277 }278 Connection connection = this.databaseSpring.connect();279 try {280 PreparedStatement preStat = connection.prepareStatement(query.toString());281 try {282 preStat.setString(1, system);283 ResultSet resultSet = preStat.executeQuery();284 try {285 //gets the data286 boolean has_data = false;287 while (resultSet.next()) {288 has_data = true;289 String appName = resultSet.getString("ApplicationName");290 String tcStatus = resultSet.getString("Status");291 int countStatus = resultSet.getInt("CountStatus");292 HashMap<String, Integer> totalsMap = result.get(appName);293 if (totalsMap == null) {294 totalsMap = new HashMap<String, Integer>();295 }296 totalsMap.put(tcStatus, countStatus);297 result.put(appName, totalsMap);298 }299 if (has_data) {300 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);301 msg.setDescription(msg.getDescription().replace("%ITEM%", "APPLICATION").replace("%OPERATION%", "SELECT TOTAL"));302 } else {303 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);304 }305 } catch (SQLException exception) {306 LOG.error("Unable to execute query : " + exception.toString());307 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);308 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));309 } finally {310 if (resultSet != null) {311 resultSet.close();312 }313 }314 } catch (SQLException exception) {315 LOG.error("Unable to execute query : " + exception.toString());316 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);317 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));318 } finally {319 if (preStat != null) {320 preStat.close();321 }322 }323 } catch (SQLException exception) {324 LOG.error("Unable to execute query : " + exception.toString());325 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);326 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));327 } finally {328 try {329 if (!this.databaseSpring.isOnTransaction()) {330 if (connection != null) {331 connection.close();332 }333 }334 } catch (SQLException exception) {335 LOG.warn("Unable to close connection : " + exception.toString());336 }337 }338 response.setResultMessage(msg);339 response.setItem(result);340 return response;341 }342 @Override343 public Answer create(Application object) {344 MessageEvent msg = null;345 StringBuilder query = new StringBuilder();346 query.append("INSERT INTO application (`application`, `description`, `sort`, `type`, `system`, `SubSystem`, `svnurl`, `BugTrackerUrl`, `BugTrackerNewUrl`, `deploytype`");347 query.append(", `mavengroupid`, `usrcreated` ) ");348 if (StringUtil.isNullOrEmpty(object.getDeploytype())) {349 query.append("VALUES (?,?,?,?,?,?,?,?,?,null,?,?)");350 } else {351 query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?)");352 }353 // Debug message on SQL.354 if (LOG.isDebugEnabled()) {355 LOG.debug("SQL : " + query.toString());356 }357 Connection connection = this.databaseSpring.connect();358 try {359 PreparedStatement preStat = connection.prepareStatement(query.toString());360 try {361 int i = 1;362 preStat.setString(i++, object.getApplication());363 preStat.setString(i++, object.getDescription());364 preStat.setInt(i++, object.getSort());365 preStat.setString(i++, object.getType());366 preStat.setString(i++, object.getSystem());367 preStat.setString(i++, object.getSubsystem());368 preStat.setString(i++, object.getSvnurl());369 preStat.setString(i++, object.getBugTrackerUrl());370 preStat.setString(i++, object.getBugTrackerNewUrl());371 if (!StringUtil.isNullOrEmpty(object.getDeploytype())) {372 preStat.setString(i++, object.getDeploytype());373 }374 preStat.setString(i++, object.getMavengroupid());375 preStat.setString(i++, object.getUsrCreated());376 preStat.executeUpdate();377 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);378 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));379 } catch (SQLException exception) {380 LOG.error("Unable to execute query : " + exception.toString());381 if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) { //23000 is the sql state for duplicate entries382 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);383 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));384 } else {385 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);386 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));387 }388 } finally {389 preStat.close();390 }391 } catch (SQLException exception) {392 LOG.error("Unable to execute query : " + exception.toString());393 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);394 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));395 } finally {396 try {397 if (connection != null) {398 connection.close();399 }400 } catch (SQLException exception) {401 LOG.error("Unable to close connection : " + exception.toString());402 }403 }404 return new Answer(msg);405 }406 @Override407 public Answer delete(Application object) {408 MessageEvent msg = null;409 final String query = "DELETE FROM application WHERE application = ? ";410 // Debug message on SQL.411 if (LOG.isDebugEnabled()) {412 LOG.debug("SQL : " + query);413 }414 Connection connection = this.databaseSpring.connect();415 try {416 PreparedStatement preStat = connection.prepareStatement(query);417 try {418 preStat.setString(1, object.getApplication());419 preStat.executeUpdate();420 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);421 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "DELETE"));422 } catch (SQLException exception) {423 LOG.error("Unable to execute query : " + exception.toString());424 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);425 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));426 } finally {427 preStat.close();428 }429 } catch (SQLException exception) {430 LOG.error("Unable to execute query : " + exception.toString());431 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);432 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));433 } finally {434 try {435 if (connection != null) {436 connection.close();437 }438 } catch (SQLException exception) {439 LOG.warn("Unable to close connection : " + exception.toString());440 }441 }442 return new Answer(msg);443 }444 @Override445 public Answer update(String application, Application object) {446 MessageEvent msg = null;447 if (StringUtil.isNullOrEmpty(object.getDeploytype())) {448 object.setDeploytype(null);449 }450 final String query = "UPDATE application SET Application = ?, description = ?, sort = ?, `type` = ?, `system` = ?, SubSystem = ?, svnurl = ?, BugTrackerUrl = ?, BugTrackerNewUrl = ?, "451 + "deploytype = ?, mavengroupid = ?, dateModif = NOW(), usrModif= ? WHERE Application = ?";452 // Debug message on SQL.453 if (LOG.isDebugEnabled()) {454 LOG.debug("SQL : " + query);455 LOG.debug("SQL.param.application : " + object.getApplication());456 }457 Connection connection = this.databaseSpring.connect();458 try {459 PreparedStatement preStat = connection.prepareStatement(query);460 try {461 int i = 1;462 preStat.setString(i++, object.getApplication());463 preStat.setString(i++, object.getDescription());464 preStat.setInt(i++, object.getSort());465 preStat.setString(i++, object.getType());466 preStat.setString(i++, object.getSystem());467 preStat.setString(i++, object.getSubsystem());468 preStat.setString(i++, object.getSvnurl());469 preStat.setString(i++, object.getBugTrackerUrl());470 preStat.setString(i++, object.getBugTrackerNewUrl());471 preStat.setString(i++, object.getDeploytype());472 preStat.setString(i++, object.getMavengroupid());473 preStat.setString(i++, object.getUsrModif());474 preStat.setString(i++, application);475 preStat.executeUpdate();476 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);477 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));478 } catch (SQLException exception) {479 LOG.error("Unable to execute query : " + exception.toString());480 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);481 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));482 } finally {483 preStat.close();484 }485 } catch (SQLException exception) {486 LOG.error("Unable to execute query : " + exception.toString());487 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);488 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));489 } finally {490 try {491 if (connection != null) {492 connection.close();493 }494 } catch (SQLException exception) {495 LOG.warn("Unable to close connection : " + exception.toString());496 }497 }498 return new Answer(msg);499 }500 @Override501 public AnswerList<String> readDistinctSystem() {502 MessageEvent msg;503 AnswerList answer = new AnswerList();504 List<String> result = new ArrayList<String>();505 final String query = "SELECT DISTINCT a.system FROM application a ORDER BY a.system ASC";506 // Debug message on SQL.507 if (LOG.isDebugEnabled()) {508 LOG.debug("SQL : " + query);509 }510 Connection connection = this.databaseSpring.connect();511 try {512 PreparedStatement preStat = connection.prepareStatement(query);513 try {514 ResultSet resultSet = preStat.executeQuery();515 try {516 while (resultSet.next()) {517 result.add(resultSet.getString("system"));518 }519 if (result.isEmpty()) {520 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);521 } else {522 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);523 }524 } catch (SQLException exception) {525 LOG.error("Unable to execute query : " + exception.toString());526 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);527 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));528 result.clear();529 } finally {530 if (resultSet != null) {531 resultSet.close();532 }533 }534 } catch (SQLException exception) {535 LOG.error("Unable to execute query : " + exception.toString());536 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);537 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));538 } finally {539 if (preStat != null) {540 preStat.close();541 }542 }543 } catch (SQLException exception) {544 LOG.error("Unable to execute query : " + exception.toString());545 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);546 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));547 } finally {548 try {549 if (connection != null) {550 connection.close();551 }552 } catch (SQLException exception) {553 LOG.warn("Unable to close connection : " + exception.toString());554 }555 }556 answer.setTotalRows(result.size());557 answer.setDataList(result);558 answer.setResultMessage(msg);559 return answer;560 }561 @Override562 public Application loadFromResultSet(ResultSet rs) throws SQLException {563 String application = ParameterParserUtil.parseStringParam(rs.getString("app.application"), "");564 String description = ParameterParserUtil.parseStringParam(rs.getString("app.description"), "");565 int sort = ParameterParserUtil.parseIntegerParam(rs.getString("app.sort"), 0);566 String type = ParameterParserUtil.parseStringParam(rs.getString("app.type"), "");567 String system = ParameterParserUtil.parseStringParam(rs.getString("app.system"), "");568 String subsystem = ParameterParserUtil.parseStringParam(rs.getString("app.subsystem"), "");569 String svnUrl = ParameterParserUtil.parseStringParam(rs.getString("app.svnurl"), "");570 String deployType = ParameterParserUtil.parseStringParam(rs.getString("app.deploytype"), "");571 String mavenGroupId = ParameterParserUtil.parseStringParam(rs.getString("app.mavengroupid"), "");572 String bugTrackerUrl = ParameterParserUtil.parseStringParam(rs.getString("app.bugtrackerurl"), "");573 String bugTrackerNewUrl = ParameterParserUtil.parseStringParam(rs.getString("app.bugtrackernewurl"), "");574 String usrModif = ParameterParserUtil.parseStringParam(rs.getString("app.UsrModif"), "");575 String usrCreated = ParameterParserUtil.parseStringParam(rs.getString("app.UsrCreated"), "");576 Timestamp dateModif = rs.getTimestamp("app.DateModif");...
loadFromResultSet
Using AI Code Generation
1package com.cerberus.test;2import java.sql.ResultSet;3import java.sql.SQLException;4import java.util.logging.Level;5import java.util.logging.Logger;6import org.cerberus.crud.dao.impl.ApplicationDAO;7import org.cerberus.crud.entity.Application;8public class TestApplicationDAO {9 public static void main(String[] args) {10 ApplicationDAO appDao = new ApplicationDAO();11 ResultSet rs = null;12 try {13 rs = appDao.readByVariousByCriteria("test", null, null, null, null, null, null);14 while(rs.next()) {15 Application app = new Application();16 appDao.loadFromResultSet(app, rs);17 System.out.println(app.toString());18 }19 } catch (SQLException ex) {20 Logger.getLogger(TestApplicationDAO.class.getName()).log(Level.SEVERE, null, ex);21 }22 }23}24Application{application=TEST, description=Test Application, type=MANUAL, system=TEST, active=Y, maintenanceact=N, maintenancestr=2015-01-01 00:00:00.0, maintenanceend=2015-01-01 00:00:00.0, maintenanceusr=TEST, group=, bugTrackerUrl=, bugTrackerNewUrl=, bugTrackerJsonUrl=, bugTrackerUrlLogin=, bugTrackerUrlPwd=, ticketOpenStatus=, ticketCloseStatus=, ticketAssignedStatus=, ticketNewStatus=, ticketReopenStatus=, ticketRejectedStatus=, ticketDeployedStatus=, ticketClosedStatus=, ticketOtherStatus=, ticketNewBugStatus=, ticketAssignedBugStatus=, ticketRejectedBugStatus=, ticketClosedBugStatus=, ticketOtherBugStatus=, ticketOpenStatusList=, ticketCloseStatusList=, ticketAssignedStatusList=, ticketNewStatusList=, ticketReopenStatusList=, ticketRejectedStatusList=, ticketDeployedStatusList=, ticketClosedStatusList=, ticketOtherStatusList=, ticketNewBugStatusList=, ticketAssignedBugStatusList=, ticketRejectedBugStatusList=, ticketClosedBugStatusList=, ticketOtherBugStatusList=}25Application{application=TEST2, description=Test Application 2, type=MANUAL, system=TEST, active=Y, maintenanceact=N, maintenancestr=2015-01-01 00:00:00
loadFromResultSet
Using AI Code Generation
1package com.mycompany.myapp;2import org.cerberus.crud.dao.impl.ApplicationDAO;3import org.cerberus.crud.entity.Application;4import java.sql.Connection;5import java.sql.DriverManager;6import java.sql.ResultSet;7import java.sql.SQLException;8import java.sql.Statement;9public class Main {10 public static void main(String[] args) throws SQLException {11 ApplicationDAO applicationDAO = new ApplicationDAO();12 Connection connection = null;13 Statement statement = null;14 ResultSet resultSet = null;15 try {16 connection = DriverManager.getConnection("jdbc:sqlite:cerberus.db");17 statement = connection.createStatement();18 resultSet = statement.executeQuery("SELECT * FROM application");19 while (resultSet.next()) {20 Application application = new Application();21 applicationDAO.loadFromResultSet(application, resultSet);22 System.out.println(application);23 }24 } catch (SQLException e) {25 e.printStackTrace();26 } finally {27 if (resultSet != null) {28 resultSet.close();29 }30 if (statement != null) {31 statement.close();32 }33 if (connection != null) {34 connection.close();35 }36 }37 }38}39Application{id=1, system=1, description='Cerberus', type='INTERNAL', subtype='Cerberus', group='Cerberus', system='Cerberus', active='Y', datecre='2015-09-07 00:00:00.0', usrcre='Cerberus', dateModif='2015-09-07 00:00:00.0', usrModif='Cerberus'}40Application{id=2, system=1, description='Cerberus', type='INTERNAL', subtype='Cerberus', group='Cerberus', system='Cerberus', active='Y', datecre='2015-09-07 00:00:00.0', usrcre='Cerberus', dateModif='2015-09-07 00:00:00.0', usrModif='Cerberus'}41Application{id=3, system=1, description='Cerberus', type='INTERNAL', subtype='Cerberus', group='Cerberus', system='Cerberus', active='Y', datecre='2015-09-07 00:00:00.0', usrcre='Cer
loadFromResultSet
Using AI Code Generation
1public class ApplicationDAOImplTest {2 public void testLoadFromResultSet() throws Exception {3 ApplicationDAOImpl instance = new ApplicationDAOImpl();4 ResultSet rs = null;5 Application expResult = null;6 Application result = instance.loadFromResultSet(rs);7 assertEquals(expResult, result);8 }9}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!