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

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

Source:AppServiceHeaderDAO.java Github

copy

Full Screen

...74 preStat.setString(1, service);75 preStat.setString(2, key);76 try (ResultSet resultSet = preStat.executeQuery()) {77 if (resultSet.first()) {78 result = loadFromResultSet(resultSet);79 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);80 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));81 ans.setItem(result);82 } else {83 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);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 }90 } catch (SQLException exception) {91 LOG.error("Unable to execute query : {}", exception.toString());92 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);93 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));94 }95 //sets the message96 ans.setResultMessage(msg);97 return ans;98 }99 @Override100 public AnswerList<AppServiceHeader> readByVariousByCriteria(String service, boolean withActiveCriteria, boolean isActive, int start, int amount, String column, String dir, String searchTerm, Map<String, List<String>> individualSearch) {101 AnswerList<AppServiceHeader> response = new AnswerList<>();102 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);103 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));104 List<AppServiceHeader> objectList = new ArrayList<>();105 StringBuilder searchSQL = new StringBuilder();106 List<String> individualColumnSearchValues = new ArrayList<>();107 StringBuilder query = new StringBuilder();108 //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disregarding the limit clauses that109 //were applied -- used for pagination p110 query.append("SELECT SQL_CALC_FOUND_ROWS * FROM appserviceheader srh ");111 searchSQL.append(" where 1=1 ");112 if (!StringUtil.isNullOrEmpty(searchTerm)) {113 searchSQL.append(" and (srh.`service` like ?");114 searchSQL.append(" or srh.`key` like ?");115 searchSQL.append(" or srh.`value` like ?");116 searchSQL.append(" or srh.`sort` like ?");117 searchSQL.append(" or srh.`isActive` like ?");118 searchSQL.append(" or srh.`usrCreated` like ?");119 searchSQL.append(" or srh.`usrModif` like ?");120 searchSQL.append(" or srh.`dateCreated` like ?");121 searchSQL.append(" or srh.`dateModif` like ?");122 searchSQL.append(" or srh.`description` like ?)");123 }124 if (individualSearch != null && !individualSearch.isEmpty()) {125 searchSQL.append(" and ( 1=1 ");126 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {127 searchSQL.append(" and ");128 searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));129 individualColumnSearchValues.addAll(entry.getValue());130 }131 searchSQL.append(" )");132 }133 if (!StringUtil.isNullOrEmpty(service)) {134 searchSQL.append(" and (srh.`service` = ? )");135 }136 if (withActiveCriteria) {137 searchSQL.append(" and (srh.`isActive` = ? )");138 }139 query.append(searchSQL);140 if (!StringUtil.isNullOrEmpty(column)) {141 query.append(" order by `").append(column).append("` ").append(dir);142 }143 if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {144 query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);145 } else {146 query.append(" limit ").append(start).append(" , ").append(amount);147 }148 LOG.debug("SQL : {}", query);149 try (Connection connection = this.databaseSpring.connect();150 PreparedStatement preStat = connection.prepareStatement(query.toString());151 Statement stm = connection.createStatement()) {152 int i = 1;153 if (!StringUtil.isNullOrEmpty(searchTerm)) {154 preStat.setString(i++, "%" + searchTerm + "%");155 preStat.setString(i++, "%" + searchTerm + "%");156 preStat.setString(i++, "%" + searchTerm + "%");157 preStat.setString(i++, "%" + searchTerm + "%");158 preStat.setString(i++, "%" + searchTerm + "%");159 preStat.setString(i++, "%" + searchTerm + "%");160 preStat.setString(i++, "%" + searchTerm + "%");161 preStat.setString(i++, "%" + searchTerm + "%");162 preStat.setString(i++, "%" + searchTerm + "%");163 preStat.setString(i++, "%" + searchTerm + "%");164 }165 for (String individualColumnSearchValue : individualColumnSearchValues) {166 preStat.setString(i++, individualColumnSearchValue);167 }168 if (!StringUtil.isNullOrEmpty(service)) {169 preStat.setString(i++, service);170 }171 if (withActiveCriteria) {172 preStat.setBoolean(i, isActive);173 }174 try (ResultSet resultSet = preStat.executeQuery();175 ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()")) {176 //gets the data177 while (resultSet.next()) {178 objectList.add(this.loadFromResultSet(resultSet));179 }180 //get the total number of rows181 int nrTotalRows = 0;182 if (rowSet != null && rowSet.next()) {183 nrTotalRows = rowSet.getInt(1);184 }185 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.186 LOG.error("Partial Result in the query.");187 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);188 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));189 response = new AnswerList<>(objectList, nrTotalRows);190 } else if (objectList.isEmpty()) {191 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);192 response = new AnswerList<>(objectList, nrTotalRows);193 } else {194 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);195 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));196 response = new AnswerList<>(objectList, nrTotalRows);197 }198 } catch (SQLException exception) {199 LOG.error("Unable to execute query : {}", exception.toString());200 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);201 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));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 }208 response.setResultMessage(msg);209 response.setDataList(objectList);210 return response;211 }212 @Override213 public Answer create(AppServiceHeader object) {214 MessageEvent msg;215 StringBuilder query = new StringBuilder();216 query.append("INSERT INTO appserviceheader (`service`, `key`, `value`, `sort`, `isActive`, `description`, `usrcreated`) ");217 query.append("VALUES (?,?,?,?,?,?,?)");218 LOG.debug("SQL : {}", query);219 try (Connection connection = this.databaseSpring.connect();220 PreparedStatement preStat = connection.prepareStatement(query.toString())) {221 int i = 1;222 preStat.setString(i++, object.getService());223 preStat.setString(i++, object.getKey());224 preStat.setString(i++, object.getValue());225 preStat.setInt(i++, object.getSort());226 preStat.setBoolean(i++, object.isActive());227 preStat.setString(i++, object.getDescription());228 preStat.setString(i, object.getUsrCreated());229 preStat.executeUpdate();230 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);231 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));232 } catch (SQLException exception) {233 LOG.error("Unable to execute query : {}", exception.toString());234 if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) { //23000 is the sql state for duplicate entries235 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);236 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));237 } else {238 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);239 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));240 }241 }242 return new Answer(msg);243 }244 @Override245 public Answer delete(AppServiceHeader object) {246 MessageEvent msg;247 final String query = "DELETE FROM appserviceheader WHERE `service` = ? and `key` = ? ";248 LOG.debug("SQL : {}", query);249 LOG.debug("SQL.param.service : {}", object.getService());250 LOG.debug("SQL.param.key : {}", object.getKey());251 try (Connection connection = this.databaseSpring.connect();252 PreparedStatement preStat = connection.prepareStatement(query)253 ) {254 int i = 1;255 preStat.setString(i++, object.getService());256 preStat.setString(i, object.getKey());257 preStat.executeUpdate();258 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);259 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "DELETE"));260 } catch (SQLException exception) {261 LOG.error("Unable to execute query : {}", exception.toString());262 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);263 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));264 }265 return new Answer(msg);266 }267 @Override268 public Answer update(String service, String key, AppServiceHeader object) {269 MessageEvent msg;270 final String query = "UPDATE appserviceheader SET `Service` = ?, `Key` = ?, description = ?, sort = ?, `IsActive` = ?, `value` = ?, "271 + "dateModif = NOW(), usrModif= ? WHERE `Service` = ? and `Key` = ?";272 LOG.debug("SQL : {}", query);273 LOG.debug("SQL.param.service : {}", object.getService());274 LOG.debug("SQL.param.key : {}", object.getKey());275 try (Connection connection = this.databaseSpring.connect();276 PreparedStatement preStat = connection.prepareStatement(query)277 ) {278 int i = 1;279 preStat.setString(i++, object.getService());280 preStat.setString(i++, object.getKey());281 preStat.setString(i++, object.getDescription());282 preStat.setInt(i++, object.getSort());283 preStat.setBoolean(i++, object.isActive());284 preStat.setString(i++, object.getValue());285 preStat.setString(i++, object.getUsrModif());286 preStat.setString(i++, service);287 preStat.setString(i, key);288 preStat.executeUpdate();289 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);290 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));291 } catch (SQLException exception) {292 LOG.error("Unable to execute query : {}", exception.toString());293 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);294 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));295 }296 return new Answer(msg);297 }298 @Override299 public AppServiceHeader loadFromResultSet(ResultSet rs) throws SQLException {300 String service = ParameterParserUtil.parseStringParam(rs.getString("srh.service"), "");301 String key = ParameterParserUtil.parseStringParam(rs.getString("srh.key"), "");302 String value = ParameterParserUtil.parseStringParam(rs.getString("srh.value"), "");303 int sort = ParameterParserUtil.parseIntegerParam(rs.getString("srh.sort"), 0);304 boolean isActive = rs.getBoolean("srh.isActive");305 String description = ParameterParserUtil.parseStringParam(rs.getString("srh.description"), "");306 String usrModif = ParameterParserUtil.parseStringParam(rs.getString("srh.UsrModif"), "");307 String usrCreated = ParameterParserUtil.parseStringParam(rs.getString("srh.UsrCreated"), "");308 Timestamp dateModif = rs.getTimestamp("srh.DateModif");309 Timestamp dateCreated = rs.getTimestamp("srh.DateCreated");310 return factoryAppServiceHeader.create(service, key, value, isActive, sort, description,311 usrCreated, dateCreated, usrModif, dateModif);312 }313 @Override...

