How to use loadFromResultSetWithSystem1 method of org.cerberus.crud.dao.impl.ParameterDAO class

Best Cerberus-source code snippet using org.cerberus.crud.dao.impl.ParameterDAO.loadFromResultSetWithSystem1

Source:ParameterDAO.java Github

copy

Full Screen

...362 ResultSet resultSet = preStat.executeQuery();363 try {364 //gets the data365 while (resultSet.next()) {366 objectList.add(this.loadFromResultSetWithSystem1(resultSet));367 }368 //get the total number of rows369 resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");370 int nrTotalRows = 0;371 if (resultSet != null && resultSet.next()) {372 nrTotalRows = resultSet.getInt(1);373 }374 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.375 LOG.error("Partial Result in the query.");376 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);377 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));378 response = new AnswerList(objectList, nrTotalRows);379 } else if (objectList.size() <= 0) {380 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);381 response = new AnswerList(objectList, nrTotalRows);382 } else {383 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);384 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));385 response = new AnswerList(objectList, nrTotalRows);386 }387 } catch (SQLException exception) {388 LOG.error("Unable to execute query : " + exception.toString());389 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);390 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));391 } finally {392 if (resultSet != null) {393 resultSet.close();394 }395 }396 } catch (SQLException exception) {397 LOG.error("Unable to execute query : " + exception.toString());398 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);399 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));400 } finally {401 if (preStat != null) {402 preStat.close();403 }404 }405 } catch (SQLException exception) {406 LOG.error("Unable to execute query : " + exception.toString());407 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);408 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));409 } finally {410 try {411 if (!this.databaseSpring.isOnTransaction()) {412 if (connection != null) {413 connection.close();414 }415 }416 } catch (SQLException exception) {417 LOG.warn("Unable to close connection : " + exception.toString());418 }419 }420 response.setResultMessage(msg);421 response.setDataList(objectList);422 return response;423 }424 @Override425 public AnswerItem readWithSystem1ByKey(String system, String key, String system1) {426 AnswerItem a = new AnswerItem();427 StringBuilder query = new StringBuilder();428 Parameter p = new Parameter();429 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);430 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));431 query.append("SELECT par.param, par.`value`, par.description, ? system1, par1.`value` system1value FROM parameter par "432 + "LEFT OUTER JOIN (SELECT * FROM parameter WHERE system = ? and param = ?) as par1 ON par.param = par1.param WHERE par.system = ? AND par.param = ?");433 // Debug message on SQL.434 if (LOG.isDebugEnabled()) {435 LOG.debug("SQL : " + query);436 LOG.debug("SQL.param.system1 : " + system1);437 LOG.debug("SQL.param.system : " + system);438 LOG.debug("SQL.param.key : " + key);439 }440 441 try(Connection connection = this.databaseSpring.connect();442 PreparedStatement preStat = connection.prepareStatement(query.toString());) {443 444 preStat.setString(1, system1);445 preStat.setString(2, system1);446 preStat.setString(3, key);447 preStat.setString(4, system);448 preStat.setString(5, key);449 450 try(ResultSet resultSet = preStat.executeQuery();){451 //gets the data452 while (resultSet.next()) {453 p = this.loadFromResultSetWithSystem1(resultSet);454 }455 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);456 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));457 }catch (SQLException exception) {458 LOG.error("Unable to execute query : " + exception.toString());459 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);460 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));461 } 462 } catch (SQLException e) {463 LOG.error("Unable to execute query : " + e.toString());464 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);465 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", e.toString()));466 }467 a.setResultMessage(msg);468 a.setItem(p);469 return a;470 }471 @Override472 public Parameter loadFromResultSetWithSystem1(ResultSet rs) throws SQLException {473 String param = ParameterParserUtil.parseStringParam(rs.getString("par.param"), "");474 String value = ParameterParserUtil.parseStringParam(rs.getString("par.value"), "");475 String description = ParameterParserUtil.parseStringParam(rs.getString("par.description"), "");476 String system1 = ParameterParserUtil.parseStringParam(rs.getString("system1"), "");477 String system1Value = ParameterParserUtil.parseStringParam(rs.getString("system1Value"), "");478 //TODO remove when working in test with mockito and autowired479 factoryParameter = new FactoryParameter();480 return factoryParameter.create("", param, value, description, system1, system1Value);481 }482 @Override483 public Parameter loadFromResultSet(ResultSet rs) throws SQLException {484 String system = ParameterParserUtil.parseStringParam(rs.getString("system"), "");485 String param = ParameterParserUtil.parseStringParam(rs.getString("param"), "");486 String value = ParameterParserUtil.parseStringParam(rs.getString("value"), "");...

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