Example #1
0
  @SuppressWarnings("unchecked")
  private boolean checkForCampaignIDExist(
      final Session session, final BatchCampaignAssociationModel batchCampaignAssociationModel)
      throws HibernateException {
    // Session session = null;
    List<BatchCampaignAssociationModel> list = Collections.emptyList();
    boolean campIdExist = true;
    final String campId = batchCampaignAssociationModel.getCampaignId();
    try {
      // session = sessionFactory.openSession();
      final String hql =
          "from BatchCampaignAssociationModel where campaignId =:cmpid and campaignType =:cmpType";
      // QC-1257 (change from Prelink to Targeted)
      list = session.createQuery(hql).setString("cmpid", campId).setString("cmpType", "T").list();

      if (list.size() > 0) {
        campIdExist = false;
        // session = null;
        // session = sessionFactory.openSession();
        final String uhql =
            "update BatchCampaignAssociationModel set campaignId = :cid, batchFileNo = :bfN, campaignStartDate = :csD, "
                + "campaignEndDate = :ceD, registrationStartDate = :rsD, registrationEndDate = :reD, "
                + "registrationRequired = :rReq, campaignType = :cT, commentsRequired = :cR, campaignDescription = :cD where id = :d";
        for (BatchCampaignAssociationModel b : list) {

          Query query = session.createQuery(uhql);
          query.setString("cid", batchCampaignAssociationModel.getCampaignId());
          query.setString("bfN", batchCampaignAssociationModel.getBatchFileNo());
          query.setDate("csD", batchCampaignAssociationModel.getCampaignStartDate());
          query.setDate("ceD", batchCampaignAssociationModel.getCampaignEndDate());
          query.setDate("rsD", batchCampaignAssociationModel.getRegistrationStartDate());
          query.setDate("reD", batchCampaignAssociationModel.getRegistrationEndDate());
          query.setParameter("rReq", batchCampaignAssociationModel.getRegistrationRequired());
          query.setString("cT", batchCampaignAssociationModel.getCampaignType());
          query.setParameter("cR", batchCampaignAssociationModel.getCommentsRequired());
          query.setString("cD", batchCampaignAssociationModel.getCampaignDescription());
          query.setInteger("d", b.getId());

          int rowCount = query.executeUpdate();
          LOGGER.info(
              rowCount > 0
                  ? "Update BatchCampaignAssociation table is successful with campaignid : "
                      + campId
                  : "Failed to update BatchCampaignAssociation table with campaignid : " + campId);
        }
      }
    } catch (HibernateException e) {
      LOGGER.error("Error in checking and updating campaign details with id : " + campId);
      throw e;
    } finally {
      // session.close();
      // batchCampaignAssociationModel = null;
    }
    return campIdExist;
  }
Example #2
0
 @Override
 public boolean createCampaign(BatchCampaignAssociationModel batchCampaignAssociationModel) {
   final String campaignId = batchCampaignAssociationModel.getCampaignId();
   LOGGER.info(
       "Saving newly created campaign "
           + campaignId
           + " started at : "
           + System.currentTimeMillis());
   boolean transactionStatus = true;
   Session session = sessionFactory.openSession();
   Transaction tx = null;
   try {
     tx = session.beginTransaction();
     session.save(batchCampaignAssociationModel);
     tx.commit();
   } catch (HibernateException e) {
     tx.rollback();
     transactionStatus = false;
     LOGGER.error(
         "HibernateException while saving newly created campaign with id ("
             + campaignId
             + "), "
             + e.getMessage());
   } finally {
     session.close();
   }
   LOGGER.info(
       "Newly created campaign ("
           + campaignId
           + ") saved successfully"
           + System.currentTimeMillis());
   return transactionStatus;
 }