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

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

Source:EventHookDAO.java Github

copy

Full Screen

...74 preStat.setInt(1, id);75 try (ResultSet resultSet = preStat.executeQuery();) {76 //parse query77 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 (Exception e) {91 LOG.warn("Unable to readByKey Label: " + e.getMessage());92 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",93 e.toString());94 } finally {95 ans.setResultMessage(msg);96 }97 return ans;98 }99 @Override100 public AnswerList<EventHook> readByEventReferenceByCriteria(List<String> eventReference, List<String> objectKey1, boolean activeOnly, int start, int amount, String column, String dir, String searchTerm, Map<String, List<String>> individualSearch) {101 AnswerList<EventHook> response = new AnswerList<>();102 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);103 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));104 List<EventHook> objectList = new ArrayList<>();105 StringBuilder searchSQL = new StringBuilder();106 List<String> individalColumnSearchValues = new ArrayList<>();107 StringBuilder query = new StringBuilder();108 //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that 109 //were applied -- used for pagination p110 query.append("SELECT SQL_CALC_FOUND_ROWS evh.* FROM `eventhook` evh ");111 searchSQL.append(" where 1=1 ");112 if (!StringUtil.isNullOrEmpty(searchTerm)) {113 searchSQL.append(" and (evh.`id` like ?");114 searchSQL.append(" or evh.`ObjectKey1` like ?");115 searchSQL.append(" or evh.`ObjectKey2` like ?");116 searchSQL.append(" or evh.`EventReference` like ?");117 searchSQL.append(" or evh.`HookConnector` like ?");118 searchSQL.append(" or evh.`HookRecipient` like ?");119 searchSQL.append(" or evh.`HookChannel` like ?");120 searchSQL.append(" or evh.`description` like ?");121 searchSQL.append(" or evh.`usrCreated` like ?");122 searchSQL.append(" or evh.`dateCreated` like ?");123 searchSQL.append(" or evh.`usrModif` like ?");124 searchSQL.append(" or evh.`dateModif` like ?)");125 }126 if (individualSearch != null && !individualSearch.isEmpty()) {127 searchSQL.append(" and ( 1=1 ");128 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {129 searchSQL.append(" and ");130 searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));131 individalColumnSearchValues.addAll(entry.getValue());132 }133 searchSQL.append(" )");134 }135 if (eventReference != null) {136 searchSQL.append(" and ");137 searchSQL.append(SqlUtil.generateInClause("evh.`EventReference`", eventReference));138 }139 if (objectKey1 != null) {140 searchSQL.append(" and ");141 searchSQL.append(SqlUtil.generateInClause("evh.`ObjectKey1`", objectKey1));142 }143 query.append(searchSQL);144 if (!StringUtil.isNullOrEmpty(column)) {145 query.append(" order by ").append(column).append(" ").append(dir);146 }147 if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {148 query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);149 } else {150 query.append(" limit ").append(start).append(" , ").append(amount);151 }152 // Debug message on SQL.153 if (LOG.isDebugEnabled()) {154 LOG.debug("SQL : " + query.toString());155 LOG.debug("SQL.param.eventReference : " + eventReference);156 LOG.debug("SQL.param.objectKey1 : " + objectKey1);157 }158 try (Connection connection = databaseSpring.connect();159 PreparedStatement preStat = connection.prepareStatement(query.toString());160 Statement stm = connection.createStatement();) {161 int i = 1;162 if (!StringUtil.isNullOrEmpty(searchTerm)) {163 preStat.setString(i++, "%" + searchTerm + "%");164 preStat.setString(i++, "%" + searchTerm + "%");165 preStat.setString(i++, "%" + searchTerm + "%");166 preStat.setString(i++, "%" + searchTerm + "%");167 preStat.setString(i++, "%" + searchTerm + "%");168 preStat.setString(i++, "%" + searchTerm + "%");169 preStat.setString(i++, "%" + searchTerm + "%");170 preStat.setString(i++, "%" + searchTerm + "%");171 preStat.setString(i++, "%" + searchTerm + "%");172 preStat.setString(i++, "%" + searchTerm + "%");173 preStat.setString(i++, "%" + searchTerm + "%");174 preStat.setString(i++, "%" + searchTerm + "%");175 }176 for (String individualColumnSearchValue : individalColumnSearchValues) {177 preStat.setString(i++, individualColumnSearchValue);178 }179 if (eventReference != null) {180 for (String evtRef : eventReference) {181 preStat.setString(i++, evtRef);182 }183 }184 if (objectKey1 != null) {185 for (String objKey1 : objectKey1) {186 preStat.setString(i++, objKey1);187 }188 }189 try (ResultSet resultSet = preStat.executeQuery();190 ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()");) {191 //gets the data192 while (resultSet.next()) {193 objectList.add(this.loadFromResultSet(resultSet));194 }195 int nrTotalRows = 0;196 if (rowSet != null && rowSet.next()) {197 nrTotalRows = rowSet.getInt(1);198 }199 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.200 LOG.error("Partial Result in the query.");201 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);202 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));203 response = new AnswerList<>(objectList, nrTotalRows);204 } else if (objectList.size() <= 0) {205 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);206 response = new AnswerList<>(objectList, nrTotalRows);207 } else {208 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);209 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));210 response = new AnswerList<>(objectList, nrTotalRows);211 }212 response.setDataList(objectList);213 } catch (SQLException exception) {214 LOG.error("Unable to execute query : " + exception.toString());215 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);216 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));217 }218 } catch (Exception e) {219 LOG.warn("Unable to readBySystemCriteria Label: " + e.getMessage());220 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",221 e.toString());222 } finally {223 response.setResultMessage(msg);224 }225 return response;226 }227 @Override228 public Answer create(EventHook eventHook) {229 Answer response = new Answer();230 MessageEvent msg = null;231 StringBuilder query = new StringBuilder();232 query.append("INSERT INTO eventhook (`EventReference`, `ObjectKey1`, `ObjectKey2`, `IsActive`, `HookConnector`, `HookRecipient`, `HookChannel`, `Description`, `usrCreated` ) ");233 query.append("VALUES (?,?,?,?,?,?,?,?,?)");234 // Debug message on SQL.235 if (LOG.isDebugEnabled()) {236 LOG.debug("SQL : " + query.toString());237 LOG.debug("eventreference : " + eventHook.toString());238 }239 try (Connection connection = databaseSpring.connect();240 PreparedStatement preStat = connection.prepareStatement(query.toString())) {241 int i = 1;242 preStat.setString(i++, eventHook.getEventReference());243 preStat.setString(i++, eventHook.getObjectKey1());244 preStat.setString(i++, eventHook.getObjectKey2());245 preStat.setBoolean(i++, eventHook.isActive());246 preStat.setString(i++, eventHook.getHookConnector());247 preStat.setString(i++, eventHook.getHookRecipient());248 preStat.setString(i++, eventHook.getHookChannel());249 preStat.setString(i++, eventHook.getDescription());250 preStat.setString(i++, eventHook.getUsrCreated());251 preStat.executeUpdate();252 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);253 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));254 } catch (Exception e) {255 LOG.warn("Unable to create EventHook: " + e.getMessage());256 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",257 e.toString());258 } finally {259 response.setResultMessage(msg);260 }261 return response;262 }263 @Override264 public Answer delete(EventHook object) {265 Answer response = new Answer();266 MessageEvent msg = null;267 final String query = "DELETE FROM eventhook WHERE id = ? ";268 // Debug message on SQL.269 if (LOG.isDebugEnabled()) {270 LOG.debug("SQL : " + query);271 }272 try (Connection connection = databaseSpring.connect();273 PreparedStatement preStat = connection.prepareStatement(query)) {274 preStat.setInt(1, object.getId());275 preStat.executeUpdate();276 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);277 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "DELETE"));278 } catch (Exception e) {279 LOG.warn("Unable to delete Event Hook: " + e.getMessage());280 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",281 e.toString());282 } finally {283 response.setResultMessage(msg);284 }285 return response;286 }287 @Override288 public Answer update(EventHook object) {289 Answer response = new Answer();290 MessageEvent msg = null;291 final String query = "UPDATE eventhook SET `EventReference` = ?, `ObjectKey1` = ?, `ObjectKey2` = ?, `IsActive` = ?, `HookConnector` = ?, `HookRecipient` = ?, `HookChannel` = ?, `description` = ?"292 + ", `usrModif` = ?, `dateModif` = now() WHERE id = ?";293 // Debug message on SQL.294 if (LOG.isDebugEnabled()) {295 LOG.debug("SQL : " + query);296 }297 try (Connection connection = databaseSpring.connect();298 PreparedStatement preStat = connection.prepareStatement(query)) {299 int i = 1;300 preStat.setString(i++, object.getEventReference());301 preStat.setString(i++, object.getObjectKey1());302 preStat.setString(i++, object.getObjectKey2());303 preStat.setBoolean(i++, object.isActive());304 preStat.setString(i++, object.getHookConnector());305 preStat.setString(i++, object.getHookRecipient());306 preStat.setString(i++, object.getHookChannel());307 preStat.setString(i++, object.getDescription());308 preStat.setString(i++, object.getUsrModif());309 preStat.setInt(i++, object.getId());310 preStat.executeUpdate();311 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);312 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));313 } catch (Exception e) {314 LOG.warn("Unable to update Event Hook: " + e.getMessage());315 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",316 e.toString());317 } finally {318 response.setResultMessage(msg);319 }320 return response;321 }322 @Override323 public EventHook loadFromResultSet(ResultSet rs) throws SQLException {324 Integer id = ParameterParserUtil.parseIntegerParam(rs.getString("evh.id"), 0);325 String eventReference = ParameterParserUtil.parseStringParam(rs.getString("evh.EventReference"), "");326 String objectKey1 = ParameterParserUtil.parseStringParam(rs.getString("evh.ObjectKey1"), "");327 String objectKey2 = ParameterParserUtil.parseStringParam(rs.getString("evh.ObjectKey2"), "");328 boolean isActive = ParameterParserUtil.parseBooleanParam(rs.getString("evh.isActive"), true);329 String hookConnector = ParameterParserUtil.parseStringParam(rs.getString("evh.hookConnector"), "");330 String hookRecipient = ParameterParserUtil.parseStringParam(rs.getString("evh.hookRecipient"), "");331 String hookChannel = ParameterParserUtil.parseStringParam(rs.getString("evh.hookChannel"), "");332 String description = ParameterParserUtil.parseStringParam(rs.getString("evh.description"), "");333 String usrCreated = ParameterParserUtil.parseStringParam(rs.getString("evh.usrCreated"), "");334 Timestamp dateCreated = rs.getTimestamp("evh.dateCreated");335 String usrModif = ParameterParserUtil.parseStringParam(rs.getString("evh.usrModif"), "");336 Timestamp dateModif = rs.getTimestamp("evh.dateModif");337 EventHook evtHookObj = factoryEventHook.create(id, eventReference, objectKey1, objectKey2, isActive, hookConnector, hookRecipient, hookChannel, description, usrCreated, dateCreated, usrModif, dateModif);...

Full Screen

Full Screen

loadFromResultSet

Using AI Code Generation

copy

Full Screen

1 public EventHook loadFromResultSet(ResultSet rs) throws SQLException {2 String id = ParameterParserUtil.parseStringParam(rs.getString("id"), "");3 String event = ParameterParserUtil.parseStringParam(rs.getString("event"), "");4 String script = ParameterParserUtil.parseStringParam(rs.getString("script"), "");5 String description = ParameterParserUtil.parseStringParam(rs.getString("description"), "");6 String active = ParameterParserUtil.parseStringParam(rs.getString("active"), "");7 String scriptType = ParameterParserUtil.parseStringParam(rs.getString("scriptType"), "");8 String scriptLib = ParameterParserUtil.parseStringParam(rs.getString("scriptLib"), "");9 String sort = ParameterParserUtil.parseStringParam(rs.getString("sort"), "");10 String system = ParameterParserUtil.parseStringParam(rs.getString("system"), "");11 int timeout = ParameterParserUtil.parseIntegerParam(rs.getString("timeout"), 0);12 String usrCreated = ParameterParserUtil.parseStringParam(rs.getString("usrCreated"), "");13 Timestamp dateCreated = rs.getTimestamp("dateCreated");14 String usrModif = ParameterParserUtil.parseStringParam(rs.getString("usrModif"), "");15 Timestamp dateModif = rs.getTimestamp("dateModif");16 return factoryEventHook.create(id, event, script, description, active, scriptType, scriptLib, sort, system, timeout, usrCreated, dateCreated, usrModif, dateModif);17 }18 public EventHook loadFromResultSet(ResultSet rs) throws SQLException {19 String id = ParameterParserUtil.parseStringParam(rs.getString("id"), "");20 String event = ParameterParserUtil.parseStringParam(rs.getString("event"), "");21 String script = ParameterParserUtil.parseStringParam(rs.getString("script"), "");22 String description = ParameterParserUtil.parseStringParam(rs.getString("description"), "");23 String active = ParameterParserUtil.parseStringParam(rs.getString("active"), "");24 String scriptType = ParameterParserUtil.parseStringParam(rs.getString("scriptType"), "");25 String scriptLib = ParameterParserUtil.parseStringParam(rs.getString("scriptLib"), "");26 String sort = ParameterParserUtil.parseStringParam(rs.getString("sort"), "");27 String system = ParameterParserUtil.parseStringParam(rs.getString("system"), "");28 int timeout = ParameterParserUtil.parseIntegerParam(rs.getString("timeout"), 0);

Full Screen

Full Screen

loadFromResultSet

Using AI Code Generation

copy

Full Screen

1 public EventHook loadFromResultSet(ResultSet rs) throws SQLException {2 Integer id = ParameterParserUtil.parseIntegerParam(rs.getString("id"), 0);3 String script = ParameterParserUtil.parseStringParam(rs.getString("script"), "");4 String description = ParameterParserUtil.parseStringParam(rs.getString("description"), "");5 String type = ParameterParserUtil.parseStringParam(rs.getString("type"), "");6 String system = ParameterParserUtil.parseStringParam(rs.getString("system"), "");7 String subsystem = ParameterParserUtil.parseStringParam(rs.getString("subsystem"), "");8 String event = ParameterParserUtil.parseStringParam(rs.getString("event"), "");9 String active = ParameterParserUtil.parseStringParam(rs.getString("active"), "");10 String sort = ParameterParserUtil.parseStringParam(rs.getString("sort"), "");11 String dateCreated = ParameterParserUtil.parseStringParam(rs.getString("dateCreated"), "");12 String usrCreated = ParameterParserUtil.parseStringParam(rs.getString("usrCreated"), "");13 String dateModif = ParameterParserUtil.parseStringParam(rs.getString("dateModif"), "");14 String usrModif = ParameterParserUtil.parseStringParam(rs.getString("usrModif"), "");15 EventHook eventHook = factoryEventHook.create(id, script, description, type, system, subsystem, event, active, sort, dateCreated, usrCreated, dateModif, usrModif);16 return eventHook;17 }

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