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

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

Source:SqlLibraryDAO.java Github

copy

Full Screen

...525 ResultSet resultSet = preStat.executeQuery();526 try {527 //gets the data528 while (resultSet.next()) {529 objectList.add(this.loadFromResultSet(resultSet));530 }531 //get the total number of rows532 resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");533 int nrTotalRows = 0;534 if (resultSet != null && resultSet.next()) {535 nrTotalRows = resultSet.getInt(1);536 }537 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.538 LOG.error("Partial Result in the query.");539 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);540 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));541 response = new AnswerList(objectList, nrTotalRows);542 } else if (objectList.size() <= 0) {543 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);544 response = new AnswerList(objectList, nrTotalRows);545 } else {546 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);547 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));548 response = new AnswerList(objectList, nrTotalRows);549 }550 } catch (SQLException exception) {551 LOG.error("Unable to execute query : " + exception.toString());552 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);553 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));554 } finally {555 if (resultSet != null) {556 resultSet.close();557 }558 }559 } catch (SQLException exception) {560 LOG.error("Unable to execute query : " + exception.toString());561 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);562 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));563 } finally {564 if (preStat != null) {565 preStat.close();566 }567 }568 } catch (SQLException exception) {569 LOG.error("Unable to execute query : " + exception.toString());570 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);571 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));572 } finally {573 try {574 if (!this.databaseSpring.isOnTransaction()) {575 if (connection != null) {576 connection.close();577 }578 }579 } catch (SQLException exception) {580 LOG.warn("Unable to close connection : " + exception.toString());581 }582 }583 response.setResultMessage(msg);584 response.setDataList(objectList);585 return response;586 }587 @Override588 public AnswerItem readByKey(String key) {589 AnswerItem a = new AnswerItem();590 StringBuilder query = new StringBuilder();591 SqlLibrary p = new SqlLibrary();592 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);593 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));594 query.append("SELECT * FROM sqllibrary `sql` WHERE Name = ?");595 596 try(Connection connection = this.databaseSpring.connect();597 PreparedStatement preStat = connection.prepareStatement(query.toString());) {598 preStat.setString(1, key);599 try(ResultSet resultSet = preStat.executeQuery()){600 //gets the data601 while (resultSet.next()) {602 p = this.loadFromResultSet(resultSet);603 }604 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);605 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));606 }catch (SQLException e) {607 LOG.error("Unable to execute query : " + e.toString());608 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);609 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", e.toString()));610 }611 } catch (SQLException e) {612 LOG.error("Unable to execute query : " + e.toString());613 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);614 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", e.toString()));615 } 616 a.setResultMessage(msg);617 a.setItem(p);618 return a;619 }620 @Override621 public SqlLibrary loadFromResultSet(ResultSet rs) throws SQLException {622 String name = ParameterParserUtil.parseStringParam(rs.getString("Name"), "");623 String type = ParameterParserUtil.parseStringParam(rs.getString("Type"), "");624 String db = ParameterParserUtil.parseStringParam(rs.getString("Database"), "");625 String script = ParameterParserUtil.parseStringParam(rs.getString("Script"), "");626 String description = ParameterParserUtil.parseStringParam(rs.getString("Description"), "");627 //TODO remove when working in test with mockito and autowired628 factorySqlLib = new FactorySqlLibrary();629 return factorySqlLib.create(name, type, db, script, description);630 }631 @Override632 public AnswerList<String> readDistinctValuesByCriteria(String searchTerm, Map<String, List<String>> individualSearch, String columnName) {633 AnswerList answer = new AnswerList();634 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);635 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));...

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