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

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

Source:TestCaseCountryPropertiesDAO.java Github

copy

Full Screen

...78 ps -> {79 ps.setString(1, test);80 ps.setString(2, testcase);81 },82 this::loadFromResultSet83 );84 }85 @Override86 public List<TestCaseCountryProperties> findListOfPropertyPerTestTestCaseList(List<TestCase> testcases) throws CerberusException {87 StringBuilder query = new StringBuilder();88 query.append("SELECT * FROM testcasecountryproperties tcp WHERE 1=1");89 // TestCase dependency should only be used on testcasedataexecution.90 // In other words, when a test case is linked to another testcase, it should have access to its data at execution level but should not inherit from testcase property definition.91 // As a consequece this method should not return testCaseCountryPropertiesList from dependencies.92 //"OR exists (select 1 from testcasedep where DepTest = tcp.Test AND DepTestCase = tcp.TestCase AND Test = ? AND TestCase = ?)";93 // Manage tc dependencies94 if ((testcases != null) && !testcases.isEmpty() && testcases.size() < 5000) {95 query.append(" AND (");96 int j = 0;97 for (TestCase testCase1 : testcases) {98 if (j != 0) {99 query.append(" OR");100 }101 query.append(" (tcp.`test` = ? and tcp.testcase = ?) ");102 j++;103 }104 query.append(" )");105 } else {106 query.append(" and 1=0 ");107 }108 return RequestDbUtils.executeQueryList(databaseSpring, query.toString(),109 ps -> {110 int i = 1;111 if ((testcases != null) && !testcases.isEmpty() && testcases.size() < 5000) {112 for (TestCase testCaseObj : testcases) {113 ps.setString(i++, testCaseObj.getTest());114 ps.setString(i++, testCaseObj.getTestcase());115 }116 }117 },118 this::loadFromResultSet119 );120 }121 @Override122 public List<TestCaseCountryProperties> findListOfPropertyPerTestTestCaseProperty(String test, String testcase, String oneproperty) {123 List<TestCaseCountryProperties> testCaseCountryPropertiesList = null;124 final String query = "SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ? AND property = ?";125 loggingQuery(query);126 try (Connection connection = this.databaseSpring.connect();127 PreparedStatement preStat = connection.prepareStatement(query);) {128 int i = 1;129 preStat.setString(i++, test);130 preStat.setString(i++, testcase);131 preStat.setString(i++, oneproperty);132 try (ResultSet resultSet = preStat.executeQuery();) {133 testCaseCountryPropertiesList = new ArrayList<>();134 while (resultSet.next()) {135 testCaseCountryPropertiesList.add(loadFromResultSet(resultSet));136 }137 } catch (SQLException exception) {138 LOG.error("Unable to execute query : " + exception.toString());139 }140 } catch (SQLException exception) {141 LOG.error("Unable to execute query : " + exception.toString());142 }143 return testCaseCountryPropertiesList;144 }145 @Override146 public List<String> findCountryByProperty(TestCaseCountryProperties testCaseCountryProperties) {147 List<String> countries = null;148 final StringBuilder query = new StringBuilder();149 query.append("SELECT country FROM testcasecountryproperties WHERE test = ? AND testcase = ?");150 query.append(" AND HEX(`property`) = hex(?) AND `type` =? AND `database` =? AND hex(`value1`) like hex( ? ) AND hex(`value2`) like hex( ? ) AND `length` = ? ");151 query.append(" AND `rowlimit` = ? AND `nature` = ?");152 loggingQuery(query.toString());153 try (Connection connection = this.databaseSpring.connect();154 PreparedStatement preStat = connection.prepareStatement(query.toString());) {155 int i = 1;156 preStat.setString(i++, testCaseCountryProperties.getTest());157 preStat.setString(i++, testCaseCountryProperties.getTestcase());158 preStat.setBytes(i++, testCaseCountryProperties.getProperty().getBytes("UTF-8"));159 preStat.setString(i++, testCaseCountryProperties.getType());160 preStat.setString(i++, testCaseCountryProperties.getDatabase());161 preStat.setBytes(i++, testCaseCountryProperties.getValue1().getBytes("UTF-8"));162 preStat.setBytes(i++, testCaseCountryProperties.getValue2().getBytes("UTF-8"));163 preStat.setString(i++, String.valueOf(testCaseCountryProperties.getLength()));164 preStat.setString(i++, String.valueOf(testCaseCountryProperties.getRowLimit()));165 preStat.setString(i++, testCaseCountryProperties.getNature());166 try (ResultSet resultSet = preStat.executeQuery();) {167 countries = new ArrayList<>();168 String countryToAdd;169 while (resultSet.next()) {170 countryToAdd = resultSet.getString("Country") == null ? "" : resultSet.getString("Country");171 countries.add(countryToAdd);172 }173 } catch (SQLException exception) {174 LOG.error("Unable to execute query : " + exception.toString());175 }176 } catch (SQLException exception) {177 LOG.error("Unable to execute query : " + exception.toString());178 } catch (UnsupportedEncodingException ex) {179 LOG.error(ex.toString());180 }181 return countries;182 }183 @Override184 public List<TestCaseCountryProperties> findListOfPropertyPerTestTestCaseCountry(String test, String testcase, String country) {185 List<TestCaseCountryProperties> testCaseCountryPropertiesList = null;186 final String query = "SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ? AND country = ?";187 // Debug message on SQL.188 if (LOG.isDebugEnabled()) {189 LOG.debug("SQL : " + query);190 LOG.debug("SQL.param.test : " + test);191 LOG.debug("SQL.param.testcase : " + testcase);192 LOG.debug("SQL.param.country : " + country);193 }194 try (Connection connection = this.databaseSpring.connect();195 PreparedStatement preStat = connection.prepareStatement(query);) {196 int i = 1;197 preStat.setString(i++, test);198 preStat.setString(i++, testcase);199 preStat.setString(i++, country);200 try (ResultSet resultSet = preStat.executeQuery();) {201 testCaseCountryPropertiesList = new ArrayList<>();202 while (resultSet.next()) {203 testCaseCountryPropertiesList.add(loadFromResultSet(resultSet));204 }205 } catch (SQLException exception) {206 LOG.error("Unable to execute query : " + exception.toString());207 }208 } catch (SQLException exception) {209 LOG.error("Unable to execute query : " + exception.toString());210 }211 return testCaseCountryPropertiesList;212 }213 @Override214 public TestCaseCountryProperties findTestCaseCountryPropertiesByKey(String test, String testcase, String country, String property) throws CerberusException {215 TestCaseCountryProperties testCaseCountryProperties = null;216 final String query = "SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ? AND country = ? AND hex(`property`) = hex(?)";217 loggingQuery(query);218 try (Connection connection = this.databaseSpring.connect();219 PreparedStatement preStat = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);) {220 int i = 1;221 preStat.setString(i++, test);222 preStat.setString(i++, testcase);223 preStat.setString(i++, country);224 preStat.setBytes(i++, property.getBytes("UTF-8"));225 ResultSet resultSet = preStat.executeQuery();226 try {227 if (resultSet.first()) {228 testCaseCountryProperties = loadFromResultSet(resultSet);229 } else {230 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));231 }232 } catch (SQLException exception) {233 LOG.error("Unable to execute query : " + exception.toString());234 }235 } catch (SQLException exception) {236 LOG.error("Unable to execute query : " + exception.toString());237 } catch (UnsupportedEncodingException ex) {238 LOG.error(ex.toString());239 }240 return testCaseCountryProperties;241 }242 @Override243 public void insertTestCaseCountryProperties(TestCaseCountryProperties testCaseCountryProperties) throws CerberusException {244 StringBuilder query = new StringBuilder();245 query.append("INSERT INTO testcasecountryproperties (`Test`,`TestCase`,`Country`,`Property` ,`Description`,`Type`");246 query.append(",`Database`,`Value1`,`Value2`,`Length`,`RowLimit`,`Nature`,`RetryNb`,`RetryPeriod`,`Rank`,");247 query.append("`UsrCreated`)");248 query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");249 loggingQuery(query.toString());250 try (Connection connection = this.databaseSpring.connect();251 PreparedStatement preStat = connection.prepareStatement(query.toString());) {252 int i = 1;253 preStat.setString(i++, testCaseCountryProperties.getTest());254 preStat.setString(i++, testCaseCountryProperties.getTestcase());255 preStat.setString(i++, testCaseCountryProperties.getCountry());256 preStat.setBytes(i++, testCaseCountryProperties.getProperty().getBytes("UTF-8"));257 preStat.setBytes(i++, testCaseCountryProperties.getDescription().getBytes("UTF-8"));258 preStat.setString(i++, testCaseCountryProperties.getType());259 preStat.setString(i++, testCaseCountryProperties.getDatabase());260 preStat.setBytes(i++, testCaseCountryProperties.getValue1().getBytes("UTF-8"));261 preStat.setBytes(i++, testCaseCountryProperties.getValue2().getBytes("UTF-8"));262 preStat.setString(i++, testCaseCountryProperties.getLength());263 preStat.setInt(i++, testCaseCountryProperties.getRowLimit());264 preStat.setString(i++, testCaseCountryProperties.getNature());265 preStat.setInt(i++, testCaseCountryProperties.getRetryNb());266 preStat.setInt(i++, testCaseCountryProperties.getRetryPeriod());267 preStat.setInt(i++, testCaseCountryProperties.getRank());268 preStat.setString(i++, testCaseCountryProperties.getUsrCreated() == null ? "" : testCaseCountryProperties.getUsrCreated());269 preStat.executeUpdate();270 } catch (SQLException exception) {271 LOG.error("Unable to execute query : " + exception.toString());272 } catch (UnsupportedEncodingException ex) {273 LOG.error(ex.toString());274 }275 }276 @Override277 public void updateTestCaseCountryProperties(TestCaseCountryProperties testCaseCountryProperties) throws CerberusException {278 StringBuilder query = new StringBuilder();279 query.append("UPDATE testcasecountryproperties SET ");280 query.append("`Description` = ?, ");281 query.append("`Type` = ?, ");282 query.append("`Database` = ?, ");283 query.append("`Value1` = ?, ");284 query.append("`Value2` = ?, ");285 query.append("`Length` = ?, ");286 query.append("`RowLimit` = ?, ");287 query.append("`Nature` = ?, ");288 query.append("`RetryNb` = ?, ");289 query.append("`RetryPeriod` = ?, ");290 query.append("`Rank` = ?, ");291 query.append("`UsrModif` = ?, ");292 query.append("`DateModif` = CURRENT_TIMESTAMP ");293 query.append(" WHERE Test = ? AND TestCase = ? AND Country = ? AND hex(`Property`) like hex(?)");294 loggingQuery(query.toString());295 try (Connection connection = this.databaseSpring.connect();296 PreparedStatement preStat = connection.prepareStatement(query.toString());) {297 int i = 1;298 preStat.setBytes(i++, testCaseCountryProperties.getDescription().getBytes("UTF-8"));299 preStat.setString(i++, testCaseCountryProperties.getType());300 preStat.setString(i++, testCaseCountryProperties.getDatabase());301 preStat.setBytes(i++, testCaseCountryProperties.getValue1().getBytes("UTF-8"));302 preStat.setBytes(i++, testCaseCountryProperties.getValue2().getBytes("UTF-8"));303 preStat.setString(i++, testCaseCountryProperties.getLength());304 preStat.setInt(i++, testCaseCountryProperties.getRowLimit());305 preStat.setString(i++, testCaseCountryProperties.getNature());306 preStat.setInt(i++, testCaseCountryProperties.getRetryNb());307 preStat.setInt(i++, testCaseCountryProperties.getRetryPeriod());308 preStat.setInt(i++, testCaseCountryProperties.getRank());309 preStat.setString(i++, testCaseCountryProperties.getUsrModif() == null ? "" : testCaseCountryProperties.getUsrModif());310 preStat.setString(i++, testCaseCountryProperties.getTest());311 preStat.setString(i++, testCaseCountryProperties.getTestcase());312 preStat.setString(i++, testCaseCountryProperties.getCountry());313 preStat.setBytes(i++, testCaseCountryProperties.getProperty().getBytes("UTF-8"));314 preStat.executeUpdate();315 } catch (SQLException exception) {316 LOG.error("Unable to execute query : " + exception.toString());317 } catch (UnsupportedEncodingException ex) {318 LOG.error(ex.toString());319 }320 }321 @Override322 public Answer bulkRenameProperties(String oldName, String newName) {323 Answer answer = new Answer();324 MessageEvent msg;325 StringBuilder query = new StringBuilder();326 query.append("UPDATE testcasecountryproperties SET ");327 query.append("`Value1`= ?, ");328 query.append("`DateModif` = CURRENT_TIMESTAMP ");329 query.append("WHERE `Type` = 'getFromDataLib' AND `Value1`= ?");330 loggingQuery(query.toString());331 try (Connection connection = this.databaseSpring.connect();332 PreparedStatement preStat = connection.prepareStatement(query.toString());) {333 int i = 1;334 preStat.setString(i++, newName);335 preStat.setString(i++, oldName);336 int rowsUpdated = preStat.executeUpdate();337 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);338 // Message to customize : X testCaseCountryPropertiesList updated using the rowsUpdated variable339 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE").replace("success!", "success! - Row(s) updated : " + String.valueOf(rowsUpdated)));340 } catch (SQLException exception) {341 LOG.error("Unable to execute query : " + exception.toString(), exception);342 if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) { //23000 is the sql state for duplicate entries343 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);344 msg.setDescription(msg.getDescription().replace("%ITEM%", "Test data lib ").replace("%OPERATION%", "UPDATE").replace("%REASON%", exception.toString()));345 } else {346 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);347 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));348 }349 }350 answer.setResultMessage(msg);351 return answer;352 }353 @Override354 public List<String> findCountryByPropertyNameAndTestCase(String test, String testcase, String property) {355 List<String> countries = new ArrayList<>();356 final String query = "SELECT country FROM testcasecountryproperties WHERE test = ? AND testcase = ? AND hex(`property`) like hex(?)";357 loggingQuery(query);358 try (Connection connection = this.databaseSpring.connect();359 PreparedStatement preStat = connection.prepareStatement(query);) {360 int i = 1;361 preStat.setString(i++, test);362 preStat.setString(i++, testcase);363 preStat.setBytes(i++, property.getBytes("UTF-8"));364 try (ResultSet resultSet = preStat.executeQuery();) {365 while (resultSet.next()) {366 String country = resultSet.getString("country");367 if (country != null && !"".equals(country)) {368 countries.add(country);369 }370 }371 } catch (SQLException exception) {372 LOG.error("Unable to execute query : " + exception.toString());373 }374 } catch (SQLException exception) {375 LOG.error("Unable to execute query : " + exception.toString());376 } catch (UnsupportedEncodingException ex) {377 LOG.error(ex.toString());378 }379 return (countries.isEmpty()) ? null : countries;380 }381 @Override382 public void deleteTestCaseCountryProperties(TestCaseCountryProperties tccp) throws CerberusException {383 final String query = "DELETE FROM testcasecountryproperties WHERE test = ? and testcase = ? and country = ? and hex(`property`) like hex(?)";384 loggingQuery(query);385 try (Connection connection = this.databaseSpring.connect();386 PreparedStatement preStat = connection.prepareStatement(query);) {387 int i = 1;388 preStat.setString(i++, tccp.getTest());389 preStat.setString(i++, tccp.getTestcase());390 preStat.setString(i++, tccp.getCountry());391 preStat.setBytes(i++, tccp.getProperty().getBytes("UTF-8"));392 if (preStat.executeUpdate() == 0) {393 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));394 }395 } catch (SQLException exception) {396 LOG.error("Unable to execute query : " + exception.toString());397 } catch (UnsupportedEncodingException ex) {398 LOG.error(ex.toString());399 }400 }401 @Override402 public AnswerList<TestListDTO> findTestCaseCountryPropertiesByValue1(int testDataLib, String name, String country, String propertyType) {403 AnswerList<TestListDTO> ansList = new AnswerList<>();404 MessageEvent msg;405 List<TestListDTO> listOfTests = new ArrayList<>();406 StringBuilder query = new StringBuilder();407 query.append("select count(*) as total, tccp.property, t.Test, tc.TestCase, t.Description as testDescription, tc.Description as testCaseDescription, tc.Application, ");408 query.append("tc.isActive, tc.`Type`, tc.UsrCreated, tc.`Status` ");409 query.append("from testcasecountryproperties tccp ");410 query.append("inner join test t on t.test = tccp.test ");411 query.append("inner join testcase tc on t.test = tccp.test and t.test = tc.test ");412 query.append("inner join testdatalib tdl on tdl.`name` = tccp.value1 and ");413 query.append("(tccp.Country = tdl.Country or tdl.country='') and tccp.test = t.test and tccp.testcase = tc.testcase ");414 query.append("where tccp.`Type` LIKE ? and tdl.TestDataLibID = ? ");415 query.append("and tdl.`Name` LIKE ? and (tdl.Country = ? or tdl.country='') ");416 query.append("group by tccp.test, tccp.testcase, tccp.property ");417 loggingQuery(query.toString());418 try (Connection connection = this.databaseSpring.connect();419 PreparedStatement preStat = connection.prepareStatement(query.toString());) {420 int i = 1;421 preStat.setString(i++, propertyType);422 preStat.setInt(i++, testDataLib);423 preStat.setString(i++, name);424 preStat.setString(i++, country);425 HashMap<String, TestListDTO> map = new HashMap<>();426 HashMap<String, List<PropertyListDTO>> auxiliaryMap = new HashMap<>();//the key is the test + ":" +testcasenumber427 String key, test, testCase;428 try (ResultSet resultSet = preStat.executeQuery();) {429 while (resultSet.next()) {430 TestListDTO testList;431 TestCaseListDTO testCaseDTO;432 List<PropertyListDTO> propertiesList;433 test = resultSet.getString("Test");434 testCase = resultSet.getString("TestCase");435 //TEST436 //gets the info from test cases that match the desired information437 if (map.containsKey(test)) {438 testList = map.get(test);439 } else {440 testList = new TestListDTO();441 testList.setDescription(resultSet.getString("testDescription"));442 testList.setTest(test);443 }444 //TESTCASE445 key = test + ":" + testCase;446 if (!auxiliaryMap.containsKey(key)) {447 //means that we must associate a new test case with a test448 testCaseDTO = new TestCaseListDTO();449 testCaseDTO.setTestCaseDescription(resultSet.getString("testCaseDescription"));450 testCaseDTO.setTestCaseNumber(testCase);451 testCaseDTO.setApplication(resultSet.getString("Application"));452 testCaseDTO.setCreator(resultSet.getString("tc.UsrCreated"));453 testCaseDTO.setStatus(resultSet.getString("Status"));454 testCaseDTO.setGroup(resultSet.getString("Type"));455 testCaseDTO.setIsActive(resultSet.getString("isActive"));456 testList.getTestCaseList().add(testCaseDTO);457 map.put(test, testList);458 propertiesList = new ArrayList<>();459 } else {460 propertiesList = auxiliaryMap.get(key);461 }462 PropertyListDTO prop = new PropertyListDTO();463 prop.setNrCountries(resultSet.getInt("total"));464 prop.setPropertyName(resultSet.getString("property"));465 propertiesList.add(prop);466 //stores the information about the testCaseCountryPropertiesList467 auxiliaryMap.put(key, propertiesList);468 }469 //assigns the testCaseCountryPropertiesList of tests retrieved by the query to the testCaseCountryPropertiesList470 listOfTests = new ArrayList<>(map.values());471 //assigns the testCaseCountryPropertiesList of testCaseCountryPropertiesList to the correct testcaselist472 for (TestListDTO list : listOfTests) {473 for (TestCaseListDTO cases : list.getTestCaseList()) {474 cases.setPropertiesList(auxiliaryMap.get(list.getTest() + ":" + cases.getTestCaseNumber()));475 }476 }477 if (listOfTests.isEmpty()) {478 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);479 } else {480 msg = successExecuteQuery("List of Test Cases", "SELECT");481 }482 } catch (SQLException exception) {483 msg = unexpectedError(exception, "Unable to get the list of test cases.");484 }485 } catch (SQLException exception) {486 msg = unexpectedError(exception, "Unable to get the list of test cases.");487 }488 ansList.setResultMessage(msg);489 ansList.setDataList(listOfTests);490 return ansList;491 }492 @Override493 public Answer createTestCaseCountryPropertiesBatch(List<TestCaseCountryProperties> testCaseCountryPropertiesList) {494 Answer answer = new Answer();495 MessageEvent msg;496 StringBuilder query = new StringBuilder();497 query.append("INSERT INTO testcasecountryproperties (`Test`,`TestCase`,`Country`,`Property` , `Description`, `Type`");498 query.append(",`Database`,`Value1`,`Value2`,`Length`,`RowLimit`,`Nature`,`RetryNb`,`RetryPeriod`, `Rank`, `UsrCreated`) ");499 query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");500 loggingQuery(query.toString());501 try (Connection connection = this.databaseSpring.connect();502 PreparedStatement preStat = connection.prepareStatement(query.toString());) {503 for (TestCaseCountryProperties testCaseCountryProperties : testCaseCountryPropertiesList) {504 int i = 1;505 preStat.setString(i++, testCaseCountryProperties.getTest());506 preStat.setString(i++, testCaseCountryProperties.getTestcase());507 preStat.setString(i++, testCaseCountryProperties.getCountry());508 preStat.setString(i++, testCaseCountryProperties.getProperty());509 preStat.setString(i++, testCaseCountryProperties.getDescription());510 preStat.setString(i++, testCaseCountryProperties.getType());511 preStat.setString(i++, testCaseCountryProperties.getDatabase());512 preStat.setString(i++, testCaseCountryProperties.getValue1());513 preStat.setString(i++, testCaseCountryProperties.getValue2());514 preStat.setString(i++, testCaseCountryProperties.getLength());515 preStat.setInt(i++, testCaseCountryProperties.getRowLimit());516 preStat.setString(i++, testCaseCountryProperties.getNature());517 preStat.setInt(i++, testCaseCountryProperties.getRetryNb());518 preStat.setInt(i++, testCaseCountryProperties.getRetryPeriod());519 preStat.setInt(i++, testCaseCountryProperties.getRank());520 preStat.setString(i++, testCaseCountryProperties.getUsrCreated() == null ? "" : testCaseCountryProperties.getUsrCreated());521 preStat.addBatch();522 }523 preStat.executeBatch();524 int affectedRows[] = preStat.executeBatch();525 //verify if some of the statements failed526 boolean someFailed = ArrayUtils.contains(affectedRows, 0) || ArrayUtils.contains(affectedRows, Statement.EXECUTE_FAILED);527 if (someFailed) {528 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);529 msg.setDescription(msg.getDescription().replace("%ITEM%", "Property").replace("%OPERATION%", "CREATE").530 replace("%REASON%", "Some problem occurred while creating the new property! "));531 } else {532 msg = successExecuteQuery(OBJECT_NAME, "CREATE");533 }534 } catch (SQLException exception) {535 msg = unexpectedError(exception, "It was not possible to update table.");536 }537 answer.setResultMessage(msg);538 return answer;539 }540 @Override541 public Answer create(TestCaseCountryProperties testCaseCountryProperties) {542 MessageEvent msg = null;543 StringBuilder query = new StringBuilder();544 query.append("INSERT INTO testcasecountryproperties (`Test`,`TestCase`,`Country`,`Property`,`Description`,`Type`");545 query.append(",`Database`,`Value1`,`Value2`,`Length`,`RowLimit`,`Nature`,`RetryNb`,`RetryPeriod`,`CacheExpire`,`Rank`, `UsrCreated`)");546 query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");547 loggingQuery(query.toString());548 try (Connection connection = this.databaseSpring.connect();549 PreparedStatement preStat = connection.prepareStatement(query.toString());) {550 int i = 1;551 preStat.setString(i++, testCaseCountryProperties.getTest());552 preStat.setString(i++, testCaseCountryProperties.getTestcase());553 preStat.setString(i++, testCaseCountryProperties.getCountry());554 preStat.setString(i++, testCaseCountryProperties.getProperty());555 preStat.setString(i++, testCaseCountryProperties.getDescription());556 preStat.setString(i++, testCaseCountryProperties.getType());557 preStat.setString(i++, testCaseCountryProperties.getDatabase());558 preStat.setString(i++, testCaseCountryProperties.getValue1());559 preStat.setString(i++, testCaseCountryProperties.getValue2());560 preStat.setString(i++, testCaseCountryProperties.getLength());561 preStat.setInt(i++, testCaseCountryProperties.getRowLimit());562 preStat.setString(i++, testCaseCountryProperties.getNature());563 preStat.setInt(i++, testCaseCountryProperties.getRetryNb());564 preStat.setInt(i++, testCaseCountryProperties.getRetryPeriod());565 preStat.setInt(i++, testCaseCountryProperties.getCacheExpire());566 preStat.setInt(i++, testCaseCountryProperties.getRank());567 preStat.setString(i++, testCaseCountryProperties.getUsrCreated() == null ? "" : testCaseCountryProperties.getUsrCreated());568 preStat.executeUpdate();569 msg = successExecuteQuery(OBJECT_NAME, "INSERT");570 } catch (SQLException exception) {571 if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) { //23000 is the sql state for duplicate entries572 LOG.error("Unable to execute query : " + exception.toString(), exception);573 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);574 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));575 } else {576 msg = unexpectedError(exception);577 }578 }579 return new Answer(msg);580 }581 @Override582 public Answer delete(TestCaseCountryProperties object) {583 MessageEvent msg;584 final String query = "DELETE FROM `testcasecountryproperties` WHERE `Test`=? and `TestCase`=? and `Country`=? and `Property`=?";585 loggingQuery(query);586 try (Connection connection = this.databaseSpring.connect();587 PreparedStatement preStat = connection.prepareStatement(query);) {588 int i = 1;589 preStat.setString(i++, object.getTest());590 preStat.setString(i++, object.getTestcase());591 preStat.setString(i++, object.getCountry());592 preStat.setString(i++, object.getProperty());593 preStat.executeUpdate();594 msg = successExecuteQuery(OBJECT_NAME, "DELETE");595 } catch (SQLException exception) {596 msg = unexpectedError(exception);597 }598 return new Answer(msg);599 }600 @Override601 public Answer update(TestCaseCountryProperties testCaseCountryProperties) {602 MessageEvent msg;603 StringBuilder query = new StringBuilder();604 query.append("UPDATE testcasecountryproperties SET ");605 query.append("`Description` = ?, ");606 query.append("`Type` = ?, ");607 query.append("`Database` = ?, ");608 query.append("`Value1` = ?, ");609 query.append("`Value2` = ?, ");610 query.append("`Length` = ?, ");611 query.append("`RowLimit` = ?, ");612 query.append("`Nature` = ?, ");613 query.append("`RetryNb` = ?, ");614 query.append("`RetryPeriod` = ?, ");615 query.append("`CacheExpire` = ?, ");616 query.append("`Rank` = ?, ");617 query.append("`UsrModif` = ?, ");618 query.append("`DateModif` = CURRENT_TIMESTAMP ");619 query.append("WHERE `Test` = ? AND `TestCase` = ? AND `Country` = ? AND `Property` = ?");620 loggingQuery(query.toString());621 try (Connection connection = this.databaseSpring.connect();622 PreparedStatement preStat = connection.prepareStatement(query.toString());) {623 int i = 1;624 preStat.setString(i++, testCaseCountryProperties.getDescription());625 preStat.setString(i++, testCaseCountryProperties.getType());626 preStat.setString(i++, testCaseCountryProperties.getDatabase());627 preStat.setString(i++, testCaseCountryProperties.getValue1());628 preStat.setString(i++, testCaseCountryProperties.getValue2());629 preStat.setString(i++, testCaseCountryProperties.getLength());630 preStat.setInt(i++, testCaseCountryProperties.getRowLimit());631 preStat.setString(i++, testCaseCountryProperties.getNature());632 preStat.setInt(i++, testCaseCountryProperties.getRetryNb());633 preStat.setInt(i++, testCaseCountryProperties.getRetryPeriod());634 preStat.setInt(i++, testCaseCountryProperties.getCacheExpire());635 preStat.setInt(i++, testCaseCountryProperties.getRank());636 preStat.setString(i++, testCaseCountryProperties.getUsrModif() == null ? "" : testCaseCountryProperties.getUsrModif());637 preStat.setString(i++, testCaseCountryProperties.getTest());638 preStat.setString(i++, testCaseCountryProperties.getTestcase());639 preStat.setString(i++, testCaseCountryProperties.getCountry());640 preStat.setString(i++, testCaseCountryProperties.getProperty());641 preStat.executeUpdate();642 msg = successExecuteQuery(OBJECT_NAME, "UPDATE");643 } catch (SQLException exception) {644 msg = unexpectedError(exception);645 }646 return new Answer(msg);647 }648 @Override649 public TestCaseCountryProperties loadFromResultSet(ResultSet resultSet) throws SQLException {650 return TestCaseCountryProperties.builder()651 .test(resultSet.getString(TestCaseCountryProperties.DB_TEST))652 .testcase(resultSet.getString(TestCaseCountryProperties.DB_TESTCASE))653 .country(resultSet.getString(TestCaseCountryProperties.DB_COUNTRY))654 .property(resultSet.getString(TestCaseCountryProperties.DB_PROPERTY))655 .description(resultSet.getString(TestCaseCountryProperties.DB_DESCRIPTION))656 .type(resultSet.getString(TestCaseCountryProperties.DB_TYPE))657 .database(resultSet.getString(TestCaseCountryProperties.DB_DATABASE))658 .value1(resultSet.getString(TestCaseCountryProperties.DB_VALUE1))659 .value2(resultSet.getString(TestCaseCountryProperties.DB_VALUE2))660 .length(resultSet.getString(TestCaseCountryProperties.DB_LENGTH))661 .rowLimit(resultSet.getInt(TestCaseCountryProperties.DB_ROWLIMIT))662 .nature(resultSet.getString(TestCaseCountryProperties.DB_NATURE))663 .retryNb(resultSet.getInt(TestCaseCountryProperties.DB_RETRYNB))...

Full Screen

Full Screen

loadFromResultSet

Using AI Code Generation

copy

Full Screen

1public class TestCaseCountryPropertiesDAOImpl implements ITestCaseCountryPropertiesDAO {2 private static final Logger LOG = LogManager.getLogger(TestCaseCountryPropertiesDAOImpl.class);3 private final String OBJECT_NAME = "TestCaseCountryProperties";4 private final String SQL_DUPLICATED_CODE = "23000";5 private final int MAX_ROW_SELECTED = 100000;6 public List<TestCaseCountryProperties> findTestCaseCountryPropertiesByTestTestCase(String test, String testCase) {7 List<TestCaseCountryProperties> result = new ArrayList<TestCaseCountryProperties>();8 final String query = "SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ? ORDER BY test, testcase, country, property";9 Connection connection = this.databaseSpring.connect();10 try {11 PreparedStatement preStat = connection.prepareStatement(query);12 preStat.setString(1, test);13 preStat.setString(2, testCase);14 ResultSet resultSet = preStat.executeQuery();15 try {16 while (resultSet.next()) {17 result.add(this.loadFromResultSet(resultSet));18 }19 } catch (SQLException exception) {20 LOG.warn("Unable to execute query : " + exception.toString());21 } finally {22 resultSet.close();23 }24 } catch (SQLException exception) {25 LOG.warn("Unable to execute query : " + exception.toString());26 } finally {27 this.databaseSpring.closeConnection(connection);28 }29 return result;30 }31 public List<TestCaseCountryProperties> findTestCaseCountryPropertiesByTestTestCaseCountry(String test, String testCase, String country) {32 List<TestCaseCountryProperties> result = new ArrayList<TestCaseCountryProperties>();33 final String query = "SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ? AND country = ? ORDER BY test, testcase, country, property";34 Connection connection = this.databaseSpring.connect();35 try {36 PreparedStatement preStat = connection.prepareStatement(query);37 preStat.setString(1, test);38 preStat.setString(2, testCase);39 preStat.setString(3, country);40 ResultSet resultSet = preStat.executeQuery();41 try {

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