gt:                 preStat.setString(index, "%" + parameter.trim() + "%");
context: /**
   * Cerberus Copyright (C) 2013 - 2017 cerberustesting
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This file is part of Cerberus.
   *
   * Cerberus is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * Cerberus is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with Cerberus.  If not, see <http://www.gnu.org/licenses/>.
   */
  package org.cerberus.crud.dao.impl;
  
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Statement;
  import java.util.ArrayList;
  import java.util.List;
  import org.apache.logging.log4j.Logger;
  import org.apache.logging.log4j.LogManager;
  import org.cerberus.crud.dao.ICampaignParameterDAO;
  import org.cerberus.crud.entity.Campaign;
  import org.cerberus.crud.entity.CampaignParameter;
  import org.cerberus.crud.factory.IFactoryCampaignParameter;
  import org.cerberus.database.DatabaseSpring;
  import org.cerberus.engine.entity.MessageEvent;
  import org.cerberus.engine.entity.MessageGeneral;
  import org.cerberus.enums.MessageEventEnum;
  import org.cerberus.enums.MessageGeneralEnum;
  import org.cerberus.exception.CerberusException;
  import org.cerberus.util.ParameterParserUtil;
  import org.cerberus.util.StringUtil;
  import org.cerberus.util.answer.Answer;
  import org.cerberus.util.answer.AnswerList;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Repository;
  
  /**
   * @author memiks
   */
  @Repository
  public class CampaignParameterDAO implements ICampaignParameterDAO {
  
      @Autowired
      private DatabaseSpring databaseSpring;
      @Autowired
      private IFactoryCampaignParameter factoryCampaignParameter;
  
      private static final Logger LOG = LogManager.getLogger(CampaignParameterDAO.class);
  
      private final String OBJECT_NAME = "CampaignParameter";
      private final String SQL_DUPLICATED_CODE = "23000";
      private final int MAX_ROW_SELECTED = 100000;
  
      /**
       * Declare SQL queries used by this {@link CampaignParameter}
       *
       * @author Aurelien Bourdon
       */
      private static interface Query {
  
          /**
           * Get list of {@link CampaignParameter} associated with the given
           * {@link Campaign}'s name
           */
          String READ_BY_KEY = "SELECT * FROM `campaignparameter` WHERE `campaigncontentID` = ?";
  
          /**
           * Create a new {@link CampaignParameter}
           */
          String CREATE = "INSERT INTO `campaignparameter` (`campaign`,`Parameter`,`Value`) VALUES (?, ?, ?)";
  
          /**
           * Remove an existing {@link CampaignParameter}
           */
          String DELETE = "DELETE FROM `campaignparameter` WHERE `campaign` = ? AND `parameter` = ? AND `value` = ?";
  
          /**
           * Remove all {@link CampaignParameter} of a {@link Campaign}
           */
          String DELETE_BY_CAMPAIGN = "DELETE FROM `campaignparameter` WHERE `campaign` = ?";
      }
  
      @Override
      public List<CampaignParameter> findAll() throws CerberusException {
          boolean throwEx = false;
          final String query = "SELECT * FROM campaignparameter c";
          List<CampaignParameter> campaignParameterList = new ArrayList<CampaignParameter>();
          try (Connection connection = this.databaseSpring.connect();
                  PreparedStatement preStat = connection.prepareStatement(query);) {
              try (ResultSet resultSet = preStat.executeQuery();) {
                  while (resultSet.next()) {
                      campaignParameterList.add(this.loadFromResultSet(resultSet));
                  }
              } catch (SQLException exception) {
                  LOG.warn("Unable to execute query : " + exception.toString());
                  campaignParameterList = null;
              }
          } catch (SQLException exception) {
              LOG.warn("Unable to execute query : " + exception.toString());
              campaignParameterList = null;
          }
          if (throwEx) {
              throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
          }
          return campaignParameterList;
      }
  
      @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;
      }
  
      @Override
      public List<CampaignParameter> findCampaignParametersByCampaign(String campaign) throws CerberusException {
          boolean throwEx = false;
          final String query = "SELECT * FROM campaignparameter c WHERE c.campaign = ?";
  
          List<CampaignParameter> campaignParameterList = new ArrayList<CampaignParameter>();
  
          try (Connection connection = this.databaseSpring.connect();
                  PreparedStatement preStat = connection.prepareStatement(query);) {
  
              preStat.setString(1, campaign);
              try (ResultSet resultSet = preStat.executeQuery();) {
                  while (resultSet.next()) {
                      campaignParameterList.add(this.loadFromResultSet(resultSet));
                  }
              } catch (SQLException exception) {
                  LOG.warn("Unable to execute query : " + exception.toString());
                  campaignParameterList = null;
              }
          } catch (SQLException exception) {
              LOG.warn("Unable to execute query : " + exception.toString());
              campaignParameterList = null;
          }
          if (throwEx) {
              throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
          }
          return campaignParameterList;
      }
  
      @Override
      public boolean updateCampaignParameter(CampaignParameter campaignParameter) {
          final StringBuilder query = new StringBuilder("UPDATE `campaignparameter` SET campaign=?, `Parameter`=?, `Value`=? WHERE campaignparameterID=?");
  
          try (Connection connection = this.databaseSpring.connect();
                  PreparedStatement preStat = connection.prepareStatement(query.toString());) {
              preStat.setString(1, campaignParameter.getCampaign());
              preStat.setString(2, campaignParameter.getParameter());
              preStat.setString(3, campaignParameter.getValue());
              preStat.setInt(4, campaignParameter.getCampaignparameterID());
              return (preStat.executeUpdate() == 1);
          } catch (SQLException exception) {
              LOG.warn("Unable to execute query : " + exception.toString());
          }
          return false;
      }
  
      @Override
      public boolean createCampaignParameter(CampaignParameter campaignParameter) {
          final StringBuilder query = new StringBuilder("INSERT INTO `campaignparameter` (`campaign`, `Parameter`, `Value`) VALUES (?, ?, ?);");
  
          try (Connection connection = this.databaseSpring.connect();
                  PreparedStatement preStat = connection.prepareStatement(query.toString());) {
              preStat.setString(1, campaignParameter.getCampaign());
              preStat.setString(2, campaignParameter.getParameter());
              preStat.setString(3, campaignParameter.getValue());
              return (preStat.executeUpdate() == 1);
          } catch (SQLException exception) {
              LOG.warn("Unable to execute query : " + exception.toString());
          }
          return false;
      }
  
      @Override
      public List<CampaignParameter> findCampaignParameterByCriteria(Integer campaignparameterID, String campaign, String parameter, String value) throws CerberusException {
          boolean throwEx = false;
          final StringBuilder query = new StringBuilder("SELECT * FROM campaignparameter c WHERE 1=1 ");
  
          if (campaignparameterID != null) {
              query.append(" AND c.campaignparameterID = ?");
          }
          if (campaign != null && !"".equals(campaign.trim())) {
              query.append(" AND c.campaign LIKE ?");
          }
          if (parameter != null && !"".equals(parameter.trim())) {
              query.append(" AND c.parameter LIKE ?");
          }
  
          if (value != null && !"".equals(value.trim())) {
              query.append(" AND c.value LIKE ?");
          }
  
          // " c.campaignID = ? AND c.campaign LIKE ? AND c.description LIKE ?";
          List<CampaignParameter> campaignParametersList = new ArrayList<CampaignParameter>();
  
          try (Connection connection = this.databaseSpring.connect();
                  PreparedStatement preStat = connection.prepareStatement(query.toString());) {
  
              int index = 1;
              if (campaignparameterID != null) {
                  preStat.setInt(index, campaignparameterID);
                  index++;
              }
              if (campaign != null && !"".equals(campaign.trim())) {
                  preStat.setString(index, "%" + campaign.trim() + "%");
                  index++;
              }
              if (parameter != null && !"".equals(parameter.trim())) {
  