Full Screen

Full Screen

loadFromResultSet

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.AppServiceHeader;2import java.sql.ResultSet;3import java.sql.SQLException;4public class AppServiceHeaderDAO {5 public AppServiceHeader loadFromResultSet(ResultSet rs) throws SQLException {6 AppServiceHeader appServiceHeader = new AppServiceHeader();7 appServiceHeader.setService(rs.getString("service"));8 appServiceHeader.setSystem(rs.getString("system"));9 appServiceHeader.setHeader(rs.getString("header"));10 appServiceHeader.setValue(rs.getString("value"));11 appServiceHeader.setUsrCreated(rs.getString("usrCreated"));12 appServiceHeader.setDateCreated(rs.getTimestamp("dateCreated"));13 appServiceHeader.setUsrModif(rs.getString("usrModif"));14 appServiceHeader.setDateModif(rs.getTimestamp("dateModif"));15 return appServiceHeader;16 }17}18import org.cerberus.crud.entity.AppServiceHeader;19import java.sql.ResultSet;20import java.sql.SQLException;21public class AppServiceHeaderDAO {22 public AppServiceHeader loadFromResultSet(ResultSet rs) throws SQLException {23 AppServiceHeader appServiceHeader = new AppServiceHeader();24 appServiceHeader.setService(rs.getString("service"));25 appServiceHeader.setSystem(rs.getString("system"));26 appServiceHeader.setHeader(rs.getString("header"));27 appServiceHeader.setValue(rs.getString("value"));28 appServiceHeader.setUsrCreated(rs.getString("usrCreated"));29 appServiceHeader.setDateCreated(rs.getTimestamp("dateCreated"));30 appServiceHeader.setUsrModif(rs.getString("usrModif"));31 appServiceHeader.setDateModif(rs.getTimestamp("dateModif"));32 return appServiceHeader;33 }34}35import org.cerberus.crud.entity.AppServiceHeader;36import java.sql.ResultSet;37import java.sql.SQLException;38public class AppServiceHeaderDAO {39 public AppServiceHeader loadFromResultSet(ResultSet rs

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