use of org.cerberus.util.answer.AnswerItem in project cerberus-source by cerberustesting.
the class TestCaseExecutionQueueDAO method getNbEntryToGo.
@Override
public int getNbEntryToGo(long id, int prio) {
AnswerItem<TestCaseExecutionQueue> ans = new AnswerItem<>();
TestCaseExecutionQueue result = null;
final String query = "SELECT count(*) FROM testcaseexecutionqueue WHERE State = 'QUEUED' and (ID < ? and Priority <= ?);";
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
int i = 1;
preStat.setLong(i++, id);
preStat.setInt(i++, prio);
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.first()) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
return resultSet.getInt(1);
} else {
LOG.error("No record found : " + query);
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 999999;
}
use of org.cerberus.util.answer.AnswerItem in project cerberus-source by cerberustesting.
the class TestCaseLabelDAO method readByKey.
@Override
public AnswerItem<TestCaseLabel> readByKey(String test, String testCase, Integer labelId) {
AnswerItem<TestCaseLabel> ans = new AnswerItem();
TestCaseLabel result = null;
final String query = "SELECT * FROM `testcaselabel` tel WHERE `labelid` = ? and `test` = ? and `testcase` = ?";
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.label : " + labelId);
LOG.debug("SQL.param.test : " + test);
LOG.debug("SQL.param.testcase : " + testCase);
}
try (Connection connection = databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query)) {
// prepare and execute query
preStat.setInt(1, labelId);
preStat.setString(2, test);
preStat.setString(3, testCase);
try (ResultSet resultSet = preStat.executeQuery()) {
// parse query
if (resultSet.first()) {
result = loadFromResultSet(resultSet, null);
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()));
}
} catch (Exception e) {
LOG.warn("Unable to readByKey TestCaseLabel: " + e.getMessage());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
} finally {
ans.setResultMessage(msg);
}
return ans;
}
use of org.cerberus.util.answer.AnswerItem in project cerberus-source by cerberustesting.
the class TestCaseStepActionControlExecutionDAO method readByKey.
@Override
public AnswerItem readByKey(long executionId, String test, String testCase, int step, int index, int sequence, int controlSequence) {
MessageEvent msg;
AnswerItem answer = new AnswerItem();
TestCaseStepActionControlExecution tcsa = null;
StringBuilder query = new StringBuilder();
query.append("SELECT * FROM testcasestepactioncontrolexecution a ");
query.append("where id = ? and test = ? and testcase = ? and step = ? and `index` = ? and controlSequence = ?");
query.append("and sequence = ?");
// 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 {
preStat.setLong(1, executionId);
preStat.setString(2, test);
preStat.setString(3, testCase);
preStat.setInt(4, step);
preStat.setInt(5, index);
preStat.setInt(6, sequence);
preStat.setInt(7, controlSequence);
ResultSet resultSet = preStat.executeQuery();
try {
while (resultSet.next()) {
tcsa = this.loadFromResultset(resultSet);
}
if (tcsa == null) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
}
} 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 (connection != null) {
connection.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
answer.setItem(tcsa);
answer.setResultMessage(msg);
return answer;
}
use of org.cerberus.util.answer.AnswerItem in project cerberus-source by cerberustesting.
the class TestCaseStepActionExecutionDAO method readByKey.
@Override
public AnswerItem readByKey(long executionId, String test, String testCase, int step, int index, int sequence) {
MessageEvent msg;
AnswerItem answer = new AnswerItem();
TestCaseStepActionExecution tcsa = null;
StringBuilder query = new StringBuilder();
query.append("SELECT * FROM testcasestepactionexecution exa ");
query.append("where exa.id = ? and exa.test = ? and exa.testcase = ? and exa.step = ? and exa.index = ? and exa.sequence = .");
// 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 {
preStat.setLong(1, executionId);
preStat.setString(2, test);
preStat.setString(3, testCase);
preStat.setInt(4, step);
preStat.setInt(5, index);
preStat.setInt(6, sequence);
ResultSet resultSet = preStat.executeQuery();
try {
while (resultSet.next()) {
tcsa = this.loadFromResultset(resultSet);
}
if (tcsa == null) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
}
} 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 (connection != null) {
connection.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
answer.setItem(tcsa);
answer.setResultMessage(msg);
return answer;
}
use of org.cerberus.util.answer.AnswerItem in project cerberus-source by cerberustesting.
the class TestDAO method readByKey.
@Override
public AnswerItem readByKey(String test) {
AnswerItem ans = new AnswerItem();
Test result;
final String query = "SELECT * FROM `test` WHERE `test` = ?";
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, test);
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;
}
Aggregations