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

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

Source:BuildRevisionParametersDAO.java Github

copy

Full Screen

...67 preStat.setInt(1, id);68 ResultSet resultSet = preStat.executeQuery();69 try {70 if (resultSet.first()) {71 result = loadFromResultSet(resultSet);72 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);73 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));74 ans.setItem(result);75 } else {76 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);77 }78 } catch (SQLException exception) {79 LOG.error("Unable to execute query : " + exception.toString());80 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);81 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));82 } finally {83 resultSet.close();84 }85 } catch (SQLException exception) {86 LOG.error("Unable to execute query : " + exception.toString());87 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);88 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));89 } finally {90 preStat.close();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 try {98 if (connection != null) {99 connection.close();100 }101 } catch (SQLException exception) {102 LOG.warn("Unable to close connection : " + exception.toString());103 }104 }105 //sets the message106 ans.setResultMessage(msg);107 return ans;108 }109 @Override110 public AnswerItem<BuildRevisionParameters> readLastBySystem(String system) {111 AnswerItem<BuildRevisionParameters> ans = new AnswerItem<>();112 BuildRevisionParameters result = null;113 StringBuilder query = new StringBuilder();114 query.append("SELECT * from buildrevisionparameters brp ");115 query.append(" left outer join buildrevisioninvariant bri1 on brp.build = bri1.versionname and bri1.level=1 and bri1.`System` = ? ");116 query.append(" left outer join buildrevisioninvariant bri2 on brp.revision = bri2.versionname and bri2.level=2 and bri2.`System` = ? ");117 query.append("WHERE 1=1 ");118 query.append(" and application in (SELECT application FROM application WHERE `System` = ? ) ");119 query.append("ORDER BY bri1.seq desc, bri2.seq desc, brp.datecre desc limit 1; ");120 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);121 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));122 // Debug message on SQL.123 if (LOG.isDebugEnabled()) {124 LOG.debug("SQL : " + query.toString());125 }126 Connection connection = this.databaseSpring.connect();127 try {128 PreparedStatement preStat = connection.prepareStatement(query.toString());129 try {130 int i = 1;131 preStat.setString(i++, system);132 preStat.setString(i++, system);133 preStat.setString(i++, system);134 ResultSet resultSet = preStat.executeQuery();135 try {136 if (resultSet.first()) {137 result = loadFromResultSet(resultSet);138 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);139 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT LAST"));140 ans.setItem(result);141 } else {142 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 resultSet.close();150 }151 } catch (SQLException exception) {152 LOG.error("Unable to execute query : " + exception.toString());153 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);154 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));155 } finally {156 preStat.close();157 }158 } catch (SQLException exception) {159 LOG.error("Unable to execute query : " + exception.toString());160 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);161 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));162 } finally {163 try {164 if (connection != null) {165 connection.close();166 }167 } catch (SQLException exception) {168 LOG.warn("Unable to close connection : " + exception.toString());169 }170 }171 //sets the message172 ans.setResultMessage(msg);173 return ans;174 }175 @Override176 public AnswerItem<BuildRevisionParameters> readByVarious2(String build, String revision, String release, String application) {177 AnswerItem<BuildRevisionParameters> ans = new AnswerItem<>();178 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);179 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));180 BuildRevisionParameters result = null;181 StringBuilder query = new StringBuilder();182 query.append("Select * FROM buildrevisionparameters ");183 query.append(" WHERE build= ? and revision= ? and `release` = ? and application = ? ");184 Connection connection = this.databaseSpring.connect();185 try {186 PreparedStatement preStat = connection.prepareStatement(query.toString());187 try {188 preStat.setString(1, build);189 preStat.setString(2, revision);190 preStat.setString(3, release);191 preStat.setString(4, application);192 ResultSet resultSet = preStat.executeQuery();193 try {194 //gets the data195 if (resultSet.first()) {196 result = loadFromResultSet(resultSet);197 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);198 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));199 ans.setItem(result);200 } else {201 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);202 }203 } catch (SQLException exception) {204 LOG.error("Unable to execute query : " + exception.toString());205 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);206 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));207 } finally {208 resultSet.close();209 }210 } catch (SQLException exception) {211 LOG.error("Unable to execute query : " + exception.toString());212 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);213 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));214 } finally {215 preStat.close();216 }217 } catch (SQLException exception) {218 LOG.error("Unable to execute query : " + exception.toString());219 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);220 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));221 } finally {222 try {223 if (connection != null) {224 connection.close();225 }226 } catch (SQLException exception) {227 LOG.warn("Unable to close connection : " + exception.toString());228 }229 }230 //sets the message231 ans.setResultMessage(msg);232 return ans;233 }234 @Override235 public AnswerList<BuildRevisionParameters> readByVarious1ByCriteria(String system, String application, String build, String revision, int start, int amount,236 String column, String dir, String searchTerm, Map<String, List<String>> individualSearch) {237 AnswerList<BuildRevisionParameters> response = new AnswerList<>();238 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);239 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));240 List<BuildRevisionParameters> brpList = new ArrayList<>();241 StringBuilder searchSQL = new StringBuilder();242 List<String> individalColumnSearchValues = new ArrayList<>();243 StringBuilder query = new StringBuilder();244 //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that 245 //were applied -- used for pagination p246 query.append("SELECT SQL_CALC_FOUND_ROWS * FROM buildrevisionparameters ");247 searchSQL.append(" where 1=1 ");248 if (!StringUtil.isNullOrEmpty(searchTerm)) {249 searchSQL.append(" and (`id` like ?");250 searchSQL.append(" or `Build` like ?");251 searchSQL.append(" or `Revision` like ?");252 searchSQL.append(" or `Release` like ?");253 searchSQL.append(" or `Application` like ?");254 searchSQL.append(" or `Project` like ?");255 searchSQL.append(" or `TicketIDFixed` like ?");256 searchSQL.append(" or `BugIDFixed` like ?");257 searchSQL.append(" or `Link` like ?");258 searchSQL.append(" or `ReleaseOwner` like ?");259 searchSQL.append(" or `datecre` like ?");260 searchSQL.append(" or `jenkinsbuildid` like ?");261 searchSQL.append(" or `mavengroupid` like ?");262 searchSQL.append(" or `mavenartifactid` like ?");263 searchSQL.append(" or `repositoryurl` like ?");264 searchSQL.append(" or `mavenversion` like ? )");265 }266 if (individualSearch != null && !individualSearch.isEmpty()) {267 searchSQL.append(" and ( 1=1 ");268 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {269 searchSQL.append(" and ");270 searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));271 individalColumnSearchValues.addAll(entry.getValue());272 }273 searchSQL.append(" )");274 }275 if (!StringUtil.isNullOrEmpty(system)) {276 searchSQL.append(" and application in (SELECT application FROM application WHERE `System` = ? )");277 }278 if (!StringUtil.isNullOrEmpty(application)) {279 searchSQL.append(" and (`Application`= ? )");280 }281 if (!StringUtil.isNullOrEmpty(build)) {282 searchSQL.append(" and (`Build`= ? )");283 }284 if (!StringUtil.isNullOrEmpty(revision)) {285 searchSQL.append(" and (`Revision`= ? )");286 }287 query.append(searchSQL);288 if (!StringUtil.isNullOrEmpty(column)) {289 query.append(" order by `").append(column).append("` ").append(dir);290 }291 if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {292 query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);293 } else {294 query.append(" limit ").append(start).append(" , ").append(amount);295 }296 // Debug message on SQL.297 if (LOG.isDebugEnabled()) {298 LOG.debug("SQL : " + query.toString());299 }300 Connection connection = this.databaseSpring.connect();301 try {302 PreparedStatement preStat = connection.prepareStatement(query.toString());303 try {304 int i = 1;305 if (!StringUtil.isNullOrEmpty(searchTerm)) {306 preStat.setString(i++, "%" + searchTerm + "%");307 preStat.setString(i++, "%" + searchTerm + "%");308 preStat.setString(i++, "%" + searchTerm + "%");309 preStat.setString(i++, "%" + searchTerm + "%");310 preStat.setString(i++, "%" + searchTerm + "%");311 preStat.setString(i++, "%" + searchTerm + "%");312 preStat.setString(i++, "%" + searchTerm + "%");313 preStat.setString(i++, "%" + searchTerm + "%");314 preStat.setString(i++, "%" + searchTerm + "%");315 preStat.setString(i++, "%" + searchTerm + "%");316 preStat.setString(i++, "%" + searchTerm + "%");317 preStat.setString(i++, "%" + searchTerm + "%");318 preStat.setString(i++, "%" + searchTerm + "%");319 preStat.setString(i++, "%" + searchTerm + "%");320 preStat.setString(i++, "%" + searchTerm + "%");321 preStat.setString(i++, "%" + searchTerm + "%");322 }323 for (String individualColumnSearchValue : individalColumnSearchValues) {324 preStat.setString(i++, individualColumnSearchValue);325 }326 if (!StringUtil.isNullOrEmpty(system)) {327 preStat.setString(i++, system);328 }329 if (!StringUtil.isNullOrEmpty(application)) {330 preStat.setString(i++, application);331 }332 if (!StringUtil.isNullOrEmpty(build)) {333 preStat.setString(i++, build);334 }335 if (!StringUtil.isNullOrEmpty(revision)) {336 preStat.setString(i++, revision);337 }338 ResultSet resultSet = preStat.executeQuery();339 try {340 //gets the data341 while (resultSet.next()) {342 brpList.add(this.loadFromResultSet(resultSet));343 }344 //get the total number of rows345 resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");346 int nrTotalRows = 0;347 if (resultSet != null && resultSet.next()) {348 nrTotalRows = resultSet.getInt(1);349 }350 if (brpList.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.351 LOG.error("Partial Result in the query.");352 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);353 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));354 response = new AnswerList<>(brpList, nrTotalRows);355 } else if (brpList.size() <= 0) {356 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);357 response = new AnswerList<>(brpList, nrTotalRows);358 } else {359 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);360 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));361 response = new AnswerList<>(brpList, nrTotalRows);362 }363 } catch (SQLException exception) {364 LOG.error("Unable to execute query : " + exception.toString());365 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);366 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));367 } finally {368 if (resultSet != null) {369 resultSet.close();370 }371 }372 } catch (SQLException exception) {373 LOG.error("Unable to execute query : " + exception.toString());374 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);375 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));376 } finally {377 if (preStat != null) {378 preStat.close();379 }380 }381 } catch (SQLException exception) {382 LOG.error("Unable to execute query : " + exception.toString());383 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);384 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));385 } finally {386 try {387 if (!this.databaseSpring.isOnTransaction()) {388 if (connection != null) {389 connection.close();390 }391 }392 } catch (SQLException exception) {393 LOG.warn("Unable to close connection : " + exception.toString());394 }395 }396 response.setResultMessage(msg);397 response.setDataList(brpList);398 return response;399 }400 @Override401 public AnswerList<BuildRevisionParameters> readMaxSVNReleasePerApplication(String system, String build, String revision, String lastBuild, String lastRevision) {402 AnswerList<BuildRevisionParameters> response = new AnswerList<>();403 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);404 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));405 List<BuildRevisionParameters> brpList = new ArrayList<>();406 StringBuilder searchSQL = new StringBuilder();407 StringBuilder query = new StringBuilder();408 //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that 409 //were applied -- used for pagination p410 query.append("SELECT * from ( ");411 query.append("SELECT Application, max(`rel1`) rel FROM (");412 query.append("SELECT brp.Application, CAST(`Release` AS UNSIGNED) rel1 ");413 query.append(" FROM buildrevisionparameters brp ");414 query.append("JOIN application a on a.application = brp.application ");415 query.append("JOIN buildrevisioninvariant bri on bri.versionname = brp.revision and bri.`system` = ? and bri.`level` = 2 ");416 query.append(" WHERE 1=1 ");417 query.append(" and a.`system` = ? ");418 query.append(" and brp.build = ? ");419 if (lastBuild.equalsIgnoreCase(build)) { // If last version is on the same build.420 if (StringUtil.isNullOrEmpty(lastRevision)) { // Same build and revision some we filter only the current content.421 query.append(" and bri.seq = (select seq from buildrevisioninvariant where `system` = ? and `level` = 2 and `versionname` = ? ) "); // revision422 } else { // 2 different revisions inside the same build, we take the content between the 2.423 query.append(" and bri.seq > (select seq from buildrevisioninvariant where `system` = ? and `level` = 2 and `versionname` = ? ) "); // lastRevision424 }425 }426 query.append(" and bri.seq <= (select seq from buildrevisioninvariant where `system` = ? and `level` = 2 and `versionname` = ? )"); // revision427 query.append(" and `release` REGEXP '^-?[0-9]+$' "); // Release needs to be an svn number428 query.append(" and jenkinsbuildid is not null and jenkinsbuildid != '' "); // We need to have a jenkinsBuildID429 query.append(" ORDER BY brp.Application ) as al1 ");430 query.append(" GROUP BY Application ORDER BY Application) as al ");431 query.append("JOIN buildrevisionparameters brp ");432 query.append(" ON brp.application=al.application and brp.release=al.rel and brp.build = ? ");433 query.append(" JOIN application app ");434 query.append(" ON app.application=al.application ");435 query.append("WHERE app.`system` = ? ;");436 // Debug message on SQL.437 if (LOG.isDebugEnabled()) {438 LOG.debug("SQL : " + query.toString());439 LOG.debug("SQL.param.system : " + system);440 LOG.debug("SQL.param.build : " + build);441 LOG.debug("SQL.param.revision : " + revision);442 LOG.debug("SQL.param.lastBuild : " + lastBuild);443 LOG.debug("SQL.param.lastRevision : " + lastRevision);444 }445 Connection connection = this.databaseSpring.connect();446 try {447 PreparedStatement preStat = connection.prepareStatement(query.toString());448 try {449 int i = 1;450 preStat.setString(i++, system);451 preStat.setString(i++, system);452 preStat.setString(i++, build);453 if (lastBuild.equalsIgnoreCase(build)) {454 if (StringUtil.isNullOrEmpty(lastRevision)) { // if lastRevision is not defined, we filter only the current content.455 preStat.setString(i++, system);456 preStat.setString(i++, revision);457 } else { // 2 different revisions inside the same build, we take the content between the 2.458 preStat.setString(i++, system);459 preStat.setString(i++, lastRevision);460 }461 }462 preStat.setString(i++, system);463 preStat.setString(i++, revision);464 preStat.setString(i++, build);465 preStat.setString(i++, system);466 ResultSet resultSet = preStat.executeQuery();467 try {468 //gets the data469 while (resultSet.next()) {470 BuildRevisionParameters brpItem = this.loadFromResultSet(resultSet);471 brpItem.setAppDeployType(resultSet.getString("app.deploytype"));472 brpList.add(brpItem);473 }474 //get the total number of rows475 resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");476 int nrTotalRows = 0;477 if (resultSet != null && resultSet.next()) {478 nrTotalRows = resultSet.getInt(1);479 }480 if (brpList.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.481 LOG.error("Partial Result in the query.");482 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);483 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));484 response = new AnswerList<>(brpList, nrTotalRows);485 } else if (brpList.size() <= 0) {486 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);487 response = new AnswerList<>(brpList, nrTotalRows);488 } else {489 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);490 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));491 response = new AnswerList<>(brpList, nrTotalRows);492 }493 } catch (SQLException exception) {494 LOG.error("Unable to execute query : " + exception.toString());495 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);496 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));497 } finally {498 if (resultSet != null) {499 resultSet.close();500 }501 }502 } catch (SQLException exception) {503 LOG.error("Unable to execute query : " + exception.toString());504 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);505 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));506 } finally {507 if (preStat != null) {508 preStat.close();509 }510 }511 } catch (SQLException exception) {512 LOG.error("Unable to execute query : " + exception.toString());513 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);514 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));515 } finally {516 try {517 if (!this.databaseSpring.isOnTransaction()) {518 if (connection != null) {519 connection.close();520 }521 }522 } catch (SQLException exception) {523 LOG.warn("Unable to close connection : " + exception.toString());524 }525 }526 response.setResultMessage(msg);527 response.setDataList(brpList);528 return response;529 }530 @Override531 public AnswerList<BuildRevisionParameters> readNonSVNRelease(String system, String build, String revision, String lastBuild, String lastRevision) {532 AnswerList<BuildRevisionParameters> response = new AnswerList<>();533 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);534 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));535 List<BuildRevisionParameters> brpList = new ArrayList<>();536 BuildRevisionParameters brpItem = null;537 StringBuilder searchSQL = new StringBuilder();538 StringBuilder query = new StringBuilder();539 //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that 540 //were applied -- used for pagination p541 query.append("SELECT * from ( ");542 query.append("SELECT distinct brp.Application, `Release` rel, link, max(id) maxid ");543 query.append(" FROM buildrevisionparameters brp ");544 query.append("JOIN application a on a.application = brp.application ");545 query.append("JOIN buildrevisioninvariant bri ON bri.versionname = brp.revision and bri.`system` = ? and bri.`level` = 2 ");546 query.append(" WHERE 1=1 ");547 query.append(" and a.`system` = ? ");548 query.append(" and brp.build = ? ");549 if (lastBuild.equalsIgnoreCase(build)) {550 if (StringUtil.isNullOrEmpty(lastRevision)) { // if lastRevision is not defined, we filter only the current content.551 query.append(" and bri.seq = (select seq from buildrevisioninvariant where `system` = ? and `level` = 2 and `versionname` = ? ) "); // revision552 } else { // 2 different revisions inside the same build, we take the content between the 2.553 query.append(" and bri.seq > (select seq from buildrevisioninvariant where `system` = ? and `level` = 2 and `versionname` = ? ) "); // lastRevision554 }555 }556 query.append(" and bri.seq <= (select seq from buildrevisioninvariant where `system` = ? and `level` = 2 and `versionname` = ? )"); // revision557 query.append(" and link is not null and length(trim(link))>0 "); // Release Link for instal instructions needs to exist.558 query.append(" GROUP BY brp.Application, `Release`, link ORDER BY Application, `Release`, link ");559 query.append(") as toto ");560 query.append(" JOIN buildrevisionparameters brp ON brp.id = toto.maxid ");561 query.append(" JOIN buildrevisioninvariant bri1 on bri1.versionname = brp.build and bri1.`system` = ? and bri1.`level` = 1 ");562 query.append(" JOIN buildrevisioninvariant bri2 on bri2.versionname = brp.revision and bri2.`system` = ? and bri2.`level` = 2 ");563 query.append(" JOIN application app ");564 query.append(" ON app.application=toto.application ");565 query.append(" ORDER BY bri1.seq asc , bri2.seq asc , brp.Application asc;");566 // Debug message on SQL.567 if (LOG.isDebugEnabled()) {568 LOG.debug("SQL : " + query.toString());569 LOG.debug("SQL.param.system : " + system);570 LOG.debug("SQL.param.build : " + build);571 LOG.debug("SQL.param.revision : " + revision);572 LOG.debug("SQL.param.lastBuild : " + lastBuild);573 LOG.debug("SQL.param.lastRevision : " + lastRevision);574 }575 Connection connection = this.databaseSpring.connect();576 try {577 PreparedStatement preStat = connection.prepareStatement(query.toString());578 try {579 int i = 1;580 preStat.setString(i++, system);581 preStat.setString(i++, system);582 preStat.setString(i++, build);583 if (lastBuild.equalsIgnoreCase(build)) {584 if (StringUtil.isNullOrEmpty(lastRevision)) { // if lastRevision is not defined, we filter only the current content.585 preStat.setString(i++, system);586 preStat.setString(i++, revision);587 } else { // 2 different revisions inside the same build, we take the content between the 2.588 preStat.setString(i++, system);589 preStat.setString(i++, lastRevision);590 }591 }592 preStat.setString(i++, system);593 preStat.setString(i++, revision);594 preStat.setString(i++, system);595 preStat.setString(i++, system);596 ResultSet resultSet = preStat.executeQuery();597 try {598 //gets the data599 while (resultSet.next()) {600 BuildRevisionParameters newBRP;601 newBRP = factoryBuildRevisionParameters.create(ParameterParserUtil.parseIntegerParam(resultSet.getString("maxid"), 0)602 , ParameterParserUtil.parseStringParam(resultSet.getString("build"), ""), ParameterParserUtil.parseStringParam(resultSet.getString("revision"), "")603 , ParameterParserUtil.parseStringParam(resultSet.getString("rel"), ""), ParameterParserUtil.parseStringParam(resultSet.getString("application"), "")604 , "", "", "", ParameterParserUtil.parseStringParam(resultSet.getString("link"), ""), "", "", null, null, null, null, null, null);605 newBRP.setAppDeployType(ParameterParserUtil.parseStringParam(resultSet.getString("app.deploytype"), ""));606 brpList.add(newBRP);607 }608 //get the total number of rows609 resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");610 int nrTotalRows = 0;611 if (resultSet != null && resultSet.next()) {612 nrTotalRows = resultSet.getInt(1);613 }614 if (brpList.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.615 LOG.error("Partial Result in the query.");616 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);617 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));618 response = new AnswerList<>(brpList, nrTotalRows);619 } else if (brpList.size() <= 0) {620 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);621 response = new AnswerList<>(brpList, nrTotalRows);622 } else {623 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);624 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));625 response = new AnswerList<>(brpList, nrTotalRows);626 }627 } catch (SQLException exception) {628 LOG.error("Unable to execute query : " + exception.toString());629 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);630 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));631 } finally {632 if (resultSet != null) {633 resultSet.close();634 }635 }636 } catch (SQLException exception) {637 LOG.error("Unable to execute query : " + exception.toString());638 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);639 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));640 } finally {641 if (preStat != null) {642 preStat.close();643 }644 }645 } catch (SQLException exception) {646 LOG.error("Unable to execute query : " + exception.toString());647 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);648 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));649 } finally {650 try {651 if (!this.databaseSpring.isOnTransaction()) {652 if (connection != null) {653 connection.close();654 }655 }656 } catch (SQLException exception) {657 LOG.warn("Unable to close connection : " + exception.toString());658 }659 }660 response.setResultMessage(msg);661 response.setDataList(brpList);662 return response;663 }664 @Override665 public Answer create(BuildRevisionParameters brp) {666 MessageEvent msg = null;667 StringBuilder query = new StringBuilder();668 query.append("INSERT INTO buildrevisionparameters (`Build`,`Revision`,`Release`,`Link` , `Application`, `releaseOwner`, `Project`");669 query.append(" , `BugIDFixed`, `TicketIDFixed` , `Subject`, `jenkinsbuildid`, `mavengroupid`, `mavenartifactid`, `mavenversion`, `repositoryurl`) ");670 query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");671 // Debug message on SQL.672 if (LOG.isDebugEnabled()) {673 LOG.debug("SQL : " + query.toString());674 }675 Connection connection = this.databaseSpring.connect();676 try {677 PreparedStatement preStat = connection.prepareStatement(query.toString());678 try {679 preStat.setString(1, brp.getBuild());680 preStat.setString(2, brp.getRevision());681 preStat.setString(3, brp.getRelease());682 preStat.setString(4, brp.getLink());683 preStat.setString(5, brp.getApplication());684 preStat.setString(6, brp.getReleaseOwner());685 preStat.setString(7, brp.getProject());686 preStat.setString(8, brp.getBugIdFixed());687 preStat.setString(9, brp.getTicketIdFixed());688 preStat.setString(10, brp.getSubject());689 preStat.setString(11, brp.getJenkinsBuildId());690 preStat.setString(12, brp.getMavenGroupId());691 preStat.setString(13, brp.getMavenArtifactId());692 preStat.setString(14, brp.getMavenVersion());693 preStat.setString(15, brp.getRepositoryUrl());694 preStat.executeUpdate();695 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);696 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));697 } catch (SQLException exception) {698 LOG.error("Unable to execute query : " + exception.toString());699 if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) { //23000 is the sql state for duplicate entries700 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);701 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));702 } else {703 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);704 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));705 }706 } finally {707 preStat.close();708 }709 } catch (SQLException exception) {710 LOG.error("Unable to execute query : " + exception.toString());711 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);712 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));713 } finally {714 try {715 if (connection != null) {716 connection.close();717 }718 } catch (SQLException exception) {719 LOG.warn("Unable to close connection : " + exception.toString());720 }721 }722 return new Answer(msg);723 }724 @Override725 public Answer delete(BuildRevisionParameters brp) {726 MessageEvent msg = null;727 final String query = "DELETE FROM buildrevisionparameters WHERE id = ?";728 // Debug message on SQL.729 if (LOG.isDebugEnabled()) {730 LOG.debug("SQL : " + query);731 }732 Connection connection = this.databaseSpring.connect();733 try {734 PreparedStatement preStat = connection.prepareStatement(query);735 try {736 preStat.setInt(1, brp.getId());737 preStat.executeUpdate();738 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);739 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "DELETE"));740 } catch (SQLException exception) {741 LOG.error("Unable to execute query : " + exception.toString());742 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);743 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));744 } finally {745 preStat.close();746 }747 } catch (SQLException exception) {748 LOG.error("Unable to execute query : " + exception.toString());749 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);750 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));751 } finally {752 try {753 if (connection != null) {754 connection.close();755 }756 } catch (SQLException exception) {757 LOG.warn("Unable to close connection : " + exception.toString());758 }759 }760 return new Answer(msg);761 }762 @Override763 public Answer update(BuildRevisionParameters brp) {764 MessageEvent msg = null;765 final String query = "UPDATE buildrevisionparameters SET `build` = ?, revision = ?, application = ?,"766 + "`release` = ?, project = ?, ticketidfixed = ?, bugidfixed = ?, `subject` = ?, releaseowner = ?,"767 + " link = ?, jenkinsbuildid = ?, mavengroupid = ?, mavenartifactid = ?, mavenversion = ?, repositoryurl = ? "768 + " WHERE id = ?";769 // Debug message on SQL.770 if (LOG.isDebugEnabled()) {771 LOG.debug("SQL : " + query);772 }773 Connection connection = this.databaseSpring.connect();774 try {775 PreparedStatement preStat = connection.prepareStatement(query);776 try {777 preStat.setString(1, brp.getBuild());778 preStat.setString(2, brp.getRevision());779 preStat.setString(3, brp.getApplication());780 preStat.setString(4, brp.getRelease());781 preStat.setString(5, brp.getProject());782 preStat.setString(6, brp.getTicketIdFixed());783 preStat.setString(7, brp.getBugIdFixed());784 preStat.setString(8, brp.getSubject());785 preStat.setString(9, brp.getReleaseOwner());786 preStat.setString(10, brp.getLink());787 preStat.setString(11, brp.getJenkinsBuildId());788 preStat.setString(12, brp.getMavenGroupId());789 preStat.setString(13, brp.getMavenArtifactId());790 preStat.setString(14, brp.getMavenVersion());791 preStat.setString(15, brp.getRepositoryUrl());792 preStat.setInt(16, brp.getId());793 preStat.executeUpdate();794 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);795 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));796 } catch (SQLException exception) {797 LOG.error("Unable to execute query : " + exception.toString());798 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);799 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));800 } finally {801 preStat.close();802 }803 } catch (SQLException exception) {804 LOG.error("Unable to execute query : " + exception.toString());805 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);806 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));807 } finally {808 try {809 if (connection != null) {810 connection.close();811 }812 } catch (SQLException exception) {813 LOG.warn("Unable to close connection : " + exception.toString());814 }815 }816 return new Answer(msg);817 }818 @Override819 public BuildRevisionParameters loadFromResultSet(ResultSet rs) throws SQLException {820 int iD = rs.getInt("ID");821 String build = ParameterParserUtil.parseStringParam(rs.getString("build"), "");822 String revision = ParameterParserUtil.parseStringParam(rs.getString("revision"), "");823 String release = ParameterParserUtil.parseStringParam(rs.getString("release"), "");824 String application = ParameterParserUtil.parseStringParam(rs.getString("application"), "");825 String project = ParameterParserUtil.parseStringParam(rs.getString("project"), "");826 String ticketIdFixed = ParameterParserUtil.parseStringParam(rs.getString("ticketidfixed"), "");827 String budIdFixed = ParameterParserUtil.parseStringParam(rs.getString("bugidfixed"), "");828 String link = ParameterParserUtil.parseStringParam(rs.getString("link"), "");829 String releaseOwner = ParameterParserUtil.parseStringParam(rs.getString("releaseowner"), "");830 String subject = ParameterParserUtil.parseStringParam(rs.getString("subject"), "");831 Timestamp dateCreation = rs.getTimestamp("datecre");832 String jenkinsBuildId = ParameterParserUtil.parseStringParam(rs.getString("jenkinsbuildid"), "");833 String mavenGroupId = ParameterParserUtil.parseStringParam(rs.getString("mavengroupid"), "");...

