Best Cerberus-source code snippet using org.cerberus.crud.entity.CountryEnvParam.getType
Source:CountryEnvParamDAO.java  
...80                preStat.setString(5, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getRevision()));81                preStat.setString(6, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getChain()));82                preStat.setString(7, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getDistribList()));83                preStat.setString(8, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.geteMailBodyRevision()));84                preStat.setString(9, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getType()));85                preStat.setString(10, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.geteMailBodyChain()));86                preStat.setString(11, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.geteMailBodyDisableEnvironment()));87                if (countryEnvParam.isActive()) {88                    preStat.setString(12, "Y");89                } else {90                    preStat.setString(12, "%");91                }92                if (countryEnvParam.isMaintenanceAct()) {93                    preStat.setString(13, "Y");94                } else {95                    preStat.setString(13, "%");96                }97                preStat.setString(14, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getMaintenanceStr()));98                preStat.setString(15, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getMaintenanceEnd()));99                ResultSet resultSet = preStat.executeQuery();100                try {101                    while (resultSet.next()) {102                        result.add(this.loadFromResultSet(resultSet));103                    }104                } catch (SQLException exception) {105                    LOG.warn("Unable to execute query : " + exception.toString());106                } finally {107                    resultSet.close();108                }109            } catch (SQLException exception) {110                LOG.warn("Unable to execute query : " + exception.toString());111            } finally {112                preStat.close();113            }114        } catch (SQLException exception) {115            LOG.warn("Unable to execute query : " + exception.toString());116        } finally {117            try {118                if (connection != null) {119                    connection.close();120                }121            } catch (SQLException e) {122                LOG.warn(e.toString());123            }124        }125        if (throwex) {126            throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));127        }128        return result;129    }130    @Override131    public AnswerItem readByKey(String system, String country, String environment) {132        AnswerItem ans = new AnswerItem();133        CountryEnvParam result = null;134        final String query = "SELECT * FROM `countryenvparam` WHERE `system` = ? and `country` = ? and `environment` = ?";135        MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);136        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));137        Connection connection = this.databaseSpring.connect();138        try {139            PreparedStatement preStat = connection.prepareStatement(query);140            try {141                preStat.setString(1, system);142                preStat.setString(2, country);143                preStat.setString(3, environment);144                ResultSet resultSet = preStat.executeQuery();145                try {146                    if (resultSet.first()) {147                        result = loadFromResultSet(resultSet);148                        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);149                        msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));150                        ans.setItem(result);151                    } else {152                        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);153                    }154                } catch (SQLException exception) {155                    LOG.error("Unable to execute query : " + exception.toString());156                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);157                    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));158                } finally {159                    resultSet.close();160                }161            } catch (SQLException exception) {162                LOG.error("Unable to execute query : " + exception.toString());163                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);164                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));165            } finally {166                preStat.close();167            }168        } catch (SQLException exception) {169            LOG.error("Unable to execute query : " + exception.toString());170            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);171            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));172        } finally {173            try {174                if (connection != null) {175                    connection.close();176                }177            } catch (SQLException exception) {178                LOG.warn("Unable to close connection : " + exception.toString());179            }180        }181        //sets the message182        ans.setResultMessage(msg);183        return ans;184    }185    @Override186    public AnswerList readActiveBySystem(String system) {187        AnswerList response = new AnswerList();188        MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);189        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));190        List<CountryEnvParam> countryEnvParamList = new ArrayList<CountryEnvParam>();191        StringBuilder query = new StringBuilder();192        //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that 193        //were applied -- used for pagination p194        query.append("SELECT * FROM countryenvparam WHERE 1=1 ");195        if (system != null) {196            query.append("AND system = ? ");197        }198        query.append("AND active = 'Y'");199        // Debug message on SQL.200        if (LOG.isDebugEnabled()) {201            LOG.debug("SQL : " + query.toString());202        }203        Connection connection = this.databaseSpring.connect();204        try {205            PreparedStatement preStat = connection.prepareStatement(query.toString());206            try {207                if (system != null) {208                    preStat.setString(1, system);209                }210                ResultSet resultSet = preStat.executeQuery();211                try {212                    //gets the data213                    while (resultSet.next()) {214                        countryEnvParamList.add(this.loadFromResultSet(resultSet));215                    }216                    //get the total number of rows217                    resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");218                    int nrTotalRows = 0;219                    if (resultSet != null && resultSet.next()) {220                        nrTotalRows = resultSet.getInt(1);221                    }222                    if (countryEnvParamList.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.223                        LOG.error("Partial Result in the query.");224                        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);225                        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));226                        response = new AnswerList(countryEnvParamList, nrTotalRows);227                    } else {228                        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);229                        msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));230                        response = new AnswerList(countryEnvParamList, nrTotalRows);231                    }232                } catch (SQLException exception) {233                    LOG.error("Unable to execute query : " + exception.toString());234                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);235                    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));236                } finally {237                    if (resultSet != null) {238                        resultSet.close();239                    }240                }241            } catch (SQLException exception) {242                LOG.error("Unable to execute query : " + exception.toString());243                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);244                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));245            } finally {246                if (preStat != null) {247                    preStat.close();248                }249            }250        } catch (SQLException exception) {251            LOG.error("Unable to execute query : " + exception.toString());252            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);253            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));254        } finally {255            try {256                if (!this.databaseSpring.isOnTransaction()) {257                    if (connection != null) {258                        connection.close();259                    }260                }261            } catch (SQLException exception) {262                LOG.error("Unable to close connection : " + exception.toString());263            }264        }265        response.setResultMessage(msg);266        response.setDataList(countryEnvParamList);267        return response;268    }269    @Override270    public AnswerList readByCriteria(int start, int amount, String colName, String dir, String searchTerm, String individualSearch) {271        AnswerList response = new AnswerList();272        MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);273        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));274        List<CountryEnvParam> cepList = new ArrayList<CountryEnvParam>();275        StringBuilder searchSQL = new StringBuilder();276        StringBuilder query = new StringBuilder();277        //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that 278        //were applied -- used for pagination p279        query.append("SELECT SQL_CALC_FOUND_ROWS * FROM countryenvparam ");280        searchSQL.append(" where 1=1 ");281        if (!StringUtil.isNullOrEmpty(searchTerm)) {282            searchSQL.append(" and (`system` like '%").append(searchTerm).append("%'");283            searchSQL.append(" or `country` like '%").append(searchTerm).append("%'");284            searchSQL.append(" or `environment` like '%").append(searchTerm).append("%'");285            searchSQL.append(" or `description` like '%").append(searchTerm).append("%'");286            searchSQL.append(" or `build` like '%").append(searchTerm).append("%'");287            searchSQL.append(" or `revision` like '%").append(searchTerm).append("%'");288            searchSQL.append(" or `chain` like '%").append(searchTerm).append("%'");289            searchSQL.append(" or `distriblist` like '%").append(searchTerm).append("%'");290            searchSQL.append(" or `emailbodyrevision` like '%").append(searchTerm).append("%'");291            searchSQL.append(" or `type` like '%").append(searchTerm).append("%'");292            searchSQL.append(" or `emailbodychain` like '%").append(searchTerm).append("%'");293            searchSQL.append(" or `emailbodydisableenvironment` like '%").append(searchTerm).append("%'");294            searchSQL.append(" or `active` like '%").append(searchTerm).append("%'");295            searchSQL.append(" or `maintenanceact` like '%").append(searchTerm).append("%'");296            searchSQL.append(" or `maintenancestr` like '%").append(searchTerm).append("%'");297            searchSQL.append(" or `maintenanceend` like '%").append(searchTerm).append("%')");298        }299        if (!StringUtil.isNullOrEmpty(individualSearch)) {300            searchSQL.append(" and (`").append(individualSearch).append("`)");301        }302        query.append(searchSQL);303        if (!StringUtil.isNullOrEmpty(colName)) {304            query.append("order by `").append(colName).append("` ").append(dir);305        }306        if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {307            query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);308        } else {309            query.append(" limit ").append(start).append(" , ").append(amount);310        }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                    //gets the data318                    while (resultSet.next()) {319                        cepList.add(this.loadFromResultSet(resultSet));320                    }321                    //get the total number of rows322                    resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");323                    int nrTotalRows = 0;324                    if (resultSet != null && resultSet.next()) {325                        nrTotalRows = resultSet.getInt(1);326                    }327                    if (cepList.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.328                        LOG.error("Partial Result in the query.");329                        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);330                        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));331                        response = new AnswerList(cepList, nrTotalRows);332                    } else {333                        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);334                        msg.setDescription(msg.getDescription().replace("%ITEM%", "CountryEnvParam").replace("%OPERATION%", "SELECT"));335                        response = new AnswerList(cepList, nrTotalRows);336                    }337                } catch (SQLException exception) {338                    LOG.error("Unable to execute query : " + exception.toString());339                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);340                    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));341                } finally {342                    if (resultSet != null) {343                        resultSet.close();344                    }345                }346            } catch (SQLException exception) {347                LOG.error("Unable to execute query : " + exception.toString());348                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);349                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));350            } finally {351                if (preStat != null) {352                    preStat.close();353                }354            }355        } catch (SQLException exception) {356            LOG.error("Unable to execute query : " + exception.toString());357            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);358            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));359        } finally {360            try {361                if (!this.databaseSpring.isOnTransaction()) {362                    if (connection != null) {363                        connection.close();364                    }365                }366            } catch (SQLException exception) {367                LOG.warn("Unable to close connection : " + exception.toString());368            }369        }370        response.setResultMessage(msg);371        response.setDataList(cepList);372        return response;373    }374    @Override375    public AnswerList readByVariousByCriteria(String system, String country, String environment, String build, String revision, String active, String envGp, int start, int amount, String colName, String dir, String searchTerm, Map<String, List<String>> individualSearch) {376        AnswerList response = new AnswerList();377        MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);378        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));379        List<CountryEnvParam> cepList = new ArrayList<CountryEnvParam>();380        StringBuilder searchSQL = new StringBuilder();381        List<String> individalColumnSearchValues = new ArrayList<String>();382        StringBuilder query = new StringBuilder();383        //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that 384        //were applied -- used for pagination p385        query.append("SELECT SQL_CALC_FOUND_ROWS * FROM countryenvparam cep");386        if (!StringUtil.isNullOrEmpty(envGp)) {387            searchSQL.append(" LEFT OUTER JOIN invariant i on i.idname='ENVIRONMENT' and i.value=cep.environment ");388        }389        searchSQL.append(" where 1=1 ");390        if (!StringUtil.isNullOrEmpty(searchTerm)) {391            searchSQL.append(" and (`system` like ?");392            searchSQL.append(" or `country` like ?");393            searchSQL.append(" or `environment` like ?");394            searchSQL.append(" or `description` like ?");395            searchSQL.append(" or `build` like ?");396            searchSQL.append(" or `revision` like ?");397            searchSQL.append(" or `chain` like ?");398            searchSQL.append(" or `distriblist` like ?");399            searchSQL.append(" or `emailbodyrevision` like ?");400            searchSQL.append(" or `type` like ?");401            searchSQL.append(" or `emailbodychain` like ?");402            searchSQL.append(" or `emailbodydisableenvironment` like ?");403            searchSQL.append(" or `active` like ?");404            searchSQL.append(" or `maintenanceact` like ?");405            searchSQL.append(" or `maintenancestr` like ?");406            searchSQL.append(" or `maintenanceend` like ?)");407        }408        if (individualSearch != null && !individualSearch.isEmpty()) {409            searchSQL.append(" and ( 1=1 ");410            for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {411                searchSQL.append(" and ");412                searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));413                individalColumnSearchValues.addAll(entry.getValue());414            }415            searchSQL.append(" )");416        }417        if (!StringUtil.isNullOrEmpty(system)) {418            searchSQL.append(" and (`System` = ? )");419        }420        if (!StringUtil.isNullOrEmpty(active)) {421            searchSQL.append(" and (`active` = ? )");422        }423        if (!StringUtil.isNullOrEmpty(country)) {424            searchSQL.append(" and (`country` = ? )");425        }426        if (!StringUtil.isNullOrEmpty(environment)) {427            searchSQL.append(" and (`environment` = ? )");428        }429        if (!StringUtil.isNullOrEmpty(build)) {430            searchSQL.append(" and (`build` = ? )");431        }432        if (!StringUtil.isNullOrEmpty(revision)) {433            searchSQL.append(" and (`revision` = ? )");434        }435        if (!StringUtil.isNullOrEmpty(envGp)) {436            searchSQL.append(" and (i.`gp1` = ? )");437        }438        query.append(searchSQL);439        if (!StringUtil.isNullOrEmpty(colName)) {440            query.append(" order by `").append(colName).append("` ").append(dir);441        }442        if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {443            query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);444        } else {445            query.append(" limit ").append(start).append(" , ").append(amount);446        }447        // Debug message on SQL.448        if (LOG.isDebugEnabled()) {449            LOG.debug("SQL : " + query.toString());450        }451        Connection connection = this.databaseSpring.connect();452        try {453            PreparedStatement preStat = connection.prepareStatement(query.toString());454            try {455                int i = 1;456                if (!StringUtil.isNullOrEmpty(searchTerm)) {457                    preStat.setString(i++, "%" + searchTerm + "%");458                    preStat.setString(i++, "%" + searchTerm + "%");459                    preStat.setString(i++, "%" + searchTerm + "%");460                    preStat.setString(i++, "%" + searchTerm + "%");461                    preStat.setString(i++, "%" + searchTerm + "%");462                    preStat.setString(i++, "%" + searchTerm + "%");463                    preStat.setString(i++, "%" + searchTerm + "%");464                    preStat.setString(i++, "%" + searchTerm + "%");465                    preStat.setString(i++, "%" + searchTerm + "%");466                    preStat.setString(i++, "%" + searchTerm + "%");467                    preStat.setString(i++, "%" + searchTerm + "%");468                    preStat.setString(i++, "%" + searchTerm + "%");469                    preStat.setString(i++, "%" + searchTerm + "%");470                    preStat.setString(i++, "%" + searchTerm + "%");471                    preStat.setString(i++, "%" + searchTerm + "%");472                    preStat.setString(i++, "%" + searchTerm + "%");473                }474                for (String individualColumnSearchValue : individalColumnSearchValues) {475                    preStat.setString(i++, individualColumnSearchValue);476                }477                if (!StringUtil.isNullOrEmpty(system)) {478                    preStat.setString(i++, system);479                }480                if (!StringUtil.isNullOrEmpty(active)) {481                    preStat.setString(i++, active);482                }483                if (!StringUtil.isNullOrEmpty(country)) {484                    preStat.setString(i++, country);485                }486                if (!StringUtil.isNullOrEmpty(environment)) {487                    preStat.setString(i++, environment);488                }489                if (!StringUtil.isNullOrEmpty(build)) {490                    preStat.setString(i++, build);491                }492                if (!StringUtil.isNullOrEmpty(revision)) {493                    preStat.setString(i++, revision);494                }495                if (!StringUtil.isNullOrEmpty(envGp)) {496                    preStat.setString(i++, envGp);497                }498                ResultSet resultSet = preStat.executeQuery();499                try {500                    //gets the data501                    while (resultSet.next()) {502                        cepList.add(this.loadFromResultSet(resultSet));503                    }504                    //get the total number of rows505                    resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");506                    int nrTotalRows = 0;507                    if (resultSet != null && resultSet.next()) {508                        nrTotalRows = resultSet.getInt(1);509                    }510                    if (cepList.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.511                        LOG.error("Partial Result in the query.");512                        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);513                        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));514                        response = new AnswerList(cepList, nrTotalRows);515                    } else if (cepList.size() <= 0) {516                        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);517                        response = new AnswerList(cepList, nrTotalRows);518                    } else {519                        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);520                        msg.setDescription(msg.getDescription().replace("%ITEM%", "CountryEnvParam").replace("%OPERATION%", "SELECT"));521                        response = new AnswerList(cepList, nrTotalRows);522                    }523                } catch (SQLException exception) {524                    LOG.error("Unable to execute query : " + exception.toString());525                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);526                    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));527                } finally {528                    if (resultSet != null) {529                        resultSet.close();530                    }531                }532            } catch (SQLException exception) {533                LOG.error("Unable to execute query : " + exception.toString());534                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);535                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));536            } finally {537                if (preStat != null) {538                    preStat.close();539                }540            }541        } catch (SQLException exception) {542            LOG.error("Unable to execute query : " + exception.toString());543            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);544            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));545        } finally {546            try {547                if (!this.databaseSpring.isOnTransaction()) {548                    if (connection != null) {549                        connection.close();550                    }551                }552            } catch (SQLException exception) {553                LOG.warn("Unable to close connection : " + exception.toString());554            }555        }556        response.setResultMessage(msg);557        response.setDataList(cepList);558        return response;559    }560    @Override561    public AnswerList readDistinctEnvironmentByVariousByCriteria(String system, String country, String environment, String build, String revision, String active, String envGp, int start, int amount, String colName, String dir, String searchTerm, String individualSearch) {562        AnswerList response = new AnswerList();563        MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);564        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));565        List<CountryEnvParam> cepList = new ArrayList<CountryEnvParam>();566        StringBuilder searchSQL = new StringBuilder();567        StringBuilder query = new StringBuilder();568        //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that 569        //were applied -- used for pagination p570        query.append("SELECT SQL_CALC_FOUND_ROWS ");571        query.append(" max(system) system, max(country) country, Environment, '' Description,  ");572        query.append(" max(build) build, max(revision) revision, max(chain) chain, '' DistribList, ");573        query.append(" '' EMailBodyRevision, max(Type) type, '' EMailBodyChain, '' EMailBodyDisableEnvironment,  ");574        query.append(" max(Active) active, max(maintenanceact) maintenanceact, max(maintenancestr) maintenancestr, max(maintenanceend) maintenanceend ");575        query.append(" FROM countryenvparam cep ");576        if (!StringUtil.isNullOrEmpty(envGp)) {577            searchSQL.append(" LEFT OUTER JOIN invariant i on i.idname='ENVIRONMENT' and i.value=cep.environment ");578        }579        searchSQL.append(" where 1=1 ");580        if (!StringUtil.isNullOrEmpty(system)) {581            searchSQL.append(" and (`System` = ? )");582        }583        if (!StringUtil.isNullOrEmpty(active)) {584            searchSQL.append(" and (`active` = ? )");585        }586        if (!StringUtil.isNullOrEmpty(country)) {587            searchSQL.append(" and (`country` = ? )");588        }589        if (!StringUtil.isNullOrEmpty(environment)) {590            searchSQL.append(" and (`environment` = ? )");591        }592        if (!StringUtil.isNullOrEmpty(build)) {593            searchSQL.append(" and (`build` = ? )");594        }595        if (!StringUtil.isNullOrEmpty(revision)) {596            searchSQL.append(" and (`revision` = ? )");597        }598        if (!StringUtil.isNullOrEmpty(envGp)) {599            searchSQL.append(" and (i.`gp1` = ? )");600        }601        query.append(searchSQL);602        query.append(" group by `environment` ");603        query.append(" order by `environment` ");604        if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {605            query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);606        } else {607            query.append(" limit ").append(start).append(" , ").append(amount);608        }609        // Debug message on SQL.610        if (LOG.isDebugEnabled()) {611            LOG.debug("SQL : " + query.toString());612            LOG.debug("SQL.system : " + system);613            LOG.debug("SQL.active : " + active);614        }615        Connection connection = this.databaseSpring.connect();616        try {617            PreparedStatement preStat = connection.prepareStatement(query.toString());618            try {619                int i = 1;620                if (!StringUtil.isNullOrEmpty(system)) {621                    preStat.setString(i++, system);622                }623                if (!StringUtil.isNullOrEmpty(active)) {624                    preStat.setString(i++, active);625                }626                if (!StringUtil.isNullOrEmpty(country)) {627                    preStat.setString(i++, country);628                }629                if (!StringUtil.isNullOrEmpty(environment)) {630                    preStat.setString(i++, environment);631                }632                if (!StringUtil.isNullOrEmpty(build)) {633                    preStat.setString(i++, build);634                }635                if (!StringUtil.isNullOrEmpty(revision)) {636                    preStat.setString(i++, revision);637                }638                if (!StringUtil.isNullOrEmpty(envGp)) {639                    preStat.setString(i++, envGp);640                }641                ResultSet resultSet = preStat.executeQuery();642                try {643                    //gets the data644                    while (resultSet.next()) {645                        cepList.add(this.loadFromResultSet(resultSet));646                    }647                    //get the total number of rows648                    resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");649                    int nrTotalRows = 0;650                    if (resultSet != null && resultSet.next()) {651                        nrTotalRows = resultSet.getInt(1);652                    }653                    if (cepList.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.654                        LOG.error("Partial Result in the query.");655                        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);656                        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));657                        response = new AnswerList(cepList, nrTotalRows);658                    } else if (cepList.size() <= 0) {659                        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);660                        response = new AnswerList(cepList, nrTotalRows);661                    } else {662                        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);663                        msg.setDescription(msg.getDescription().replace("%ITEM%", "CountryEnvParam").replace("%OPERATION%", "SELECT"));664                        response = new AnswerList(cepList, nrTotalRows);665                    }666                } catch (SQLException exception) {667                    LOG.error("Unable to execute query : " + exception.toString());668                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);669                    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));670                } finally {671                    if (resultSet != null) {672                        resultSet.close();673                    }674                }675            } catch (SQLException exception) {676                LOG.error("Unable to execute query : " + exception.toString());677                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);678                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));679            } finally {680                if (preStat != null) {681                    preStat.close();682                }683            }684        } catch (SQLException exception) {685            LOG.error("Unable to execute query : " + exception.toString());686            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);687            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));688        } finally {689            try {690                if (!this.databaseSpring.isOnTransaction()) {691                    if (connection != null) {692                        connection.close();693                    }694                }695            } catch (SQLException exception) {696                LOG.warn("Unable to close connection : " + exception.toString());697            }698        }699        response.setResultMessage(msg);700        response.setDataList(cepList);701        return response;702    }703    @Override704    public Answer create(CountryEnvParam cep) {705        MessageEvent msg = null;706        StringBuilder query = new StringBuilder();707        query.append("INSERT INTO `countryenvparam`  (`system`, `country`, `environment`, `build`, `revision`,`chain`, `distriblist`, `eMailBodyRevision`, `type`,`eMailBodyChain`, ");708        query.append("`eMailBodyDisableEnvironment`,  `active`, `maintenanceact`, `maintenancestr`, `maintenanceend`, `description`) ");709        query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");710        // Debug message on SQL.711        if (LOG.isDebugEnabled()) {712            LOG.debug("SQL : " + query.toString());713        }714        Connection connection = this.databaseSpring.connect();715        try {716            PreparedStatement preStat = connection.prepareStatement(query.toString());717            try {718                preStat.setString(1, cep.getSystem());719                preStat.setString(2, cep.getCountry());720                preStat.setString(3, cep.getEnvironment());721                preStat.setString(4, cep.getBuild());722                preStat.setString(5, cep.getRevision());723                preStat.setString(6, cep.getChain());724                preStat.setString(7, cep.getDistribList());725                preStat.setString(8, cep.geteMailBodyRevision());726                preStat.setString(9, cep.getType());727                preStat.setString(10, cep.geteMailBodyChain());728                preStat.setString(11, cep.geteMailBodyDisableEnvironment());729                if (cep.isActive()) {730                    preStat.setString(12, "Y");731                } else {732                    preStat.setString(12, "N");733                }734                if (cep.isMaintenanceAct()) {735                    preStat.setString(13, "Y");736                } else {737                    preStat.setString(13, "N");738                }739                preStat.setString(14, cep.getMaintenanceStr());740                preStat.setString(15, cep.getMaintenanceEnd());741                preStat.setString(16, cep.getDescription());742                preStat.executeUpdate();743                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);744                msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));745            } catch (SQLException exception) {746                LOG.error("Unable to execute query : " + exception.toString());747                if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) { //23000 is the sql state for duplicate entries748                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);749                    msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));750                } else {751                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);752                    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));753                }754            } finally {755                preStat.close();756            }757        } catch (SQLException exception) {758            LOG.error("Unable to execute query : " + exception.toString());759            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);760            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));761        } finally {762            try {763                if (connection != null) {764                    connection.close();765                }766            } catch (SQLException exception) {767                LOG.warn("Unable to close connection : " + exception.toString());768            }769        }770        return new Answer(msg);771    }772    @Override773    public Answer delete(CountryEnvParam cep) {774        MessageEvent msg = null;775        final String query = "DELETE FROM `countryenvparam` WHERE `system`=? and `country`=? and `environment`=?";776        // Debug message on SQL.777        if (LOG.isDebugEnabled()) {778            LOG.debug("SQL : " + query);779        }780        Connection connection = this.databaseSpring.connect();781        try {782            PreparedStatement preStat = connection.prepareStatement(query);783            try {784                preStat.setString(1, cep.getSystem());785                preStat.setString(2, cep.getCountry());786                preStat.setString(3, cep.getEnvironment());787                preStat.executeUpdate();788                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);789                msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "DELETE"));790            } catch (SQLException exception) {791                LOG.error("Unable to execute query : " + exception.toString());792                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);793                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));794            } finally {795                preStat.close();796            }797        } catch (SQLException exception) {798            LOG.error("Unable to execute query : " + exception.toString());799            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);800            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));801        } finally {802            try {803                if (connection != null) {804                    connection.close();805                }806            } catch (SQLException exception) {807                LOG.warn("Unable to close connection : " + exception.toString());808            }809        }810        return new Answer(msg);811    }812    @Override813    public Answer update(CountryEnvParam cep) {814        MessageEvent msg = null;815        final StringBuilder query = new StringBuilder("UPDATE `countryenvparam` SET `build`=?, ");816        query.append("`revision`=?,`chain`=?, `distriblist`=?, `eMailBodyRevision`=?, `type`=?,`eMailBodyChain`=?,");817        query.append("`eMailBodyDisableEnvironment`=?,  `active`=?, `maintenanceact`=?, `maintenancestr`=?, `maintenanceend`=?, `description`=? ");818        query.append(" where `system`=? and `country`=? and `environment`=? ");819        // Debug message on SQL.820        if (LOG.isDebugEnabled()) {821            LOG.debug("SQL : " + query.toString());822            LOG.debug("SQL.param.maintenancestr : " + cep.getMaintenanceStr());823        }824        Connection connection = this.databaseSpring.connect();825        try {826            PreparedStatement preStat = connection.prepareStatement(query.toString());827            try {828                preStat.setString(1, ParameterParserUtil.parseStringParam(cep.getBuild(), ""));829                preStat.setString(2, cep.getRevision());830                preStat.setString(3, cep.getChain());831                preStat.setString(4, cep.getDistribList());832                preStat.setString(5, cep.geteMailBodyRevision());833                preStat.setString(6, cep.getType());834                preStat.setString(7, cep.geteMailBodyChain());835                preStat.setString(8, cep.geteMailBodyDisableEnvironment());836                if (cep.isActive()) {837                    preStat.setString(9, "Y");838                } else {839                    preStat.setString(9, "N");840                }841                if (cep.isMaintenanceAct()) {842                    preStat.setString(10, "Y");843                } else {844                    preStat.setString(10, "N");845                }846                preStat.setString(11, cep.getMaintenanceStr());847                preStat.setString(12, cep.getMaintenanceEnd());...Source:ExecutionStartService.java  
...353        LOG.debug("Checks performed -- > OK to continue.");354        /**355         * For GUI application, check if Browser is supported.356         */357        if (!tCExecution.getManualExecution().equals("Y") && tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {358            try {359                myInvariant = invariantService.convert(invariantService.readByKey("BROWSER", tCExecution.getBrowser()));360            } catch (CerberusException ex) {361                MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_BROWSER_NOT_SUPPORTED);362                mes.setDescription(mes.getDescription().replace("%BROWSER%", tCExecution.getBrowser()));363                LOG.debug(mes.getDescription());364                throw new CerberusException(mes);365            }366        }367        /**368         * Start server if execution is not manual369         */370        if (!tCExecution.getManualExecution().equals("Y")) {371            tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_STARTINGROBOTSERVER));372            if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)373                    || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)374                    || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)375                    || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {376                if (tCExecution.getIp().equalsIgnoreCase("")) {377                    MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_SELENIUM_EMPTYORBADIP);378                    mes.setDescription(mes.getDescription().replace("%IP%", tCExecution.getIp()));379                    LOG.debug(mes.getDescription());380                    throw new CerberusException(mes);381                }382                /**383                 * Start Selenium server384                 */385                LOG.debug("Starting Server.");386                tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_CREATINGRUNID));387                try {388                    this.serverService.startServer(tCExecution);389                } catch (CerberusException ex) {...getType
Using AI Code Generation
1public class 3 {2    public static void main(String[] args) {3        CountryEnvParam c = new CountryEnvParam();4        String type = c.getType();5        System.out.println(type);6    }7}getType
Using AI Code Generation
1CountryEnvParam cep = new CountryEnvParam();2String type = cep.getType();3cep.setType(type);4String country = cep.getCountry();5cep.setCountry(country);6String environment = cep.getEnvironment();7cep.setEnvironment(environment);8String ip = cep.getIp();9cep.setIp(ip);10String domain = cep.getDomain();11cep.setDomain(domain);12String build = cep.getBuild();13cep.setBuild(build);14String revision = cep.getRevision();15cep.setRevision(revision);16String chain = cep.getChain();17cep.setChain(chain);18String distribList = cep.getDistribList();19cep.setDistribList(distribList);getType
Using AI Code Generation
1type = countryEnvParam.getType();2type = application.getType();3type = testCase.getType();4type = application.getType();5type = countryEnvParam.getType();6type = testCase.getType();7type = application.getType();8type = application.getType();9type = application.getType();10type = countryEnvParam.getType();11type = testCase.getType();12type = application.getType();13type = application.getType();14type = application.getType();15type = countryEnvParam.getType();16type = application.getType();getType
Using AI Code Generation
1import org.cerberus.crud.entity.CountryEnvParam;2import org.cerberus.crud.entity.CountryEnvParam;3public class 3 {4    public static void main(String[] args) {5        CountryEnvParam countryEnvParam = new CountryEnvParam();6        System.out.println("The type of the object is: " + countryEnvParam.getType());7    }8}getType
Using AI Code Generation
1public class 3 {2    public static void main(String[] args) {3        CountryEnvParam cep = new CountryEnvParam();4        System.out.println(cep.getType());5    }6}7public class 4 {8    public static void main(String[] args) {9        CountryEnvParam cep = new CountryEnvParam();10        cep.setType("type");11        System.out.println(cep.getType());12    }13}14public class 5 {15    public static void main(String[] args) {16        CountryEnvParam cep = new CountryEnvParam();17        cep.setType("type");18        System.out.println(cep.getType());19    }20}21public class 6 {22    public static void main(String[] args) {23        CountryEnvParam cep = new CountryEnvParam();24        cep.setType("type");25        System.out.println(cep.getType());26    }27}28public class 7 {29    public static void main(String[] args) {30        CountryEnvParam cep = new CountryEnvParam();31        cep.setType("type");32        System.out.println(cep.getType());33    }34}35public class 8 {36    public static void main(String[] args) {37        CountryEnvParam cep = new CountryEnvParam();38        cep.setType("type");39        System.out.println(cep.getType());40    }41}42public class 9 {43    public static void main(String[] args) {44        CountryEnvParam cep = new CountryEnvParam();45        cep.setType("type");46        System.out.println(cep.getType());47    }48}getType
Using AI Code Generation
1package org.cerberus.crud.entity;2import java.util.ArrayList;3import java.util.List;4public class CountryEnvParam {5    private CountryEnvParamPK key;6    private String type;7    private String description;8    private String system;9    private String database;10    private String url;11    private String ip;12    private String domain;13    private String dns;14    private String databaseUrl;15    private String databaseIp;16    private String databaseName;17    private String databaseLogin;18    private String databasePassword;19    private String databaseScript;20    private String databaseScriptError;21    private String databaseScriptTag;22    private String databaseScriptLocation;23    private String databaseScriptFilename;24    private String databaseScriptSeparator;25    private String databaseScriptDelimiter;26    private String databaseScriptIndex;27    private String databaseScriptNbLines;28    private String databaseScriptNbLinesExecuted;29    private String databaseScriptNbLinesError;30    private String databaseScriptNbLinesWarning;31    private String databaseScriptNbLinesSkipped;32    private String databaseScriptNbLinesInserted;33    private String databaseScriptNbLinesUpdated;34    private String databaseScriptNbLinesDeleted;35    private String databaseScriptNbLinesSelected;36    private String databaseScriptNbLinesProcessed;37    private String databaseScriptNbLinesRead;38    private String databaseScriptNbLinesWritten;39    private String databaseScriptNbLinesRejected;40    private String databaseScriptNbLinesDiscarded;41    private String databaseScriptNbLinesUnknown;42    private String databaseScriptNbLinesEmpty;43    private String databaseScriptNbLinesComment;44    private String databaseScriptNbLinesTotal;45    private String databaseScriptNbLinesTotalExecuted;46    private String databaseScriptNbLinesTotalError;47    private String databaseScriptNbLinesTotalWarning;48    private String databaseScriptNbLinesTotalSkipped;49    private String databaseScriptNbLinesTotalInserted;50    private String databaseScriptNbLinesTotalUpdated;51    private String databaseScriptNbLinesTotalDeleted;52    private String databaseScriptNbLinesTotalSelected;53    private String databaseScriptNbLinesTotalProcessed;54    private String databaseScriptNbLinesTotalRead;55    private String databaseScriptNbLinesTotalWritten;56    private String databaseScriptNbLinesTotalRejected;57    private String databaseScriptNbLinesTotalDiscarded;58    private String databaseScriptNbLinesTotalUnknown;59    private String databaseScriptNbLinesTotalEmpty;60    private String databaseScriptNbLinesTotalComment;61    private String databaseScriptNbFiles;getType
Using AI Code Generation
1package org.cerberus.crud.entity;2import java.lang.reflect.Method;3import java.lang.reflect.Type;4public class CountryEnvParam {5    public static void main(String[] args) throws Exception {6        Class<?> clazz = Class.forName("org.cerberus.crud.entity.CountryEnvParam");7        Method method = clazz.getMethod("getType");8        Type type = method.getGenericReturnType();9        System.out.println(type);10    }11}12public Class<CountryEnvParam> getType() {13    return type;14}15public Class<CountryEnvParam> getType() {16    return type;17}getType
Using AI Code Generation
1package org.cerberus.crud.entity;2import java.util.Objects;3public class CountryEnvParam {4    private String system;5    private String country;6    private String environment;7    private String build;8    private String revision;9    private String chain;10    private String distribList;11    private String type;12    private String database;13    private String url;14    private String ip;15    private String port;16    private String login;17    private String password;18    private String database1;19    private String url1;20    private String ip1;21    private String port1;22    private String login1;23    private String password1;24    private String database2;25    private String url2;26    private String ip2;27    private String port2;28    private String login2;29    private String password2;30    private String database3;31    private String url3;32    private String ip3;33    private String port3;34    private String login3;35    private String password3;36    private String database4;37    private String url4;38    private String ip4;39    private String port4;40    private String login4;41    private String password4;42    private String database5;43    private String url5;44    private String ip5;45    private String port5;46    private String login5;47    private String password5;48    private String database6;49    private String url6;50    private String ip6;51    private String port6;52    private String login6;53    private String password6;54    private String database7;55    private String url7;56    private String ip7;57    private String port7;58    private String login7;59    private String password7;60    private String database8;61    private String url8;62    private String ip8;63    private String port8;64    private String login8;65    private String password8;66    private String database9;67    private String url9;68    private String ip9;69    private String port9;70    private String login9;71    private String password9;72    private String database10;73    private String url10;74    private String ip10;75    private String port10;76    private String login10;77    private String password10;78    private String database11;79    private String url11;80    private String ip11;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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
