Search in sources :

Example 11 with Campaign

use of org.cerberus.crud.entity.Campaign in project cerberus-source by cerberustesting.

the class CampaignDAO method readByKey.

@Override
public AnswerItem readByKey(String key) {
    AnswerItem<Campaign> ans = new AnswerItem<>();
    MessageEvent msg = null;
    StringBuilder query = new StringBuilder();
    query.append("SELECT * FROM campaign cpg WHERE campaign = ?");
    try (Connection connection = databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query.toString())) {
        // Prepare and execute query
        preStat.setString(1, key);
        try (ResultSet resultSet = preStat.executeQuery()) {
            while (resultSet.next()) {
                ans.setItem(loadFromResultSet(resultSet));
            }
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "SELECT");
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
        }
    } catch (Exception e) {
        LOG.warn("Unable to execute query : " + e.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
    } finally {
        // We always set the result message
        ans.setResultMessage(msg);
    }
    return ans;
}
Also used : IFactoryCampaign(org.cerberus.crud.factory.IFactoryCampaign) Campaign(org.cerberus.crud.entity.Campaign) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) AnswerItem(org.cerberus.util.answer.AnswerItem) SQLException(java.sql.SQLException)

Aggregations

Campaign (org.cerberus.crud.entity.Campaign)11 MessageEvent (org.cerberus.engine.entity.MessageEvent)8 AnswerItem (org.cerberus.util.answer.AnswerItem)6 JSONObject (org.json.JSONObject)6 ArrayList (java.util.ArrayList)5 IFactoryCampaign (org.cerberus.crud.factory.IFactoryCampaign)5 ICampaignService (org.cerberus.crud.service.ICampaignService)5 JSONArray (org.json.JSONArray)4 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 List (java.util.List)3 CampaignLabel (org.cerberus.crud.entity.CampaignLabel)3 CampaignParameter (org.cerberus.crud.entity.CampaignParameter)3 ICampaignLabelService (org.cerberus.crud.service.ICampaignLabelService)3 ICampaignParameterService (org.cerberus.crud.service.ICampaignParameterService)3 ILogEventService (org.cerberus.crud.service.ILogEventService)3 Answer (org.cerberus.util.answer.Answer)3 AnswerList (org.cerberus.util.answer.AnswerList)3