Search in sources :

Example 56 with MessageGeneral

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

Example 57 with MessageGeneral

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

Example 58 with MessageGeneral

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));
    }
}
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 59 with MessageGeneral

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;
}
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) Parameter(org.cerberus.crud.entity.Parameter) IFactoryParameter(org.cerberus.crud.factory.IFactoryParameter) FactoryParameter(org.cerberus.crud.factory.impl.FactoryParameter) PreparedStatement(java.sql.PreparedStatement)

Example 60 with MessageGeneral

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));
    }
}
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