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

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

Source:TestDataLibDataDAO.java Github

copy

Full Screen

...74 try {75 ResultSet resultSet = preStat.executeQuery();76 try {77 if (resultSet.first()) {78 result = this.loadFromResultSet(resultSet);79 } else {80 //specific message for gefromdatalib81 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);82 }83 } catch (SQLException exception) {84 LOG.error("Unable to execute query : " + exception.toString());85 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);86 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));87 } finally {88 if (resultSet != null) {89 resultSet.close();90 }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 if (preStat != null) {98 preStat.close();99 }100 }101 } catch (SQLException exception) {102 LOG.error("Unable to execute query : " + exception.toString());103 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);104 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));105 } finally {106 try {107 if (!this.databaseSpring.isOnTransaction()) {108 if (connection != null) {109 connection.close();110 }111 }112 } catch (SQLException ex) {113 LOG.warn("Unable to close connection : " + ex.toString());114 }115 }116 answer.setResultMessage(msg);117 answer.setItem(result);118 return answer;119 }120 @Override121 public AnswerItem<TestDataLibData> readByKeyTech(Integer testDataLibDataID) {122 AnswerItem<TestDataLibData> answer = new AnswerItem<>();123 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);124 TestDataLibData result = null;125 final String query = "SELECT * FROM testdatalibdata where `testdatalibdataid`=? ";126 // Debug message on SQL.127 if (LOG.isDebugEnabled()) {128 LOG.debug("SQL : " + query);129 LOG.debug("SQL.param.testDataLibDataID : " + testDataLibDataID);130 }131 Connection connection = this.databaseSpring.connect();132 try {133 PreparedStatement preStat = connection.prepareStatement(query);134 preStat.setInt(1, testDataLibDataID);135 try {136 ResultSet resultSet = preStat.executeQuery();137 try {138 if (resultSet.first()) {139 result = this.loadFromResultSet(resultSet);140 } else {141 //specific message for gefromdatalib142 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);143 }144 } catch (SQLException exception) {145 LOG.error("Unable to execute query : " + exception.toString());146 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);147 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));148 } finally {149 if (resultSet != null) {150 resultSet.close();151 }152 }153 } catch (SQLException exception) {154 LOG.error("Unable to execute query : " + exception.toString());155 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);156 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));157 } finally {158 if (preStat != null) {159 preStat.close();160 }161 }162 } catch (SQLException exception) {163 LOG.error("Unable to execute query : " + exception.toString());164 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);165 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));166 } finally {167 try {168 if (!this.databaseSpring.isOnTransaction()) {169 if (connection != null) {170 connection.close();171 }172 }173 } catch (SQLException ex) {174 LOG.warn("Unable to close connection : " + ex.toString());175 }176 }177 answer.setResultMessage(msg);178 answer.setItem(result);179 return answer;180 }181 @Override182 public AnswerList<TestDataLibData> readByVarious(Integer testDataLibID, String columnEmpty, String parsingAnswerEmpty, String columnPositionEmpty) {183 List<TestDataLibData> testDataLibListData = new ArrayList<>();184 AnswerList<TestDataLibData> answer = new AnswerList<>();185 MessageEvent msg;186 StringBuilder query = new StringBuilder();187 query.append("SELECT * FROM testdatalibdata where `testDataLibID` = ? ");188 if ("Y".equalsIgnoreCase(columnEmpty)) {189 query.append(" and `Column`='' ");190 } else if ("N".equalsIgnoreCase(columnEmpty)) {191 query.append(" and `Column`!='' ");192 }193 if ("Y".equalsIgnoreCase(parsingAnswerEmpty)) {194 query.append(" and `ParsingAnswer`='' ");195 } else if ("N".equalsIgnoreCase(parsingAnswerEmpty)) {196 query.append(" and `ParsingAnswer`!='' ");197 }198 if ("Y".equalsIgnoreCase(columnPositionEmpty)) {199 query.append(" and `columnPosition`='' ");200 } else if ("N".equalsIgnoreCase(columnPositionEmpty)) {201 query.append(" and `columnPosition`!='' ");202 }203 // Debug message on SQL.204 if (LOG.isDebugEnabled()) {205 LOG.debug("SQL : " + query);206 LOG.debug("SQL.param.testDataLibID : " + testDataLibID);207 }208 Connection connection = this.databaseSpring.connect();209 try {210 PreparedStatement preStat = connection.prepareStatement(query.toString());211 preStat.setInt(1, testDataLibID);212 try {213 ResultSet resultSet = preStat.executeQuery();214 try {215 while (resultSet.next()) {216 testDataLibListData.add(this.loadFromResultSet(resultSet));217 }218 if (testDataLibListData.isEmpty()) {219 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);220 } else {221 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);222 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));223 }224 } catch (SQLException exception) {225 LOG.error("Unable to execute query : " + exception.toString());226 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);227 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));228 testDataLibListData.clear();229 } finally {230 if (resultSet != null) {231 resultSet.close();232 }233 }234 } catch (SQLException exception) {235 LOG.error("Unable to execute query : " + exception.toString());236 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);237 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));238 testDataLibListData.clear();239 } finally {240 if (preStat != null) {241 preStat.close();242 }243 }244 } catch (SQLException exception) {245 LOG.error("Unable to execute query : " + exception.toString());246 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);247 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));248 testDataLibListData.clear();249 } finally {250 try {251 if (!this.databaseSpring.isOnTransaction()) {252 if (connection != null) {253 connection.close();254 }255 }256 } catch (SQLException ex) {257 LOG.warn("Unable to close connection : " + ex.toString());258 }259 }260 answer.setDataList(testDataLibListData);261 answer.setTotalRows(testDataLibListData.size());262 answer.setResultMessage(msg);263 return answer;264 }265 @Override266 public AnswerList<TestDataLibData> readAll() {267 AnswerList<TestDataLibData> answerList = new AnswerList<>();268 List<TestDataLibData> list = new ArrayList<>();269 MessageEvent msg;270 final String query = "SELECT * FROM testdatalibdata";271 // Debug message on SQL.272 if (LOG.isDebugEnabled()) {273 LOG.debug("SQL : " + query);274 }275 Connection connection = this.databaseSpring.connect();276 try {277 PreparedStatement preStat = connection.prepareStatement(query);278 try {279 ResultSet resultSet = preStat.executeQuery();280 try {281 while (resultSet.next()) {282 list.add(this.loadFromResultSet(resultSet));283 }284 if (list.isEmpty()) {285 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);286 } else {287 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);288 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));289 }290 } catch (SQLException exception) {291 LOG.error("Unable to execute query : " + exception.toString());292 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);293 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));294 list.clear();295 } finally {296 if (resultSet != null) {297 resultSet.close();298 }299 }300 } catch (SQLException exception) {301 LOG.error("Unable to execute query : " + exception.toString());302 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);303 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));304 list.clear();305 } finally {306 if (preStat != null) {307 preStat.close();308 }309 }310 } catch (SQLException exception) {311 LOG.error("Unable to execute query : " + exception.toString());312 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);313 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));314 list.clear();315 } finally {316 try {317 if (!this.databaseSpring.isOnTransaction()) {318 if (connection != null) {319 connection.close();320 }321 }322 } catch (SQLException ex) {323 LOG.warn("Unable to close connection : " + ex.toString());324 }325 }326 answerList.setDataList(list);327 answerList.setTotalRows(list.size());328 answerList.setResultMessage(msg);329 return answerList;330 }331 @Override332 public AnswerList<TestDataLibData> readByCriteria(int start, int amount, String colName, String dir, String searchTerm, String individualSearch) {333 AnswerList<TestDataLibData> answer = new AnswerList<>();334 MessageEvent msg;335 int nrTotalRows = 0;336 List<TestDataLibData> testDataLibListData = new ArrayList<>();337 StringBuilder gSearch = new StringBuilder();338 StringBuilder searchSQL = new StringBuilder();339 StringBuilder query = new StringBuilder();340 //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that 341 //were applied -- used for pagination p342 query.append("SELECT SQL_CALC_FOUND_ROWS * FROM testdatalibdata ");343 gSearch.append(" where (`subdata` like '%");344 gSearch.append(searchTerm);345 gSearch.append("%'");346 gSearch.append(" or `value` like '%");347 gSearch.append(searchTerm);348 gSearch.append("%'");349 gSearch.append(" or `column` like '%");350 gSearch.append(searchTerm);351 gSearch.append("%'");352 gSearch.append(" or `parsinganswer` like '%");353 gSearch.append(searchTerm);354 gSearch.append("%'");355 gSearch.append(" or `columnPosition` like '%");356 gSearch.append(searchTerm);357 gSearch.append("%'");358 gSearch.append(" or `description` like '%");359 gSearch.append("%') ");360 if (!searchTerm.equals("") && !individualSearch.equals("")) {361 searchSQL.append(gSearch.toString());362 searchSQL.append(" and ");363 searchSQL.append(individualSearch);364 } else if (!individualSearch.equals("")) {365 searchSQL.append(" where `");366 searchSQL.append(individualSearch);367 searchSQL.append("`");368 } else if (!searchTerm.equals("")) {369 searchSQL.append(gSearch.toString());370 }371 query.append(searchSQL);372 query.append("order by `");373 query.append(colName);374 query.append("` ");375 query.append(dir);376 if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {377 query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);378 } else {379 query.append(" limit ").append(start).append(" , ").append(amount).append(" ");380 }381 // Debug message on SQL.382 if (LOG.isDebugEnabled()) {383 LOG.debug("SQL : " + query);384 }385 Connection connection = this.databaseSpring.connect();386 try {387 PreparedStatement preStat = connection.prepareStatement(query.toString());388 try {389 ResultSet resultSet = preStat.executeQuery();390 try {391 //gets the data392 while (resultSet.next()) {393 testDataLibListData.add(this.loadFromResultSet(resultSet));394 }395 //get the total number of rows396 resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");397 if (resultSet != null && resultSet.next()) {398 nrTotalRows = resultSet.getInt(1);399 }400 if (testDataLibListData.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.401 LOG.warn("Partial Result in the query.");402 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);403 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));404 } else if (testDataLibListData.isEmpty()) {405 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);406 } else {407 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);408 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));409 }410 } catch (SQLException exception) {411 LOG.error("Unable to execute query : " + exception.toString());412 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);413 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));414 testDataLibListData.clear();415 } finally {416 if (resultSet != null) {417 resultSet.close();418 }419 }420 } catch (SQLException exception) {421 LOG.error("Unable to execute query : " + exception.toString());422 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);423 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));424 } finally {425 if (preStat != null) {426 preStat.close();427 }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 (!this.databaseSpring.isOnTransaction()) {436 if (connection != null) {437 connection.close();438 }439 }440 } catch (SQLException ex) {441 LOG.warn("Unable to close connection : " + ex.toString());442 }443 }444 answer.setTotalRows(nrTotalRows);445 answer.setResultMessage(msg);446 answer.setDataList(testDataLibListData);447 return answer;448 }449 @Override450 public AnswerList<TestDataLibData> readByName(String testDataLibName) {451 AnswerList<TestDataLibData> answer = new AnswerList<>();452 MessageEvent msg;453 List<TestDataLibData> testDataLibListData = new ArrayList<>();454 StringBuilder query = new StringBuilder();455 query.append("SELECT tdld.*, tdl.`name`, tdl.type, tdl.system, tdl.country, tdl.environment FROM testdatalibdata tdld ");456 query.append("inner join testdatalib tdl ");457 query.append("on tdld.testDataLibID = tdl.testDataLibID ");458 query.append("and tdl.`name` LIKE ? ");459 // Debug message on SQL.460 if (LOG.isDebugEnabled()) {461 LOG.debug("SQL : " + query);462 LOG.debug("SQL.param.testDataLibName : " + testDataLibName);463 }464 Connection connection = this.databaseSpring.connect();465 try {466 PreparedStatement preStat = connection.prepareStatement(query.toString());467 preStat.setString(1, testDataLibName);468 try {469 ResultSet resultSet = preStat.executeQuery();470 try {471 while (resultSet.next()) {472 testDataLibListData.add(this.loadFromResultSet(resultSet));473 }474 if (testDataLibListData.isEmpty()) {475 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);476 } else {477 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);478 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));479 }480 } catch (SQLException exception) {481 LOG.error("Unable to execute query : " + exception.toString());482 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);483 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));484 } finally {485 if (resultSet != null) {486 resultSet.close();487 }488 }489 } catch (SQLException exception) {490 LOG.error("Unable to execute query : " + exception.toString());491 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);492 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));493 } finally {494 if (preStat != null) {495 preStat.close();496 }497 }498 } catch (SQLException exception) {499 LOG.error("Unable to execute query : " + exception.toString());500 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);501 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));502 } finally {503 try {504 if (!this.databaseSpring.isOnTransaction()) {505 if (connection != null) {506 connection.close();507 }508 }509 } catch (SQLException ex) {510 LOG.warn("Unable to close connection : " + ex.toString());511 }512 }513 answer.setResultMessage(msg);514 answer.setDataList(testDataLibListData);515 answer.setTotalRows(testDataLibListData.size()); //all lines are retrieved 516 return answer;517 }518 @Override519 public Answer create(TestDataLibData object) {520 MessageEvent msg = null;521 StringBuilder query = new StringBuilder();522 query.append("INSERT INTO testdatalibdata (`TestDataLibID`, `subData`, `encrypt`, `value`, `column`, `parsinganswer`, `columnPosition`,`description`) ");523 query.append("VALUES (?,?,?,?,?,?,?,?)");524 // Debug message on SQL.525 if (LOG.isDebugEnabled()) {526 LOG.debug("SQL : " + query.toString());527 LOG.debug("SQL.param.TestDataLibID : " + object.getTestDataLibID());528 }529 Connection connection = this.databaseSpring.connect();530 try {531 PreparedStatement preStat = connection.prepareStatement(query.toString());532 try {533 int i = 1;534 preStat.setInt(i++, object.getTestDataLibID());535 preStat.setString(i++, ParameterParserUtil.returnEmptyStringIfNull(object.getSubData()));536 preStat.setString(i++, ParameterParserUtil.returnEmptyStringIfNull(object.getEncrypt()));537 preStat.setString(i++, "Y".equals(object.getEncrypt()) ? EncryptionService.encrypt(ParameterParserUtil.returnEmptyStringIfNull(object.getValue())) : ParameterParserUtil.returnEmptyStringIfNull(object.getValue()));538 preStat.setString(i++, ParameterParserUtil.returnEmptyStringIfNull(object.getColumn()));539 preStat.setString(i++, ParameterParserUtil.returnEmptyStringIfNull(object.getParsingAnswer()));540 preStat.setString(i++, ParameterParserUtil.returnEmptyStringIfNull(object.getColumnPosition()));541 preStat.setString(i++, ParameterParserUtil.returnEmptyStringIfNull(object.getDescription()));542 preStat.executeUpdate();543 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);544 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));545 } catch (SQLException exception) {546 LOG.error("Unable to execute query : " + exception.toString());547 if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) { //23000 is the sql state for duplicate entries548 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);549 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));550 } else {551 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);552 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));553 }554 } finally {555 preStat.close();556 }557 } catch (SQLException exception) {558 LOG.error("Unable to execute query : " + exception.toString());559 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);560 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));561 } finally {562 try {563 if (connection != null) {564 connection.close();565 }566 } catch (SQLException exception) {567 LOG.error("Unable to close connection : " + exception.toString());568 }569 }570 return new Answer(msg);571 }572 @Override573 public Answer update(TestDataLibData object) {574 MessageEvent msg = null;575 final String query = "UPDATE testdatalibdata SET `encrypt`= ?, `value`= ? , `column`= ? , `parsinganswer`= ? , `columnPosition`= ? , `description`= ? WHERE `testdatalibdataid`= ? ";576 // Debug message on SQL.577 if (LOG.isDebugEnabled()) {578 LOG.debug("SQL : " + query);579 }580 Connection connection = this.databaseSpring.connect();581 try {582 PreparedStatement preStat = connection.prepareStatement(query);583 try {584 int i = 1;585 preStat.setString(i++, object.getEncrypt());586 preStat.setString(i++, "Y".equals(object.getEncrypt()) ? EncryptionService.encrypt(object.getValue()) : object.getValue());587 preStat.setString(i++, object.getColumn());588 preStat.setString(i++, object.getParsingAnswer());589 preStat.setString(i++, object.getColumnPosition());590 preStat.setString(i++, object.getDescription());591 preStat.setInt(i++, object.getTestDataLibDataID());592 preStat.executeUpdate();593 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);594 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));595 } catch (SQLException exception) {596 LOG.error("Unable to execute query : " + exception.toString());597 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);598 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));599 } finally {600 preStat.close();601 }602 } catch (SQLException exception) {603 LOG.error("Unable to execute query : " + exception.toString());604 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);605 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));606 } finally {607 try {608 if (connection != null) {609 connection.close();610 }611 } catch (SQLException exception) {612 LOG.warn("Unable to close connection : " + exception.toString());613 }614 }615 return new Answer(msg);616 }617 @Override618 public Answer delete(TestDataLibData object) {619 MessageEvent msg = null;620 final String query = "DELETE FROM testdatalibdata WHERE `testdatalibdataid`= ? ";621 // Debug message on SQL.622 if (LOG.isDebugEnabled()) {623 LOG.debug("SQL : " + query.toString());624 LOG.debug("SQL.param.TestDataLibDataID : " + object.getTestDataLibDataID());625 }626 Connection connection = this.databaseSpring.connect();627 try {628 PreparedStatement preStat = connection.prepareStatement(query);629 try {630 preStat.setInt(1, object.getTestDataLibDataID());631 preStat.executeUpdate();632 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);633 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "DELETE"));634 } catch (SQLException exception) {635 LOG.error("Unable to execute query : " + exception.toString());636 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);637 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));638 } finally {639 preStat.close();640 }641 } catch (SQLException exception) {642 LOG.error("Unable to execute query : " + exception.toString());643 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);644 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));645 } finally {646 try {647 if (connection != null) {648 connection.close();649 }650 } catch (SQLException exception) {651 LOG.warn("Unable to close connection : " + exception.toString());652 }653 }654 return new Answer(msg);655 }656 private TestDataLibData loadFromResultSet(ResultSet resultSet) throws SQLException {657 Integer testDataLibDataID = resultSet.getInt("TestDataLibDataID");658 Integer testDataLibID = resultSet.getInt("TestDataLibID");659 String subData = resultSet.getString("SubData");660 String encrypt = resultSet.getString("Encrypt");661 String value = "Y".equals(encrypt) ? 662 EncryptionService.decrypt(ParameterParserUtil.returnEmptyStringIfNull(resultSet.getString("Value"))) : 663 ParameterParserUtil.returnEmptyStringIfNull(resultSet.getString("Value"));664 String column = ParameterParserUtil.returnEmptyStringIfNull(resultSet.getString("Column"));665 String parsingAnswer = ParameterParserUtil.returnEmptyStringIfNull(resultSet.getString("ParsingAnswer"));666 String columnPosition = ParameterParserUtil.returnEmptyStringIfNull(resultSet.getString("columnPosition"));667 String description = resultSet.getString("Description");668 return factoryTestDataLibData.create(testDataLibDataID, testDataLibID, subData, encrypt, value, column, parsingAnswer, columnPosition, description);669 }670}...

Full Screen

Full Screen

loadFromResultSet

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestDataLibData;2import org.cerberus.crud.dao.ITestDataLibDataDAO;3import org.cerberus.crud.dao.impl.TestDataLibDataDAO;4import org.cerberus.crud.factory.IFactoryTestDataLibData;5import org.cerberus.crud.factory.impl.FactoryTestDataLibData;6import org.cerberus.util.SqlUtil;7import java.sql.ResultSet;8import java.sql.SQLException;9import java.sql.Statement;10import java.util.logging.Level;11import java.util.logging.Logger;12import org.cerberus.crud.entity.TestDataLib;13import org.cerberus.crud.factory.IFactoryTestDataLib;14import org.cerberus.crud.factory.impl.FactoryTestDataLib;15IFactoryTestDataLibData factoryTestDataLibData = new FactoryTestDataLibData();16ITestDataLibDataDAO testDataLibDataDAO = new TestDataLibDataDAO();17TestDataLib testDataLib = new TestDataLib();18testDataLib.setSubData("SELECT * FROM mytable");19Statement statement = databaseConnection.createStatement();20ResultSet resultSet = statement.executeQuery(testDataLib.getSubData());21TestDataLibData testDataLibData = factoryTestDataLibData.create("","",1,"",testDataLib.getSubData());22testDataLibDataDAO.loadFromResultSet(testDataLibData, resultSet);23statement.close();24resultSet.close();25System.out.println(testDataLibData.getValue1());26databaseConnection.close();

Full Screen

Full Screen

loadFromResultSet

Using AI Code Generation

copy

Full Screen

1package org.cerberus.crud.dao.impl;2import java.sql.ResultSet;3import java.sql.SQLException;4import java.util.HashMap;5import java.util.Map;6import org.cerberus.crud.entity.TestDataLibData;7import org.springframework.jdbc.core.RowMapper;8public class TestDataLibDataDAO implements RowMapper<Map<Integer, TestDataLibData>> {9 public Map<Integer, TestDataLibData> mapRow(ResultSet rs, int i) throws SQLException {10 Map<Integer, TestDataLibData> map = new HashMap<Integer, TestDataLibData>();11 do {12 TestDataLibData testDataLibData = new TestDataLibData();13 testDataLibData.setTestDataLibDataID(rs.getInt("TestDataLibDataID"));14 testDataLibData.setTestDataLibID(rs.getInt("TestDataLibID"));15 testDataLibData.setSubData(rs.getString("SubData"));16 testDataLibData.setColumn(rs.getString("Column"));17 testDataLibData.setValue(rs.getString("Value"));18 testDataLibData.setSort(rs.getInt("Sort"));19 testDataLibData.setNature(rs.getString("Nature"));20 testDataLibData.setDescription(rs.getString("Description"));21 testDataLibData.setEncoding(rs.getString("Encoding"));22 testDataLibData.setRowLimit(rs.getInt("RowLimit"));23 testDataLibData.setCountry(rs.getString("Country"));24 testDataLibData.setDatabase(rs.getString("Database"));25 testDataLibData.setServicePath(rs.getString("ServicePath"));26 testDataLibData.setMethod(rs.getString("Method"));27 testDataLibData.setEnvelope(rs.getString("Envelope"));28 testDataLibData.setDatabaseUrl(rs.getString("DatabaseUrl"));29 testDataLibData.setDatabaseScript(rs.getString("DatabaseScript"));30 testDataLibData.setDatabaseCsv(rs.getString("DatabaseCsv"));31 testDataLibData.setDatabaseXml(rs.getString("DatabaseXml"));32 testDataLibData.setDatabaseJson(rs.getString("DatabaseJson"));33 testDataLibData.setServicePathUrl(rs.getString("ServicePathUrl"));34 testDataLibData.setServicePathCsv(rs.getString("ServicePathCsv"));35 testDataLibData.setServicePathXml(rs.getString("ServicePathXml"));36 testDataLibData.setServicePathJson(rs.getString("ServicePathJson"));37 testDataLibData.setServicePathService(rs.getString("ServicePathService"));

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.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful