Search in sources :

Example 66 with MessageGeneral

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

the class SqlLibraryDAO method updateSqlLibrary.

@Override
public void updateSqlLibrary(String name, String columnName, String value) throws CerberusException {
    boolean throwExcep = false;
    StringBuilder query = new StringBuilder();
    query.append("update sqllibrary set `");
    query.append(columnName);
    query.append("`=? where `name`=? ");
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setString(1, value);
            preStat.setString(2, name);
            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 67 with MessageGeneral

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

the class SqlLibraryDAO method updateSqlLibrary.

@Override
public void updateSqlLibrary(SqlLibrary sqlLibrary) throws CerberusException {
    boolean throwExcep = false;
    StringBuilder query = new StringBuilder();
    query.append("update sqllibrary set `script`=?,`description`=?, `type`=?, `database`=?  where `name`=? ");
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setString(1, sqlLibrary.getScript());
            preStat.setString(2, sqlLibrary.getDescription());
            preStat.setString(3, sqlLibrary.getType());
            preStat.setString(4, sqlLibrary.getDatabase());
            preStat.setString(5, 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)

Example 68 with MessageGeneral

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

the class TestCaseCountryDAO method deleteTestCaseCountry.

@Override
public void deleteTestCaseCountry(TestCaseCountry tcc) throws CerberusException {
    boolean throwExcep = false;
    final String query = "DELETE FROM testcasecountry WHERE test = ? and testcase = ? and country = ?";
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, tcc.getTest());
            preStat.setString(2, tcc.getTestCase());
            preStat.setString(3, tcc.getCountry());
            throwExcep = preStat.executeUpdate() == 0;
        } 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 69 with MessageGeneral

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

the class UserSystemDAO method insertUserSystem.

@Override
public void insertUserSystem(UserSystem userSystem) throws CerberusException {
    final String query = "INSERT INTO usersystem (`login`, `system`) VALUES (?, ?)";
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        try {
            preStat.setString(1, userSystem.getLogin());
            preStat.setString(2, userSystem.getSystem());
            preStat.execute();
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
            throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
        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 70 with MessageGeneral

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

the class UserSystemDAO method deleteUserSystem.

@Override
public void deleteUserSystem(UserSystem userSystem) throws CerberusException {
    final String query = "DELETE FROM usersystem WHERE `login` = ? and `system` = ?";
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        try {
            preStat.setString(1, userSystem.getLogin());
            preStat.setString(2, userSystem.getSystem());
            preStat.execute();
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
            throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
        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