Full Screen

Full Screen

loadFromResultSet

Using AI Code Generation

copy

Full Screen

1BuildRevisionParametersDAO buildRevisionParametersDAO = new BuildRevisionParametersDAO();2BuildRevisionParameters buildRevisionParameters = new BuildRevisionParameters();3buildRevisionParameters = buildRevisionParametersDAO.loadFromResultSet(resultSet);4BuildRevisionInvariantDAO buildRevisionInvariantDAO = new BuildRevisionInvariantDAO();5BuildRevisionInvariant buildRevisionInvariant = new BuildRevisionInvariant();6buildRevisionInvariant = buildRevisionInvariantDAO.loadFromResultSet(resultSet);7BuildRevisionParametersDAO buildRevisionParametersDAO = new BuildRevisionParametersDAO();8BuildRevisionParameters buildRevisionParameters = new BuildRevisionParameters();9buildRevisionParameters = buildRevisionParametersDAO.loadFromResultSet(resultSet);10BuildRevisionInvariantDAO buildRevisionInvariantDAO = new BuildRevisionInvariantDAO();11BuildRevisionInvariant buildRevisionInvariant = new BuildRevisionInvariant();12buildRevisionInvariant = buildRevisionInvariantDAO.loadFromResultSet(resultSet);13BuildRevisionParametersDAO buildRevisionParametersDAO = new BuildRevisionParametersDAO();14BuildRevisionParameters buildRevisionParameters = new BuildRevisionParameters();15buildRevisionParameters = buildRevisionParametersDAO.loadFromResultSet(resultSet);16BuildRevisionInvariantDAO buildRevisionInvariantDAO = new BuildRevisionInvariantDAO();17BuildRevisionInvariant buildRevisionInvariant = new BuildRevisionInvariant();18buildRevisionInvariant = buildRevisionInvariantDAO.loadFromResultSet(resultSet);19BuildRevisionParametersDAO buildRevisionParametersDAO = new BuildRevisionParametersDAO();20BuildRevisionParameters buildRevisionParameters = new BuildRevisionParameters();21buildRevisionParameters = buildRevisionParametersDAO.loadFromResultSet(resultSet);22BuildRevisionInvariantDAO buildRevisionInvariantDAO = new BuildRevisionInvariantDAO();23BuildRevisionInvariant buildRevisionInvariant = new BuildRevisionInvariant();24buildRevisionInvariant = buildRevisionInvariantDAO.loadFromResultSet(resultSet);

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