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

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

Source:BuildRevisionInvariantDAO.java Github

copy

Full Screen

...69 preStat.setInt(3, seq);70 ResultSet resultSet = preStat.executeQuery();71 try {72 if (resultSet.first()) {73 result = loadFromResultSet(resultSet);74 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);75 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));76 ans.setItem(result);77 } else {78 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);79 }80 } catch (SQLException exception) {81 LOG.error("Unable to execute query : " + exception.toString());82 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);83 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));84 } finally {85 resultSet.close();86 }87 } catch (SQLException exception) {88 LOG.error("Unable to execute query : " + exception.toString());89 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);90 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));91 } finally {92 preStat.close();93 }94 } catch (SQLException exception) {95 LOG.error("Unable to execute query : " + exception.toString());96 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);97 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));98 } finally {99 try {100 if (connection != null) {101 connection.close();102 }103 } catch (SQLException exception) {104 LOG.warn("Unable to close connection : " + exception.toString());105 }106 }107 //sets the message108 ans.setResultMessage(msg);109 return ans;110 }111 @Override112 public AnswerItem readByKey(String system, Integer level, String versionName) {113 AnswerItem ans = new AnswerItem();114 BuildRevisionInvariant result = null;115 final String query = "SELECT * FROM `buildrevisioninvariant` WHERE `system` = ? and level = ? and versionname = ? ";116 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);117 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));118 Connection connection = this.databaseSpring.connect();119 try {120 PreparedStatement preStat = connection.prepareStatement(query);121 try {122 preStat.setString(1, system);123 preStat.setInt(2, level);124 preStat.setString(3, versionName);125 ResultSet resultSet = preStat.executeQuery();126 try {127 if (resultSet.first()) {128 result = loadFromResultSet(resultSet);129 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);130 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));131 ans.setItem(result);132 } else {133 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);134 }135 } catch (SQLException exception) {136 LOG.error("Unable to execute query : " + exception.toString());137 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);138 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));139 } finally {140 resultSet.close();141 }142 } catch (SQLException exception) {143 LOG.error("Unable to execute query : " + exception.toString());144 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);145 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));146 } finally {147 preStat.close();148 }149 } catch (SQLException exception) {150 LOG.error("Unable to execute query : " + exception.toString());151 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);152 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));153 } finally {154 try {155 if (connection != null) {156 connection.close();157 }158 } catch (SQLException exception) {159 LOG.warn("Unable to close connection : " + exception.toString());160 }161 }162 //sets the message163 ans.setResultMessage(msg);164 return ans;165 }166 @Override167 public AnswerList readByVariousByCriteria(String system, Integer level, int start, int amount, String column, String dir, String searchTerm, Map<String, List<String>> individualSearch) {168 AnswerList response = new AnswerList();169 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);170 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));171 List<BuildRevisionInvariant> briList = new ArrayList<BuildRevisionInvariant>();172 StringBuilder searchSQL = new StringBuilder();173 List<String> individalColumnSearchValues = new ArrayList<String>();174 StringBuilder query = new StringBuilder();175 //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that 176 //were applied -- used for pagination p177 query.append("SELECT SQL_CALC_FOUND_ROWS * FROM buildrevisioninvariant ");178 searchSQL.append(" where 1=1 ");179 if (!StringUtil.isNullOrEmpty(searchTerm)) {180 searchSQL.append(" and (`seq` like ?");181 searchSQL.append(" or `level` like ?");182 searchSQL.append(" or `versionname` like ? )");183 }184 if (individualSearch != null && !individualSearch.isEmpty()) {185 searchSQL.append(" and ( 1=1 ");186 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {187 searchSQL.append(" and ");188 searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));189 individalColumnSearchValues.addAll(entry.getValue());190 }191 searchSQL.append(" )");192 }193 if (!StringUtil.isNullOrEmpty(system)) {194 searchSQL.append(" and (`System` like ? )");195 }196 if (level != -1) {197 searchSQL.append(" and (`level`= ?)");198 }199 query.append(searchSQL);200 if (!StringUtil.isNullOrEmpty(column)) {201 query.append(" order by `").append(column).append("` ").append(dir);202 }203 if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {204 query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);205 } else {206 query.append(" limit ").append(start).append(" , ").append(amount);207 }208 // Debug message on SQL.209 if (LOG.isDebugEnabled()) {210 LOG.debug("SQL : " + query.toString());211 }212 Connection connection = this.databaseSpring.connect();213 try {214 PreparedStatement preStat = connection.prepareStatement(query.toString());215 try {216 int i = 1;217 if (!StringUtil.isNullOrEmpty(searchTerm)) {218 preStat.setString(i++, "%" + searchTerm + "%");219 preStat.setString(i++, "%" + searchTerm + "%");220 preStat.setString(i++, "%" + searchTerm + "%");221 }222 for (String individualColumnSearchValue : individalColumnSearchValues) {223 preStat.setString(i++, individualColumnSearchValue);224 }225 if (!StringUtil.isNullOrEmpty(system)) {226 preStat.setString(i++, system);227 }228 if (level != -1) {229 preStat.setInt(i++, level);230 }231 ResultSet resultSet = preStat.executeQuery();232 try {233 //gets the data234 while (resultSet.next()) {235 briList.add(this.loadFromResultSet(resultSet));236 }237 //get the total number of rows238 resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");239 int nrTotalRows = 0;240 if (resultSet != null && resultSet.next()) {241 nrTotalRows = resultSet.getInt(1);242 }243 if (briList.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.244 LOG.error("Partial Result in the query.");245 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);246 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));247 response = new AnswerList(briList, nrTotalRows);248 } else if (briList.size() <= 0) {249 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);250 response = new AnswerList(briList, nrTotalRows);251 } else {252 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);253 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));254 response = new AnswerList(briList, nrTotalRows);255 }256 } catch (SQLException exception) {257 LOG.error("Unable to execute query : " + exception.toString());258 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);259 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));260 } finally {261 if (resultSet != null) {262 resultSet.close();263 }264 }265 } catch (SQLException exception) {266 LOG.error("Unable to execute query : " + exception.toString());267 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);268 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));269 } finally {270 if (preStat != null) {271 preStat.close();272 }273 }274 } catch (SQLException exception) {275 LOG.error("Unable to execute query : " + exception.toString());276 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);277 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));278 } finally {279 try {280 if (!this.databaseSpring.isOnTransaction()) {281 if (connection != null) {282 connection.close();283 }284 }285 } catch (SQLException exception) {286 LOG.warn("Unable to close connection : " + exception.toString());287 }288 }289 response.setResultMessage(msg);290 response.setDataList(briList);291 return response;292 }293 @Override294 public Answer create(BuildRevisionInvariant buildRevisionInvariant) {295 MessageEvent msg = null;296 StringBuilder query = new StringBuilder();297 query.append("INSERT INTO buildrevisioninvariant (system, level, seq, versionname) ");298 query.append("VALUES (?, ?, ?, ?)");299 // Debug message on SQL.300 if (LOG.isDebugEnabled()) {301 LOG.debug("SQL : " + query.toString());302 }303 Connection connection = this.databaseSpring.connect();304 try {305 PreparedStatement preStat = connection.prepareStatement(query.toString());306 try {307 preStat.setString(1, buildRevisionInvariant.getSystem());308 preStat.setInt(2, buildRevisionInvariant.getLevel());309 preStat.setInt(3, buildRevisionInvariant.getSeq());310 preStat.setString(4, buildRevisionInvariant.getVersionName());311 preStat.executeUpdate();312 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);313 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));314 } catch (SQLException exception) {315 LOG.error("Unable to execute query : " + exception.toString());316 if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) { //23000 is the sql state for duplicate entries317 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);318 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));319 } else {320 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);321 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));322 }323 } finally {324 preStat.close();325 }326 } catch (SQLException exception) {327 LOG.error("Unable to execute query : " + exception.toString());328 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);329 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));330 } finally {331 try {332 if (connection != null) {333 connection.close();334 }335 } catch (SQLException exception) {336 LOG.warn("Unable to close connection : " + exception.toString());337 }338 }339 return new Answer(msg);340 }341 @Override342 public Answer delete(BuildRevisionInvariant buildRevisionInvariant) {343 MessageEvent msg = null;344 final String query = "DELETE FROM buildrevisioninvariant WHERE system = ? and level= ? and seq = ? ";345 // Debug message on SQL.346 if (LOG.isDebugEnabled()) {347 LOG.debug("SQL : " + query);348 }349 Connection connection = this.databaseSpring.connect();350 try {351 PreparedStatement preStat = connection.prepareStatement(query);352 try {353 preStat.setString(1, buildRevisionInvariant.getSystem());354 preStat.setInt(2, buildRevisionInvariant.getLevel());355 preStat.setInt(3, buildRevisionInvariant.getSeq());356 preStat.executeUpdate();357 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);358 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "DELETE"));359 } catch (SQLException exception) {360 LOG.error("Unable to execute query : " + exception.toString());361 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);362 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));363 } finally {364 preStat.close();365 }366 } catch (SQLException exception) {367 LOG.error("Unable to execute query : " + exception.toString());368 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);369 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));370 } finally {371 try {372 if (connection != null) {373 connection.close();374 }375 } catch (SQLException exception) {376 LOG.warn("Unable to close connection : " + exception.toString());377 }378 }379 return new Answer(msg);380 }381 @Override382 public Answer update(String system, Integer level, Integer seq, BuildRevisionInvariant buildRevisionInvariant) {383 MessageEvent msg = null;384 final String query = "UPDATE buildrevisioninvariant SET system = ?, level = ?, seq = ?, versionname = ? WHERE system = ? and level = ? and seq = ? ";385 // Debug message on SQL.386 if (LOG.isDebugEnabled()) {387 LOG.debug("SQL : " + query);388 }389 Connection connection = this.databaseSpring.connect();390 try {391 PreparedStatement preStat = connection.prepareStatement(query);392 try {393 int i=1;394 preStat.setString(i++, buildRevisionInvariant.getSystem());395 preStat.setInt(i++, buildRevisionInvariant.getLevel());396 preStat.setInt(i++, buildRevisionInvariant.getSeq());397 preStat.setString(i++, buildRevisionInvariant.getVersionName());398 preStat.setString(i++, system);399 preStat.setInt(i++, level);400 preStat.setInt(i++, seq);401 preStat.executeUpdate();402 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);403 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));404 } catch (SQLException exception) {405 LOG.error("Unable to execute query : " + exception.toString());406 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);407 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));408 } finally {409 preStat.close();410 }411 } catch (SQLException exception) {412 LOG.error("Unable to execute query : " + exception.toString());413 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);414 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));415 } finally {416 try {417 if (connection != null) {418 connection.close();419 }420 } catch (SQLException exception) {421 LOG.warn("Unable to close connection : " + exception.toString());422 }423 }424 return new Answer(msg);425 }426 @Override427 public BuildRevisionInvariant loadFromResultSet(ResultSet resultSet) throws SQLException {428 String system = ParameterParserUtil.parseStringParam(resultSet.getString("system"), "");429 Integer level = ParameterParserUtil.parseIntegerParam(resultSet.getString("level"), 0);430 Integer seq = ParameterParserUtil.parseIntegerParam(resultSet.getString("seq"), 0);431 String versionname = ParameterParserUtil.parseStringParam(resultSet.getString("versionname"), "");432 factoryBuildRevisionInvariant = new FactoryBuildRevisionInvariant();433 return factoryBuildRevisionInvariant.create(system, level, seq, versionname);434 }435 @Override436 public AnswerList<List<String>> readDistinctValuesByCriteria(String system, String searchTerm, Map<String, List<String>> individualSearch, String columnName) {437 AnswerList answer = new AnswerList();438 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);439 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));440 List<String> distinctValues = new ArrayList<>();441 StringBuilder searchSQL = new StringBuilder();...

