Search in sources :

Example 61 with MessageGeneral

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));
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 62 with MessageGeneral

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));
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 63 with MessageGeneral

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;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) Connection(java.sql.Connection) Autowired(org.springframework.beans.factory.annotation.Autowired) ParameterParserUtil(org.cerberus.util.ParameterParserUtil) MessageEventEnum(org.cerberus.enums.MessageEventEnum) ArrayList(java.util.ArrayList) StringUtil(org.cerberus.util.StringUtil) Strings(com.google.common.base.Strings) SQLException(java.sql.SQLException) DatabaseSpring(org.cerberus.database.DatabaseSpring) SqlUtil(org.cerberus.util.SqlUtil) ResultSet(java.sql.ResultSet) Map(java.util.Map) IFactoryRobot(org.cerberus.crud.factory.IFactoryRobot) MessageEvent(org.cerberus.engine.entity.MessageEvent) RequestDbUtils(org.cerberus.crud.utils.RequestDbUtils) Repository(org.springframework.stereotype.Repository) FactoryRobot(org.cerberus.crud.factory.impl.FactoryRobot) Answer(org.cerberus.util.answer.Answer) CerberusException(org.cerberus.exception.CerberusException) PreparedStatement(java.sql.PreparedStatement) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Robot(org.cerberus.crud.entity.Robot) IRobotDAO(org.cerberus.crud.dao.IRobotDAO) Statement(java.sql.Statement) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) AnswerItem(org.cerberus.util.answer.AnswerItem) LogManager(org.apache.logging.log4j.LogManager) MessageGeneralEnum(org.cerberus.enums.MessageGeneralEnum) CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) IFactoryRobot(org.cerberus.crud.factory.IFactoryRobot) FactoryRobot(org.cerberus.crud.factory.impl.FactoryRobot) Robot(org.cerberus.crud.entity.Robot)

Example 64 with MessageGeneral

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;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) SqlLibrary(org.cerberus.crud.entity.SqlLibrary) IFactorySqlLibrary(org.cerberus.crud.factory.IFactorySqlLibrary) FactorySqlLibrary(org.cerberus.crud.factory.impl.FactorySqlLibrary) PreparedStatement(java.sql.PreparedStatement)

Example 65 with MessageGeneral

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));
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Aggregations

MessageGeneral (org.cerberus.engine.entity.MessageGeneral)71 CerberusException (org.cerberus.exception.CerberusException)61 Connection (java.sql.Connection)46 PreparedStatement (java.sql.PreparedStatement)46 SQLException (java.sql.SQLException)46 ResultSet (java.sql.ResultSet)18 ArrayList (java.util.ArrayList)12 Date (java.util.Date)10 TestCase (org.cerberus.crud.entity.TestCase)10 MessageEvent (org.cerberus.engine.entity.MessageEvent)8 AnswerItem (org.cerberus.util.answer.AnswerItem)7 Timestamp (java.sql.Timestamp)5 CerberusEventException (org.cerberus.exception.CerberusEventException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 CountryEnvParam (org.cerberus.crud.entity.CountryEnvParam)4 TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)4 TestCaseExecutionQueue (org.cerberus.crud.entity.TestCaseExecutionQueue)4 IOException (java.io.IOException)3 CampaignParameter (org.cerberus.crud.entity.CampaignParameter)3 IFactoryCampaignParameter (org.cerberus.crud.factory.IFactoryCampaignParameter)3