use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.
the class TestCaseExecutionQueueDAO method updateToStarting.
@Override
public void updateToStarting(long id) throws CerberusException {
String queryUpdate = "UPDATE `" + TABLE + "` " + "SET `" + COLUMN_STATE + "` = 'STARTING', `" + COLUMN_REQUEST_DATE + "` = now(), `" + COLUMN_DATEMODIF + "` = now() " + "WHERE `" + COLUMN_ID + "` = ? " + "AND `" + COLUMN_STATE + "` = 'WAITING'";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + queryUpdate);
LOG.debug("SQL.param.id : " + id);
}
try (Connection connection = databaseSpring.connect();
PreparedStatement updateStateStatement = connection.prepareStatement(queryUpdate)) {
updateStateStatement.setLong(1, id);
int updateResult = updateStateStatement.executeUpdate();
if (updateResult <= 0) {
LOG.warn("Unable to move state to STARTING for execution in queue " + id + " (update result: " + updateResult + "). Is the execution currently WAITING ?");
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));
}
} catch (SQLException e) {
LOG.warn("Unable to move state from WAITING to STARTING for execution in queue " + id, e);
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));
}
}
use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.
the class TestCaseExecutionQueueDAO method updateToExecuting.
@Override
public void updateToExecuting(long id, String comment, long exeId) throws CerberusException {
String queryUpdate = "UPDATE `" + TABLE + "` " + "SET `" + COLUMN_STATE + "` = 'EXECUTING', `" + COLUMN_EXEID + "` = ?, `" + COLUMN_COMMENT + "` = ?, `" + COLUMN_REQUEST_DATE + "` = now(), `" + COLUMN_DATEMODIF + "` = now() " + "WHERE `" + COLUMN_ID + "` = ? " + "AND `" + COLUMN_STATE + "` in ('STARTING')";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + queryUpdate);
LOG.debug("SQL.param.id : " + id);
}
try (Connection connection = databaseSpring.connect();
PreparedStatement updateStateStatement = connection.prepareStatement(queryUpdate)) {
updateStateStatement.setLong(1, exeId);
updateStateStatement.setString(2, comment);
updateStateStatement.setLong(3, id);
int updateResult = updateStateStatement.executeUpdate();
if (updateResult <= 0) {
LOG.warn("Unable to move state to EXECUTING for execution in queue " + id + " (update result: " + updateResult + "). Is the execution currently STARTING ?");
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));
}
} catch (SQLException e) {
LOG.warn("Unable to move state from STARTING to EXECUTING for execution in queue " + id, e);
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));
}
}
use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.
the class RobotDAO method readByKey.
@Override
public Robot readByKey(String robot) throws CerberusException {
Robot result;
final String query = "SELECT * FROM `robot` WHERE `robot` = ?";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
}
try {
result = RequestDbUtils.executeQuery(databaseSpring, query, ps -> {
ps.setString(1, robot);
}, rs -> {
return loadFromResultSet(rs);
});
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR), exception);
}
// sets the message
return result;
}
use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.
the class SqlLibraryDAO method findSqlLibraryByKey.
/**
* Short one line description.
* <p/>
* Longer description. If there were any, it would be here. <p> And even
* more explanations to follow in consecutive paragraphs separated by HTML
* paragraph breaks.
*
* @param name Description text text text.
* @return Description text text text.
*/
@Override
public SqlLibrary findSqlLibraryByKey(String name) throws CerberusException {
boolean throwEx = false;
SqlLibrary result = null;
final String query = "SELECT * FROM sqllibrary WHERE NAME = ?";
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, name);
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.first()) {
String type = resultSet.getString("Type");
String database = resultSet.getString("Database");
String script = resultSet.getString("Script");
String description = resultSet.getString("Description");
result = factorySqlLib.create(name, type, database, script, description);
} else {
throwEx = 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 (throwEx) {
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.SQLLIB_NOT_FOUND));
}
return result;
}
use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.
the class SqlLibraryDAO method deleteSqlLibrary.
@Override
public void deleteSqlLibrary(SqlLibrary sqlLibrary) throws CerberusException {
boolean throwExcep = false;
StringBuilder query = new StringBuilder();
query.append("delete from sqllibrary where `Name`=? ");
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
preStat.setString(1, sqlLibrary.getName());
preStat.executeUpdate();
throwExcep = false;
} 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 (throwExcep) {
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));
}
}
Aggregations