use of org.cerberus.crud.entity.CountryEnvParam in project cerberus-source by cerberustesting.
the class CountryEnvParamDAO method findCountryEnvParamByCriteria.
@Override
public List<CountryEnvParam> findCountryEnvParamByCriteria(CountryEnvParam countryEnvParam) throws CerberusException {
List<CountryEnvParam> result = new ArrayList();
boolean throwex = false;
StringBuilder query = new StringBuilder();
query.append("SELECT `system`, `country`, `environment`, `Build`, `Revision`,`chain`, `distriblist`, `eMailBodyRevision`, `type`,`eMailBodyChain`, `eMailBodyDisableEnvironment`, `active`, `maintenanceact`, ");
query.append(" `maintenancestr`, `maintenanceend`, `Description` FROM countryenvparam WHERE `system` LIKE ? AND `country` LIKE ? ");
query.append("AND `environment` LIKE ? AND `build` LIKE ? AND `Revision` LIKE ? AND `chain` LIKE ? ");
query.append("AND `distriblist` LIKE ? AND `eMailBodyRevision` LIKE ? AND `type` LIKE ? AND `eMailBodyChain` LIKE ? ");
query.append("AND `eMailBodyDisableEnvironment` LIKE ? AND `active` LIKE ? AND `maintenanceact` LIKE ? AND `maintenancestr` LIKE ? ");
query.append("AND `maintenanceend` LIKE ? ");
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
preStat.setString(1, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getSystem()));
preStat.setString(2, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getCountry()));
preStat.setString(3, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getEnvironment()));
preStat.setString(4, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getBuild()));
preStat.setString(5, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getRevision()));
preStat.setString(6, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getChain()));
preStat.setString(7, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getDistribList()));
preStat.setString(8, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.geteMailBodyRevision()));
preStat.setString(9, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getType()));
preStat.setString(10, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.geteMailBodyChain()));
preStat.setString(11, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.geteMailBodyDisableEnvironment()));
if (countryEnvParam.isActive()) {
preStat.setString(12, "Y");
} else {
preStat.setString(12, "%");
}
if (countryEnvParam.isMaintenanceAct()) {
preStat.setString(13, "Y");
} else {
preStat.setString(13, "%");
}
preStat.setString(14, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getMaintenanceStr()));
preStat.setString(15, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getMaintenanceEnd()));
ResultSet resultSet = preStat.executeQuery();
try {
while (resultSet.next()) {
result.add(this.loadFromResultSet(resultSet));
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
if (throwex) {
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
}
return result;
}
use of org.cerberus.crud.entity.CountryEnvParam in project cerberus-source by cerberustesting.
the class CountryEnvParamDAO method readDistinctEnvironmentByVariousByCriteria.
@Override
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) {
AnswerList response = new AnswerList();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
List<CountryEnvParam> cepList = new ArrayList<CountryEnvParam>();
StringBuilder searchSQL = new StringBuilder();
StringBuilder query = new StringBuilder();
// SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that
// were applied -- used for pagination p
query.append("SELECT SQL_CALC_FOUND_ROWS ");
query.append(" max(system) system, max(country) country, Environment, '' Description, ");
query.append(" max(build) build, max(revision) revision, max(chain) chain, '' DistribList, ");
query.append(" '' EMailBodyRevision, max(Type) type, '' EMailBodyChain, '' EMailBodyDisableEnvironment, ");
query.append(" max(Active) active, max(maintenanceact) maintenanceact, max(maintenancestr) maintenancestr, max(maintenanceend) maintenanceend ");
query.append(" FROM countryenvparam cep ");
if (!StringUtil.isNullOrEmpty(envGp)) {
searchSQL.append(" LEFT OUTER JOIN invariant i on i.idname='ENVIRONMENT' and i.value=cep.environment ");
}
searchSQL.append(" where 1=1 ");
if (!StringUtil.isNullOrEmpty(system)) {
searchSQL.append(" and (`System` = ? )");
}
if (!StringUtil.isNullOrEmpty(active)) {
searchSQL.append(" and (`active` = ? )");
}
if (!StringUtil.isNullOrEmpty(country)) {
searchSQL.append(" and (`country` = ? )");
}
if (!StringUtil.isNullOrEmpty(environment)) {
searchSQL.append(" and (`environment` = ? )");
}
if (!StringUtil.isNullOrEmpty(build)) {
searchSQL.append(" and (`build` = ? )");
}
if (!StringUtil.isNullOrEmpty(revision)) {
searchSQL.append(" and (`revision` = ? )");
}
if (!StringUtil.isNullOrEmpty(envGp)) {
searchSQL.append(" and (i.`gp1` = ? )");
}
query.append(searchSQL);
query.append(" group by `environment` ");
query.append(" order by `environment` ");
if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {
query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);
} else {
query.append(" limit ").append(start).append(" , ").append(amount);
}
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
LOG.debug("SQL.system : " + system);
LOG.debug("SQL.active : " + active);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
int i = 1;
if (!StringUtil.isNullOrEmpty(system)) {
preStat.setString(i++, system);
}
if (!StringUtil.isNullOrEmpty(active)) {
preStat.setString(i++, active);
}
if (!StringUtil.isNullOrEmpty(country)) {
preStat.setString(i++, country);
}
if (!StringUtil.isNullOrEmpty(environment)) {
preStat.setString(i++, environment);
}
if (!StringUtil.isNullOrEmpty(build)) {
preStat.setString(i++, build);
}
if (!StringUtil.isNullOrEmpty(revision)) {
preStat.setString(i++, revision);
}
if (!StringUtil.isNullOrEmpty(envGp)) {
preStat.setString(i++, envGp);
}
ResultSet resultSet = preStat.executeQuery();
try {
// gets the data
while (resultSet.next()) {
cepList.add(this.loadFromResultSet(resultSet));
}
// get the total number of rows
resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");
int nrTotalRows = 0;
if (resultSet != null && resultSet.next()) {
nrTotalRows = resultSet.getInt(1);
}
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.
LOG.error("Partial Result in the query.");
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));
response = new AnswerList(cepList, nrTotalRows);
} else if (cepList.size() <= 0) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
response = new AnswerList(cepList, nrTotalRows);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", "CountryEnvParam").replace("%OPERATION%", "SELECT"));
response = new AnswerList(cepList, nrTotalRows);
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
if (resultSet != null) {
resultSet.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
if (preStat != null) {
preStat.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
try {
if (!this.databaseSpring.isOnTransaction()) {
if (connection != null) {
connection.close();
}
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
response.setResultMessage(msg);
response.setDataList(cepList);
return response;
}
use of org.cerberus.crud.entity.CountryEnvParam in project cerberus-source by cerberustesting.
the class CountryEnvParamDAO method readByCriteria.
@Override
public AnswerList readByCriteria(int start, int amount, String colName, String dir, String searchTerm, String individualSearch) {
AnswerList response = new AnswerList();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
List<CountryEnvParam> cepList = new ArrayList<CountryEnvParam>();
StringBuilder searchSQL = new StringBuilder();
StringBuilder query = new StringBuilder();
// SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that
// were applied -- used for pagination p
query.append("SELECT SQL_CALC_FOUND_ROWS * FROM countryenvparam ");
searchSQL.append(" where 1=1 ");
if (!StringUtil.isNullOrEmpty(searchTerm)) {
searchSQL.append(" and (`system` like '%").append(searchTerm).append("%'");
searchSQL.append(" or `country` like '%").append(searchTerm).append("%'");
searchSQL.append(" or `environment` like '%").append(searchTerm).append("%'");
searchSQL.append(" or `description` like '%").append(searchTerm).append("%'");
searchSQL.append(" or `build` like '%").append(searchTerm).append("%'");
searchSQL.append(" or `revision` like '%").append(searchTerm).append("%'");
searchSQL.append(" or `chain` like '%").append(searchTerm).append("%'");
searchSQL.append(" or `distriblist` like '%").append(searchTerm).append("%'");
searchSQL.append(" or `emailbodyrevision` like '%").append(searchTerm).append("%'");
searchSQL.append(" or `type` like '%").append(searchTerm).append("%'");
searchSQL.append(" or `emailbodychain` like '%").append(searchTerm).append("%'");
searchSQL.append(" or `emailbodydisableenvironment` like '%").append(searchTerm).append("%'");
searchSQL.append(" or `active` like '%").append(searchTerm).append("%'");
searchSQL.append(" or `maintenanceact` like '%").append(searchTerm).append("%'");
searchSQL.append(" or `maintenancestr` like '%").append(searchTerm).append("%'");
searchSQL.append(" or `maintenanceend` like '%").append(searchTerm).append("%')");
}
if (!StringUtil.isNullOrEmpty(individualSearch)) {
searchSQL.append(" and (`").append(individualSearch).append("`)");
}
query.append(searchSQL);
if (!StringUtil.isNullOrEmpty(colName)) {
query.append("order by `").append(colName).append("` ").append(dir);
}
if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {
query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);
} else {
query.append(" limit ").append(start).append(" , ").append(amount);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
ResultSet resultSet = preStat.executeQuery();
try {
// gets the data
while (resultSet.next()) {
cepList.add(this.loadFromResultSet(resultSet));
}
// get the total number of rows
resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");
int nrTotalRows = 0;
if (resultSet != null && resultSet.next()) {
nrTotalRows = resultSet.getInt(1);
}
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.
LOG.error("Partial Result in the query.");
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));
response = new AnswerList(cepList, nrTotalRows);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", "CountryEnvParam").replace("%OPERATION%", "SELECT"));
response = new AnswerList(cepList, nrTotalRows);
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
} finally {
if (resultSet != null) {
resultSet.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
} finally {
if (preStat != null) {
preStat.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
} finally {
try {
if (!this.databaseSpring.isOnTransaction()) {
if (connection != null) {
connection.close();
}
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
response.setResultMessage(msg);
response.setDataList(cepList);
return response;
}
use of org.cerberus.crud.entity.CountryEnvParam in project cerberus-source by cerberustesting.
the class CountryEnvParamDAO method readByKey.
@Override
public AnswerItem readByKey(String system, String country, String environment) {
AnswerItem ans = new AnswerItem();
CountryEnvParam result = null;
final String query = "SELECT * FROM `countryenvparam` WHERE `system` = ? and `country` = ? and `environment` = ?";
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, system);
preStat.setString(2, country);
preStat.setString(3, environment);
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.first()) {
result = loadFromResultSet(resultSet);
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
ans.setItem(result);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
// sets the message
ans.setResultMessage(msg);
return ans;
}
use of org.cerberus.crud.entity.CountryEnvParam in project cerberus-source by cerberustesting.
the class CountryEnvParamDAO method readByVariousByCriteria.
@Override
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) {
AnswerList response = new AnswerList();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
List<CountryEnvParam> cepList = new ArrayList<CountryEnvParam>();
StringBuilder searchSQL = new StringBuilder();
List<String> individalColumnSearchValues = new ArrayList<String>();
StringBuilder query = new StringBuilder();
// SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that
// were applied -- used for pagination p
query.append("SELECT SQL_CALC_FOUND_ROWS * FROM countryenvparam cep");
if (!StringUtil.isNullOrEmpty(envGp)) {
searchSQL.append(" LEFT OUTER JOIN invariant i on i.idname='ENVIRONMENT' and i.value=cep.environment ");
}
searchSQL.append(" where 1=1 ");
if (!StringUtil.isNullOrEmpty(searchTerm)) {
searchSQL.append(" and (`system` like ?");
searchSQL.append(" or `country` like ?");
searchSQL.append(" or `environment` like ?");
searchSQL.append(" or `description` like ?");
searchSQL.append(" or `build` like ?");
searchSQL.append(" or `revision` like ?");
searchSQL.append(" or `chain` like ?");
searchSQL.append(" or `distriblist` like ?");
searchSQL.append(" or `emailbodyrevision` like ?");
searchSQL.append(" or `type` like ?");
searchSQL.append(" or `emailbodychain` like ?");
searchSQL.append(" or `emailbodydisableenvironment` like ?");
searchSQL.append(" or `active` like ?");
searchSQL.append(" or `maintenanceact` like ?");
searchSQL.append(" or `maintenancestr` like ?");
searchSQL.append(" or `maintenanceend` like ?)");
}
if (individualSearch != null && !individualSearch.isEmpty()) {
searchSQL.append(" and ( 1=1 ");
for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {
searchSQL.append(" and ");
searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));
individalColumnSearchValues.addAll(entry.getValue());
}
searchSQL.append(" )");
}
if (!StringUtil.isNullOrEmpty(system)) {
searchSQL.append(" and (`System` = ? )");
}
if (!StringUtil.isNullOrEmpty(active)) {
searchSQL.append(" and (`active` = ? )");
}
if (!StringUtil.isNullOrEmpty(country)) {
searchSQL.append(" and (`country` = ? )");
}
if (!StringUtil.isNullOrEmpty(environment)) {
searchSQL.append(" and (`environment` = ? )");
}
if (!StringUtil.isNullOrEmpty(build)) {
searchSQL.append(" and (`build` = ? )");
}
if (!StringUtil.isNullOrEmpty(revision)) {
searchSQL.append(" and (`revision` = ? )");
}
if (!StringUtil.isNullOrEmpty(envGp)) {
searchSQL.append(" and (i.`gp1` = ? )");
}
query.append(searchSQL);
if (!StringUtil.isNullOrEmpty(colName)) {
query.append(" order by `").append(colName).append("` ").append(dir);
}
if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {
query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);
} else {
query.append(" limit ").append(start).append(" , ").append(amount);
}
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
int i = 1;
if (!StringUtil.isNullOrEmpty(searchTerm)) {
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
}
for (String individualColumnSearchValue : individalColumnSearchValues) {
preStat.setString(i++, individualColumnSearchValue);
}
if (!StringUtil.isNullOrEmpty(system)) {
preStat.setString(i++, system);
}
if (!StringUtil.isNullOrEmpty(active)) {
preStat.setString(i++, active);
}
if (!StringUtil.isNullOrEmpty(country)) {
preStat.setString(i++, country);
}
if (!StringUtil.isNullOrEmpty(environment)) {
preStat.setString(i++, environment);
}
if (!StringUtil.isNullOrEmpty(build)) {
preStat.setString(i++, build);
}
if (!StringUtil.isNullOrEmpty(revision)) {
preStat.setString(i++, revision);
}
if (!StringUtil.isNullOrEmpty(envGp)) {
preStat.setString(i++, envGp);
}
ResultSet resultSet = preStat.executeQuery();
try {
// gets the data
while (resultSet.next()) {
cepList.add(this.loadFromResultSet(resultSet));
}
// get the total number of rows
resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");
int nrTotalRows = 0;
if (resultSet != null && resultSet.next()) {
nrTotalRows = resultSet.getInt(1);
}
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.
LOG.error("Partial Result in the query.");
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));
response = new AnswerList(cepList, nrTotalRows);
} else if (cepList.size() <= 0) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
response = new AnswerList(cepList, nrTotalRows);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", "CountryEnvParam").replace("%OPERATION%", "SELECT"));
response = new AnswerList(cepList, nrTotalRows);
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
if (resultSet != null) {
resultSet.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
if (preStat != null) {
preStat.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
try {
if (!this.databaseSpring.isOnTransaction()) {
if (connection != null) {
connection.close();
}
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
response.setResultMessage(msg);
response.setDataList(cepList);
return response;
}
Aggregations