use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.
the class TestCaseCountryPropertiesDAO method deleteTestCaseCountryProperties.
@Override
public void deleteTestCaseCountryProperties(TestCaseCountryProperties tccp) throws CerberusException {
boolean throwExcep = false;
final String query = "DELETE FROM testcasecountryproperties WHERE test = ? and testcase = ? and country = ? and hex(`property`) like hex(?)";
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, tccp.getTest());
preStat.setString(2, tccp.getTestCase());
preStat.setString(3, tccp.getCountry());
preStat.setBytes(4, tccp.getProperty().getBytes("UTF-8"));
throwExcep = preStat.executeUpdate() == 0;
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} catch (UnsupportedEncodingException ex) {
LOG.error(ex.toString());
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
if (throwExcep) {
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));
}
}
use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.
the class TestCaseCountryPropertiesDAO method findTestCaseCountryPropertiesByKey.
@Override
public TestCaseCountryProperties findTestCaseCountryPropertiesByKey(String test, String testcase, String country, String property) throws CerberusException {
TestCaseCountryProperties result = null;
boolean throwException = false;
final String query = "SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ? AND country = ? AND hex(`property`) = hex(?)";
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, test);
preStat.setString(2, testcase);
preStat.setString(3, country);
preStat.setBytes(4, property.getBytes("UTF-8"));
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.first()) {
String description = resultSet.getString("description");
String type = resultSet.getString("type");
String database = resultSet.getString("database");
String value1 = resultSet.getString("value1");
String value2 = resultSet.getString("value2");
String length = resultSet.getString("length");
int rowLimit = resultSet.getInt("rowLimit");
String nature = resultSet.getString("nature");
int retryNb = resultSet.getInt("RetryNb");
int retryPeriod = resultSet.getInt("RetryPeriod");
int cacheExpire = resultSet.getInt("CacheExpire");
result = factoryTestCaseCountryProperties.create(test, testcase, country, property, description, type, database, value1, value2, length, rowLimit, nature, retryNb, retryPeriod, cacheExpire);
} else {
throwException = true;
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} catch (UnsupportedEncodingException ex) {
LOG.error(ex.toString());
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
if (throwException) {
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
}
return result;
}
use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.
the class TestCaseExecutionDAO method setTagToExecution.
@Override
public void setTagToExecution(long id, String tag) throws CerberusException {
boolean throwEx = false;
final String query = "UPDATE testcaseexecution exe SET exe.tag = ? WHERE exe.id = ?";
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, tag);
preStat.setLong(2, id);
preStat.executeUpdate();
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
throwEx = true;
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("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.CANNOT_UPDATE_TABLE));
}
}
use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.
the class ParameterDAO method findParameterByKey.
@Override
public Parameter findParameterByKey(String system, String key) throws CerberusException {
boolean throwExep = false;
Parameter result = null;
final String query = "SELECT * FROM parameter p WHERE p.`system` = ? and p.param = ? ";
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, system);
preStat.setString(2, key);
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.first()) {
String value = resultSet.getString("value");
String desc = resultSet.getString("description");
result = factoryParameter.create(system, key, value, desc);
} else {
throwExep = true;
}
} 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 (throwExep) {
MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND);
mes.setDescription(mes.getDescription() + " Parameter not defined : " + key);
throw new CerberusException(mes);
}
return result;
}
use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.
the class TestCaseExecutionQueueDAO method updateToWaiting.
@Override
public boolean updateToWaiting(final Long id) throws CerberusException {
String queryUpdate = "UPDATE `" + TABLE + "` " + "SET `" + COLUMN_STATE + "` = 'WAITING', `" + COLUMN_REQUEST_DATE + "` = now(), `" + COLUMN_DATEMODIF + "` = now() " + "WHERE `" + COLUMN_ID + "` = ? " + "AND `" + COLUMN_STATE + "` = 'QUEUED'";
try (Connection connection = this.databaseSpring.connect();
PreparedStatement updateStateStatement = connection.prepareStatement(queryUpdate)) {
try {
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + queryUpdate);
LOG.debug("SQL.param.id : " + id);
}
updateStateStatement.setLong(1, id);
int updateResult = updateStateStatement.executeUpdate();
if (updateResult <= 0) {
LOG.warn("Unable to move state to WAITING for execution in queue " + id + " (update result: " + updateResult + "). Maybe execution is not in QUEUED ?");
return false;
}
return true;
} catch (SQLException e) {
LOG.warn("Unable to move state to WAITING for execution in queue " + id + ". Maybe execution is not in QUEUED ?", e);
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));
}
} catch (SQLException e) {
LOG.warn("Unable to state from QUEUED to WAITING state for executions in queue", e);
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));
}
}
Aggregations