Search in sources :

Example 51 with MessageGeneral

use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.

the class CampaignParameterDAO method findCampaignParameterByKey.

@Override
public CampaignParameter findCampaignParameterByKey(Integer campaignparameterID) throws CerberusException {
    boolean throwEx = false;
    final String query = "SELECT * FROM campaignparameter c WHERE c.campaignparameterID = ?";
    CampaignParameter campaignParameterResult = null;
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        preStat.setInt(1, campaignparameterID);
        try (ResultSet resultSet = preStat.executeQuery()) {
            if (resultSet.first()) {
                campaignParameterResult = this.loadFromResultSet(resultSet);
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    }
    if (throwEx) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
    }
    return campaignParameterResult;
}
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) PreparedStatement(java.sql.PreparedStatement) IFactoryCampaignParameter(org.cerberus.crud.factory.IFactoryCampaignParameter) CampaignParameter(org.cerberus.crud.entity.CampaignParameter)

Example 52 with MessageGeneral

use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.

the class CountryEnvParamDAO method findCountryEnvParamByCriteria.

@Override
public List<CountryEnvParam> findCountryEnvParamByCriteria(CountryEnvParam countryEnvParam) throws CerberusException {
    List<CountryEnvParam> result = new ArrayList();
    boolean throwex = false;
    StringBuilder query = new StringBuilder();
    query.append("SELECT `system`, `country`, `environment`, `Build`, `Revision`,`chain`, `distriblist`, `eMailBodyRevision`, `type`,`eMailBodyChain`, `eMailBodyDisableEnvironment`,  `active`, `maintenanceact`, ");
    query.append(" `maintenancestr`, `maintenanceend`, `Description` FROM countryenvparam WHERE `system` LIKE ? AND `country` LIKE ? ");
    query.append("AND `environment` LIKE ? AND `build` LIKE ? AND `Revision` LIKE ? AND `chain` LIKE ? ");
    query.append("AND `distriblist` LIKE ? AND `eMailBodyRevision` LIKE ? AND `type` LIKE ? AND `eMailBodyChain` LIKE ? ");
    query.append("AND `eMailBodyDisableEnvironment` LIKE ? AND `active` LIKE ? AND `maintenanceact` LIKE ? AND `maintenancestr` LIKE ? ");
    query.append("AND `maintenanceend` LIKE ? ");
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setString(1, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getSystem()));
            preStat.setString(2, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getCountry()));
            preStat.setString(3, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getEnvironment()));
            preStat.setString(4, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getBuild()));
            preStat.setString(5, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getRevision()));
            preStat.setString(6, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getChain()));
            preStat.setString(7, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getDistribList()));
            preStat.setString(8, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.geteMailBodyRevision()));
            preStat.setString(9, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getType()));
            preStat.setString(10, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.geteMailBodyChain()));
            preStat.setString(11, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.geteMailBodyDisableEnvironment()));
            if (countryEnvParam.isActive()) {
                preStat.setString(12, "Y");
            } else {
                preStat.setString(12, "%");
            }
            if (countryEnvParam.isMaintenanceAct()) {
                preStat.setString(13, "Y");
            } else {
                preStat.setString(13, "%");
            }
            preStat.setString(14, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getMaintenanceStr()));
            preStat.setString(15, ParameterParserUtil.wildcardIfEmpty(countryEnvParam.getMaintenanceEnd()));
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    result.add(this.loadFromResultSet(resultSet));
                }
            } 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.NO_DATA_FOUND));
    }
    return result;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IFactoryCountryEnvParam(org.cerberus.crud.factory.IFactoryCountryEnvParam) CountryEnvParam(org.cerberus.crud.entity.CountryEnvParam)

Example 53 with MessageGeneral

use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.

the class TestCaseCountryDAO method findTestCaseCountryByKey.

@Override
public TestCaseCountry findTestCaseCountryByKey(String test, String testCase, String country) throws CerberusException {
    final String query = "SELECT * FROM testcasecountry tcc WHERE test = ? AND testcase = ? AND country = ? ";
    TestCaseCountry result = null;
    boolean throwException = false;
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, test);
            preStat.setString(2, testCase);
            preStat.setString(3, country);
            ResultSet resultSet = preStat.executeQuery();
            try {
                if (resultSet.first()) {
                    result = factoryTestCaseCountry.create(test, testCase, country);
                } else {
                    throwException = 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 (throwException) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_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) IFactoryTestCaseCountry(org.cerberus.crud.factory.IFactoryTestCaseCountry) TestCaseCountry(org.cerberus.crud.entity.TestCaseCountry) PreparedStatement(java.sql.PreparedStatement)

Example 54 with MessageGeneral

use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.

the class TestCaseCountryDAO method insertTestCaseCountry.

@Override
public void insertTestCaseCountry(TestCaseCountry testCaseCountry) throws CerberusException {
    boolean throwExcep = false;
    StringBuilder query = new StringBuilder();
    query.append("INSERT INTO testcasecountry (`test`, `testCase`, `country`) ");
    query.append("VALUES (?,?,?)");
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setString(1, testCaseCountry.getTest());
            preStat.setString(2, testCaseCountry.getTestCase());
            preStat.setString(3, testCaseCountry.getCountry());
            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)

Example 55 with MessageGeneral

use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.

the class TestCaseCountryPropertiesDAO method insertTestCaseCountryProperties.

@Override
public void insertTestCaseCountryProperties(TestCaseCountryProperties testCaseCountryProperties) throws CerberusException {
    boolean throwExcep = false;
    StringBuilder query = new StringBuilder();
    query.append("INSERT INTO testcasecountryproperties (`Test`,`TestCase`,`Country`,`Property` ,`Description`,`Type`");
    query.append(",`Database`,`Value1`,`Value2`,`Length`,`RowLimit`,`Nature`,`RetryNb`,`RetryPeriod`) ");
    query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setString(1, testCaseCountryProperties.getTest());
            preStat.setString(2, testCaseCountryProperties.getTestCase());
            preStat.setString(3, testCaseCountryProperties.getCountry());
            preStat.setBytes(4, testCaseCountryProperties.getProperty().getBytes("UTF-8"));
            preStat.setBytes(5, testCaseCountryProperties.getDescription().getBytes("UTF-8"));
            preStat.setString(6, testCaseCountryProperties.getType());
            preStat.setString(7, testCaseCountryProperties.getDatabase());
            preStat.setBytes(8, testCaseCountryProperties.getValue1().getBytes("UTF-8"));
            preStat.setBytes(9, testCaseCountryProperties.getValue2().getBytes("UTF-8"));
            preStat.setString(10, testCaseCountryProperties.getLength());
            preStat.setInt(11, testCaseCountryProperties.getRowLimit());
            preStat.setString(12, testCaseCountryProperties.getNature());
            preStat.setInt(13, testCaseCountryProperties.getRetryNb());
            preStat.setInt(14, testCaseCountryProperties.getRetryPeriod());
            preStat.executeUpdate();
            throwExcep = false;
        } 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)

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