use of org.cerberus.util.answer.AnswerItem in project cerberus-source by cerberustesting.
the class TestDataLibDataDAO method readByKeyTech.
@Override
public AnswerItem readByKeyTech(Integer testDataLibDataID) {
AnswerItem answer = new AnswerItem();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
TestDataLibData result = null;
final String query = "SELECT * FROM testdatalibdata where `testdatalibdataid`=? ";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.testDataLibDataID : " + testDataLibDataID);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
preStat.setInt(1, testDataLibDataID);
try {
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.first()) {
result = this.loadFromResultSet(resultSet);
} else {
// specific message for gefromdatalib
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 {
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 ex) {
LOG.warn("Unable to close connection : " + ex.toString());
}
}
answer.setResultMessage(msg);
answer.setItem(result);
return answer;
}
use of org.cerberus.util.answer.AnswerItem in project cerberus-source by cerberustesting.
the class BuildRevisionInvariantDAO method readByKey.
@Override
public AnswerItem readByKey(String system, Integer level, Integer seq) {
AnswerItem ans = new AnswerItem();
BuildRevisionInvariant result = null;
final String query = "SELECT * FROM `buildrevisioninvariant` WHERE `system` = ? and level = ? and seq = ? ";
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.setInt(2, level);
preStat.setInt(3, seq);
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.util.answer.AnswerItem in project cerberus-source by cerberustesting.
the class BuildRevisionParametersDAO method readByVarious2.
@Override
public AnswerItem readByVarious2(String build, String revision, String release, String application) {
AnswerItem ans = new AnswerItem();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
BuildRevisionParameters result = null;
StringBuilder query = new StringBuilder();
query.append("Select * FROM buildrevisionparameters ");
query.append(" WHERE build= ? and revision= ? and `release` = ? and application = ? ");
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
preStat.setString(1, build);
preStat.setString(2, revision);
preStat.setString(3, release);
preStat.setString(4, application);
ResultSet resultSet = preStat.executeQuery();
try {
// gets the data
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.util.answer.AnswerItem in project cerberus-source by cerberustesting.
the class BuildRevisionParametersDAO method readLastBySystem.
@Override
public AnswerItem readLastBySystem(String system) {
AnswerItem ans = new AnswerItem();
BuildRevisionParameters result = null;
StringBuilder query = new StringBuilder();
query.append("SELECT * from buildrevisionparameters brp ");
query.append(" left outer join buildrevisioninvariant bri1 on brp.build = bri1.versionname and bri1.level=1 and bri1.`System` = ? ");
query.append(" left outer join buildrevisioninvariant bri2 on brp.revision = bri2.versionname and bri2.level=2 and bri2.`System` = ? ");
query.append("WHERE 1=1 ");
query.append(" and application in (SELECT application FROM application WHERE `System` = ? ) ");
query.append("ORDER BY bri1.seq desc, bri2.seq desc, brp.datecre desc limit 1; ");
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.toString());
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
int i = 1;
preStat.setString(i++, system);
preStat.setString(i++, system);
preStat.setString(i++, system);
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 LAST"));
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.util.answer.AnswerItem in project cerberus-source by cerberustesting.
the class BuildRevisionParametersDAO method readByKeyTech.
@Override
public AnswerItem readByKeyTech(int id) {
AnswerItem ans = new AnswerItem();
BuildRevisionParameters result = null;
final String query = "SELECT * FROM `buildrevisionparameters` WHERE `id` = ?";
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 {
preStat.setInt(1, id);
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