How to use getDatabase method of org.cerberus.crud.entity.SqlLibrary class

Best Cerberus-source code snippet using org.cerberus.crud.entity.SqlLibrary.getDatabase

Source:SqlLibraryDAO.java Github

copy

Full Screen

...136 preStat.setString(1, sqlLibrary.getType());137 preStat.setString(2, sqlLibrary.getName());138 preStat.setString(3, sqlLibrary.getScript());139 preStat.setString(4, sqlLibrary.getDescription());140 preStat.setString(5, sqlLibrary.getDatabase());141 preStat.executeUpdate();142 throwExcep = false;143 } catch (SQLException exception) {144 LOG.warn("Unable to execute query : " + exception.toString());145 } finally {146 preStat.close();147 }148 } catch (SQLException exception) {149 LOG.warn("Unable to execute query : " + exception.toString());150 } finally {151 try {152 if (connection != null) {153 connection.close();154 }155 } catch (SQLException e) {156 LOG.warn(e.toString());157 }158 }159 if (throwExcep) {160 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));161 }162 }163 @Override164 public void updateSqlLibrary(SqlLibrary sqlLibrary) throws CerberusException {165 boolean throwExcep = false;166 StringBuilder query = new StringBuilder();167 query.append("update sqllibrary set `script`=?,`description`=?, `type`=?, `database`=? where `name`=? ");168 Connection connection = this.databaseSpring.connect();169 try {170 PreparedStatement preStat = connection.prepareStatement(query.toString());171 try {172 preStat.setString(1, sqlLibrary.getScript());173 preStat.setString(2, sqlLibrary.getDescription());174 preStat.setString(3, sqlLibrary.getType());175 preStat.setString(4, sqlLibrary.getDatabase());176 preStat.setString(5, sqlLibrary.getName());177 preStat.executeUpdate();178 throwExcep = false;179 } catch (SQLException exception) {180 LOG.warn("Unable to execute query : " + exception.toString());181 } finally {182 preStat.close();183 }184 } catch (SQLException exception) {185 LOG.warn("Unable to execute query : " + exception.toString());186 } finally {187 try {188 if (connection != null) {189 connection.close();190 }191 } catch (SQLException e) {192 LOG.warn(e.toString());193 }194 }195 if (throwExcep) {196 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));197 }198 }199 @Override200 public void deleteSqlLibrary(SqlLibrary sqlLibrary) throws CerberusException {201 boolean throwExcep = false;202 StringBuilder query = new StringBuilder();203 query.append("delete from sqllibrary where `Name`=? ");204 Connection connection = this.databaseSpring.connect();205 try {206 PreparedStatement preStat = connection.prepareStatement(query.toString());207 try {208 preStat.setString(1, sqlLibrary.getName());209 preStat.executeUpdate();210 throwExcep = false;211 } catch (SQLException exception) {212 LOG.warn("Unable to execute query : " + exception.toString());213 } finally {214 preStat.close();215 }216 } catch (SQLException exception) {217 LOG.warn("Unable to execute query : " + exception.toString());218 } finally {219 try {220 if (connection != null) {221 connection.close();222 }223 } catch (SQLException e) {224 LOG.warn(e.toString());225 }226 }227 if (throwExcep) {228 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));229 }230 }231 @Override232 public List<SqlLibrary> findAllSqlLibrary() {233 List<SqlLibrary> list = null;234 final String query = "SELECT * FROM SqlLibrary";235 Connection connection = this.databaseSpring.connect();236 try {237 PreparedStatement preStat = connection.prepareStatement(query);238 try {239 ResultSet resultSet = preStat.executeQuery();240 list = new ArrayList<SqlLibrary>();241 try {242 while (resultSet.next()) {243 list.add(this.loadSqlLibraryFromResultSet(resultSet));244 }245 } catch (SQLException exception) {246 LOG.warn("Unable to execute query : " + exception.toString());247 } finally {248 resultSet.close();249 }250 } catch (SQLException exception) {251 LOG.warn("Unable to execute query : " + exception.toString());252 } finally {253 preStat.close();254 }255 } catch (SQLException exception) {256 LOG.warn("Unable to execute query : " + exception.toString());257 } finally {258 try {259 if (connection != null) {260 connection.close();261 }262 } catch (SQLException e) {263 LOG.warn(e.toString());264 }265 }266 return list;267 }268 @Override269 public List<SqlLibrary> findSqlLibraryListByCriteria(int start, int amount, String column, String dir, String searchTerm, String individualSearch) {270 List<SqlLibrary> sqlLibraryList = new ArrayList<SqlLibrary>();271 StringBuilder gSearch = new StringBuilder();272 StringBuilder searchSQL = new StringBuilder();273 StringBuilder query = new StringBuilder();274 query.append("SELECT * FROM sqllibrary ");275 gSearch.append(" where (`type` like '%");276 gSearch.append(searchTerm);277 gSearch.append("%'");278 gSearch.append(" or `name` like '%");279 gSearch.append(searchTerm);280 gSearch.append("%'");281 gSearch.append(" or `database` like '%");282 gSearch.append(searchTerm);283 gSearch.append("%'");284 gSearch.append(" or `script` like '%");285 gSearch.append(searchTerm);286 gSearch.append("%'");287 gSearch.append(" or `description` like '%");288 gSearch.append(searchTerm);289 gSearch.append("%')");290 if (!searchTerm.equals("") && !individualSearch.equals("")) {291 searchSQL.append(gSearch.toString());292 searchSQL.append(" and ");293 searchSQL.append(individualSearch);294 } else if (!individualSearch.equals("")) {295 searchSQL.append(" where `");296 searchSQL.append(individualSearch);297 searchSQL.append("`");298 } else if (!searchTerm.equals("")) {299 searchSQL.append(gSearch.toString());300 }301 query.append(searchSQL);302 query.append("order by `");303 query.append(column);304 query.append("` ");305 query.append(dir);306 query.append(" limit ");307 query.append(start);308 query.append(" , ");309 query.append(amount);310 SqlLibrary sqlLibrary;311 Connection connection = this.databaseSpring.connect();312 try {313 PreparedStatement preStat = connection.prepareStatement(query.toString());314 try {315 ResultSet resultSet = preStat.executeQuery();316 try {317 while (resultSet.next()) {318 sqlLibraryList.add(this.loadSqlLibraryFromResultSet(resultSet));319 }320 } catch (SQLException exception) {321 LOG.warn("Unable to execute query : " + exception.toString());322 } finally {323 resultSet.close();324 }325 } catch (SQLException exception) {326 LOG.warn("Unable to execute query : " + exception.toString());327 } finally {328 preStat.close();329 }330 } catch (SQLException exception) {331 LOG.warn("Unable to execute query : " + exception.toString());332 } finally {333 try {334 if (connection != null) {335 connection.close();336 }337 } catch (SQLException e) {338 LOG.warn(e.toString());339 }340 }341 return sqlLibraryList;342 }343 private SqlLibrary loadSqlLibraryFromResultSet(ResultSet resultSet) throws SQLException {344 String name = resultSet.getString("name");345 String type = resultSet.getString("type");346 String database = resultSet.getString("database");347 String script = resultSet.getString("script");348 String description = resultSet.getString("description");349 return factorySqlLib.create(name, type, database, script, description);350 }351 @Override352 public void updateSqlLibrary(String name, String columnName, String value) throws CerberusException {353 boolean throwExcep = false;354 StringBuilder query = new StringBuilder();355 query.append("update sqllibrary set `");356 query.append(columnName);357 query.append("`=? where `name`=? ");358 Connection connection = this.databaseSpring.connect();359 try {360 PreparedStatement preStat = connection.prepareStatement(query.toString());361 try {362 preStat.setString(1, value);363 preStat.setString(2, name);364 preStat.executeUpdate();365 throwExcep = false;366 } catch (SQLException exception) {367 LOG.warn("Unable to execute query : " + exception.toString());368 } finally {369 preStat.close();370 }371 } catch (SQLException exception) {372 LOG.warn("Unable to execute query : " + exception.toString());373 } finally {374 try {375 if (connection != null) {376 connection.close();377 }378 } catch (SQLException e) {379 LOG.warn(e.toString());380 }381 }382 if (throwExcep) {383 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));384 }385 }386 @Override387 public Integer getNumberOfSqlLibraryPerCriteria(String searchTerm, String inds) {388 Integer result = 0;389 StringBuilder query = new StringBuilder();390 StringBuilder gSearch = new StringBuilder();391 String searchSQL = "";392 query.append("SELECT count(*) FROM sqllibrary");393 gSearch.append(" where (`name` like '%");394 gSearch.append(searchTerm);395 gSearch.append("%'");396 gSearch.append(" or `type` like '%");397 gSearch.append(searchTerm);398 gSearch.append("%'");399 gSearch.append(" or `database` like '%");400 gSearch.append(searchTerm);401 gSearch.append("%'");402 gSearch.append(" or `script` like '%");403 gSearch.append(searchTerm);404 gSearch.append("%'");405 gSearch.append(" or `description` like '%");406 gSearch.append(searchTerm);407 gSearch.append("%')");408 if (!searchTerm.equals("") && !inds.equals("")) {409 searchSQL = gSearch.toString() + " and " + inds;410 } else if (!inds.equals("")) {411 searchSQL = " where " + inds;412 } else if (!searchTerm.equals("")) {413 searchSQL = gSearch.toString();414 }415 query.append(searchSQL);416 Connection connection = this.databaseSpring.connect();417 try {418 PreparedStatement preStat = connection.prepareStatement(query.toString());419 try {420 ResultSet resultSet = preStat.executeQuery();421 try {422 if (resultSet.first()) {423 result = resultSet.getInt(1);424 }425 } catch (SQLException exception) {426 LOG.warn("Unable to execute query : " + exception.toString());427 } finally {428 resultSet.close();429 }430 } catch (SQLException exception) {431 LOG.warn("Unable to execute query : " + exception.toString());432 } finally {433 preStat.close();434 }435 } catch (SQLException exception) {436 LOG.warn("Unable to execute query : " + exception.toString());437 } finally {438 try {439 if (connection != null) {440 connection.close();441 }442 } catch (SQLException e) {443 LOG.warn(e.toString());444 }445 }446 return result;447 }448 @Override449 public List<String> findDistinctTypeOfSqlLibrary() {450 List<String> list = null;451 final String query = "SELECT DISTINCT Type FROM SqlLibrary";452 try(Connection connection = this.databaseSpring.connect();453 PreparedStatement preStat = connection.prepareStatement(query);454 ResultSet resultSet = preStat.executeQuery();) {455 list = new ArrayList<String>();456 while (resultSet.next()) {457 list.add(resultSet.getString("Type"));458 }459 } catch (SQLException exception) {460 LOG.warn("Unable to execute query : " + exception.toString());461 }462 return list;463 }464 @Override465 public AnswerList readByCriteria(int start, int amount, String column, String dir, String searchTerm, Map<String, List<String>> individualSearch) {466 AnswerList response = new AnswerList();467 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);468 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));469 List<SqlLibrary> objectList = new ArrayList<SqlLibrary>();470 StringBuilder searchSQL = new StringBuilder();471 List<String> individalColumnSearchValues = new ArrayList<String>();472 StringBuilder query = new StringBuilder();473 //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that474 //were applied -- used for pagination p475 query.append("SELECT SQL_CALC_FOUND_ROWS * FROM sqllibrary `sql` ");476 query.append(" WHERE 1=1");477 if (!StringUtil.isNullOrEmpty(searchTerm)) {478 searchSQL.append(" and (`sql`.Name like ?");479 searchSQL.append(" or `sql`.Type like ?");480 searchSQL.append(" or `sql`.Database like ?");481 searchSQL.append(" or `sql`.description like ?");482 searchSQL.append(" or `sql`.script like ?)");483 }484 if (individualSearch != null && !individualSearch.isEmpty()) {485 searchSQL.append(" and ( 1=1 ");486 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {487 searchSQL.append(" and ");488 String q = SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue());489 if (q == null || q == "") {490 q = "(`sql`." + entry.getKey() + " IS NULL OR " + entry.getKey() + " = '')";491 }492 searchSQL.append(q);493 individalColumnSearchValues.addAll(entry.getValue());494 }495 searchSQL.append(" )");496 }497 query.append(searchSQL);498 if (!StringUtil.isNullOrEmpty(column)) {499 query.append(" order by `sql`.").append(column).append(" ").append(dir);500 }501 if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {502 query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);503 } else {504 query.append(" limit ").append(start).append(" , ").append(amount);505 }506 // Debug message on SQL.507 if (LOG.isDebugEnabled()) {508 LOG.debug("SQL : " + query.toString());509 }510 Connection connection = this.databaseSpring.connect();511 try {512 PreparedStatement preStat = connection.prepareStatement(query.toString());513 try {514 int i = 1;515 if (!StringUtil.isNullOrEmpty(searchTerm)) {516 preStat.setString(i++, "%" + searchTerm + "%");517 preStat.setString(i++, "%" + searchTerm + "%");518 preStat.setString(i++, "%" + searchTerm + "%");519 preStat.setString(i++, "%" + searchTerm + "%");520 preStat.setString(i++, "%" + searchTerm + "%");521 }522 for (String individualColumnSearchValue : individalColumnSearchValues) {523 preStat.setString(i++, individualColumnSearchValue);524 }525 ResultSet resultSet = preStat.executeQuery();526 try {527 //gets the data528 while (resultSet.next()) {529 objectList.add(this.loadFromResultSet(resultSet));530 }531 //get the total number of rows532 resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");533 int nrTotalRows = 0;534 if (resultSet != null && resultSet.next()) {535 nrTotalRows = resultSet.getInt(1);536 }537 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.538 LOG.error("Partial Result in the query.");539 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);540 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));541 response = new AnswerList(objectList, nrTotalRows);542 } else if (objectList.size() <= 0) {543 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);544 response = new AnswerList(objectList, nrTotalRows);545 } else {546 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);547 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));548 response = new AnswerList(objectList, nrTotalRows);549 }550 } catch (SQLException exception) {551 LOG.error("Unable to execute query : " + exception.toString());552 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);553 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));554 } finally {555 if (resultSet != null) {556 resultSet.close();557 }558 }559 } catch (SQLException exception) {560 LOG.error("Unable to execute query : " + exception.toString());561 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);562 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));563 } finally {564 if (preStat != null) {565 preStat.close();566 }567 }568 } catch (SQLException exception) {569 LOG.error("Unable to execute query : " + exception.toString());570 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);571 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));572 } finally {573 try {574 if (!this.databaseSpring.isOnTransaction()) {575 if (connection != null) {576 connection.close();577 }578 }579 } catch (SQLException exception) {580 LOG.warn("Unable to close connection : " + exception.toString());581 }582 }583 response.setResultMessage(msg);584 response.setDataList(objectList);585 return response;586 }587 @Override588 public AnswerItem readByKey(String key) {589 AnswerItem a = new AnswerItem();590 StringBuilder query = new StringBuilder();591 SqlLibrary p = new SqlLibrary();592 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);593 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));594 query.append("SELECT * FROM sqllibrary `sql` WHERE Name = ?");595 596 try(Connection connection = this.databaseSpring.connect();597 PreparedStatement preStat = connection.prepareStatement(query.toString());) {598 preStat.setString(1, key);599 try(ResultSet resultSet = preStat.executeQuery()){600 //gets the data601 while (resultSet.next()) {602 p = this.loadFromResultSet(resultSet);603 }604 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);605 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));606 }catch (SQLException e) {607 LOG.error("Unable to execute query : " + e.toString());608 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);609 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", e.toString()));610 }611 } catch (SQLException e) {612 LOG.error("Unable to execute query : " + e.toString());613 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);614 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", e.toString()));615 } 616 a.setResultMessage(msg);617 a.setItem(p);618 return a;619 }620 @Override621 public SqlLibrary loadFromResultSet(ResultSet rs) throws SQLException {622 String name = ParameterParserUtil.parseStringParam(rs.getString("Name"), "");623 String type = ParameterParserUtil.parseStringParam(rs.getString("Type"), "");624 String db = ParameterParserUtil.parseStringParam(rs.getString("Database"), "");625 String script = ParameterParserUtil.parseStringParam(rs.getString("Script"), "");626 String description = ParameterParserUtil.parseStringParam(rs.getString("Description"), "");627 //TODO remove when working in test with mockito and autowired628 factorySqlLib = new FactorySqlLibrary();629 return factorySqlLib.create(name, type, db, script, description);630 }631 @Override632 public AnswerList<String> readDistinctValuesByCriteria(String searchTerm, Map<String, List<String>> individualSearch, String columnName) {633 AnswerList answer = new AnswerList();634 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);635 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));636 List<String> distinctValues = new ArrayList<>();637 StringBuilder searchSQL = new StringBuilder();638 List<String> individalColumnSearchValues = new ArrayList<String>();639 StringBuilder query = new StringBuilder();640 query.append("SELECT distinct `sql`.");641 query.append(columnName);642 query.append(" as distinctValues FROM sqllibrary `sql`");643 query.append(" where 1=1");644 if (!StringUtil.isNullOrEmpty(searchTerm)) {645 searchSQL.append(" and (`sql`.Name like ?");646 searchSQL.append(" or `sql`.Type like ?");647 searchSQL.append(" or `sql`.Database like ?");648 searchSQL.append(" or `sql`.description like ?");649 searchSQL.append(" or `sql`.script like ?)");650 }651 if (individualSearch != null && !individualSearch.isEmpty()) {652 searchSQL.append(" and ( 1=1 ");653 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {654 searchSQL.append(" and `sql`.");655 searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));656 individalColumnSearchValues.addAll(entry.getValue());657 }658 searchSQL.append(" )");659 }660 query.append(searchSQL);661 query.append(" group by ifnull(`sql`.").append(columnName).append(",'')");662 query.append(" order by `sql`.").append(columnName).append(" asc");663 // Debug message on SQL.664 if (LOG.isDebugEnabled()) {665 LOG.debug("SQL : " + query.toString());666 }667 try (Connection connection = databaseSpring.connect();668 PreparedStatement preStat = connection.prepareStatement(query.toString());669 Statement stm = connection.createStatement();) {670 int i = 1;671 if (!StringUtil.isNullOrEmpty(searchTerm)) {672 preStat.setString(i++, "%" + searchTerm + "%");673 preStat.setString(i++, "%" + searchTerm + "%");674 preStat.setString(i++, "%" + searchTerm + "%");675 preStat.setString(i++, "%" + searchTerm + "%");676 preStat.setString(i++, "%" + searchTerm + "%");677 }678 for (String individualColumnSearchValue : individalColumnSearchValues) {679 preStat.setString(i++, individualColumnSearchValue);680 }681 682 try(ResultSet resultSet = preStat.executeQuery();683 ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()");) {684 //gets the data685 while (resultSet.next()) {686 distinctValues.add(resultSet.getString("distinctValues") == null ? "" : resultSet.getString("distinctValues"));687 }688 //get the total number of rows689 690 int nrTotalRows = 0;691 if (rowSet != null && rowSet.next()) {692 nrTotalRows = rowSet.getInt(1);693 }694 if (distinctValues.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.695 LOG.error("Partial Result in the query.");696 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);697 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));698 answer = new AnswerList(distinctValues, nrTotalRows);699 } else if (distinctValues.size() <= 0) {700 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);701 answer = new AnswerList(distinctValues, nrTotalRows);702 } else {703 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);704 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));705 answer = new AnswerList(distinctValues, nrTotalRows);706 }707 }catch (SQLException exception) {708 LOG.error("Unable to execute query : " + exception.toString());709 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);710 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));711 } 712 } catch (Exception e) {713 LOG.warn("Unable to execute query : " + e.toString());714 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",715 e.toString());716 } finally {717 // We always set the result message718 answer.setResultMessage(msg);719 }720 answer.setResultMessage(msg);721 answer.setDataList(distinctValues);722 return answer;723 }724 @Override725 public Answer create(SqlLibrary object) {726 MessageEvent msg = null;727 StringBuilder query = new StringBuilder();728 query.append("INSERT INTO sqllibrary (`Name`, `Type`, `Database`, `Script`, `Description`) ");729 query.append("VALUES (?,?,?,?,?)");730 // Debug message on SQL.731 if (LOG.isDebugEnabled()) {732 LOG.debug("SQL : " + query.toString());733 }734 Connection connection = this.databaseSpring.connect();735 try {736 PreparedStatement preStat = connection.prepareStatement(query.toString());737 try {738 preStat.setString(1, object.getName());739 preStat.setString(2, object.getType());740 preStat.setString(3, object.getDatabase());741 preStat.setString(4, object.getScript());742 preStat.setString(5, object.getDescription());743 preStat.executeUpdate();744 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);745 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));746 } catch (SQLException exception) {747 LOG.error("Unable to execute query : " + exception.toString());748 if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) { //23000 is the sql state for duplicate entries749 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);750 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));751 } else {752 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);753 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));754 }755 } finally {756 preStat.close();757 }758 } catch (SQLException exception) {759 LOG.error("Unable to execute query : " + exception.toString());760 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);761 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));762 } finally {763 try {764 if (connection != null) {765 connection.close();766 }767 } catch (SQLException exception) {768 LOG.error("Unable to close connection : " + exception.toString());769 }770 }771 return new Answer(msg);772 }773 @Override774 public Answer delete(SqlLibrary object) {775 MessageEvent msg = null;776 final String query = "DELETE FROM sqllibrary WHERE name = ? ";777 // Debug message on SQL.778 if (LOG.isDebugEnabled()) {779 LOG.debug("SQL : " + query);780 }781 Connection connection = this.databaseSpring.connect();782 try {783 PreparedStatement preStat = connection.prepareStatement(query);784 try {785 preStat.setString(1, object.getName());786 preStat.executeUpdate();787 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);788 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "DELETE"));789 } catch (SQLException exception) {790 LOG.error("Unable to execute query : " + exception.toString());791 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);792 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));793 } finally {794 preStat.close();795 }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 try {802 if (connection != null) {803 connection.close();804 }805 } catch (SQLException exception) {806 LOG.warn("Unable to close connection : " + exception.toString());807 }808 }809 return new Answer(msg);810 }811 @Override812 public Answer update(SqlLibrary object) {813 MessageEvent msg = null;814 final String query = "UPDATE sqllibrary SET Type = ?, `Database` = ?, `Script` = ?, Description = ? WHERE Name = ?";815 // Debug message on SQL.816 if (LOG.isDebugEnabled()) {817 LOG.debug("SQL : " + query);818 }819 Connection connection = this.databaseSpring.connect();820 try {821 PreparedStatement preStat = connection.prepareStatement(query);822 try {823 preStat.setString(1, object.getType());824 preStat.setString(2, object.getDatabase());825 preStat.setString(3, object.getScript());826 preStat.setString(4, object.getDescription());827 preStat.setString(5, object.getName());828 preStat.executeUpdate();829 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);830 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));831 } catch (SQLException exception) {832 LOG.error("Unable to execute query : " + exception.toString());833 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);834 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));835 } finally {836 preStat.close();837 }838 } catch (SQLException exception) {...

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