Full Screen

Full Screen

loadFromResultSet

Using AI Code Generation

copy

Full Screen

1 public void loadFromResultSet(ResultSet resultSet) throws SQLException {2 this.id = resultSet.getInt("id");3 this.value = resultSet.getString("value");4 this.sort = resultSet.getInt("sort");5 this.description = resultSet.getString("description");6 this.gp1 = resultSet.getString("gp1");7 this.gp2 = resultSet.getString("gp2");8 this.gp3 = resultSet.getString("gp3");9 this.gp4 = resultSet.getString("gp4");10 this.gp5 = resultSet.getString("gp5");11 this.type = resultSet.getString("type");12 this.extraLong1 = resultSet.getLong("extraLong1");13 this.extraLong2 = resultSet.getLong("extraLong2");14 this.extraLong3 = resultSet.getLong("extraLong3");15 this.extraLong4 = resultSet.getLong("extraLong4");16 this.extraLong5 = resultSet.getLong("extraLong5");17 this.extraString1 = resultSet.getString("extraString1");18 this.extraString2 = resultSet.getString("extraString2");19 this.extraString3 = resultSet.getString("extraString3");20 this.extraString4 = resultSet.getString("extraString4");21 this.extraString5 = resultSet.getString("extraString5");22 this.extraDate1 = resultSet.getDate("extraDate1");23 this.extraDate2 = resultSet.getDate("extraDate2");24 this.extraDate3 = resultSet.getDate("extraDate3");25 this.extraDate4 = resultSet.getDate("extraDate4");26 this.extraDate5 = resultSet.getDate("extraDate5");27 this.system = resultSet.getString("system");28 this.dateCreated = resultSet.getDate("dateCreated");29 this.userCreated = resultSet.getString("userCreated");30 this.dateModif = resultSet.getDate("dateModif");31 this.userModif = resultSet.getString("userModif");32 }33 public void loadFromResultSet(ResultSet resultSet) throws SQLException {34 this.id = resultSet.getInt("id");35 this.value = resultSet.getString("value");36 this.sort = resultSet.getInt("sort");

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