package com.dreamoval.motech.core.dao.hibernate;

import com.dreamoval.motech.core.dao.GatewayRequestDAO;
import com.dreamoval.motech.core.model.GatewayRequest;
import com.dreamoval.motech.core.model.GatewayRequestImpl;
import com.dreamoval.motech.core.model.MStatus;
import java.util.Date;
import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.criterion.Restrictions;

/*
 * GatewayRequestDAOImpl is the implementation class of the GatewayRequestDAO interface
 * This Class implements only GatewayRequestDAO specific persistent operation to the GatewayRequest model.
 * 
 * Date: Jul 24, 2009
 * @author Joseph Djomeda (joseph@dreamoval.com)
 * @author Henry Sampson (henry@dreamoval.com)
 */
public class GatewayRequestDAOImpl extends HibernateGenericDAOImpl<GatewayRequestImpl> implements GatewayRequestDAO<GatewayRequestImpl> {

    private static Logger logger = Logger.getLogger(GatewayRequestDAOImpl.class);

    public GatewayRequestDAOImpl() {
    }

    /**
     * Searches for all messages with status: <code>status</code>
     *
     * @param status The status to use as criteria for the search
     * @return The list of GatewayRequest object with status: <code>status</code>
     */
    public List<GatewayRequest> getByStatus(MStatus status) {
        logger.info("getByStatus");
        logger.debug(status);
        try {

            List<GatewayRequest> allbyStatus;
            allbyStatus = (List<GatewayRequest>) getDBSession().getSession().createCriteria(getPersistentClass()).add(Restrictions.eq("messageStatus", status)).list();

            logger.debug(allbyStatus);
            return allbyStatus;
        } catch (HibernateException he) {

            logger.debug("Persistence or JDBC Exception in Method getByStatus", he);
            return null;
        } catch (Exception ex) {

            logger.debug("Exception in Method getByStatus", ex);
            return null;
        }
    }

    public List<GatewayRequest> getByStatusAndSchedule(MStatus status, Date schedule) {
        logger.info("getByStatusAndSchedule");
        logger.debug(status);

//        try {

        List<GatewayRequest> allbystatandSdule;
        Criteria criteria = getDBSession().getSession().createCriteria(getPersistentClass());
        if (schedule == null) {
            criteria = criteria
                    .add(Restrictions.isNull("dateTo"))
                    .add(Restrictions.isNull("dateFrom"))
                    .add(Restrictions.eq("messageStatus", status));
        } else {
            criteria = criteria
                    .add(Restrictions.eq("messageStatus", status))
                    .add(Restrictions.lt("dateFrom", schedule))
                    .add(Restrictions.gt("dateTo", schedule));

        }

        allbystatandSdule = (List<GatewayRequest>) criteria.add(Restrictions.isNotNull("gatewayRequestDetails")).list();
        logger.debug(allbystatandSdule);
        return allbystatandSdule;
//        } catch (HibernateException he) {
//
//            logger.debug("Persistence or JDBC Exception in Method getByStatusAndSchedule", he);
//            return null;
//        } catch (Exception ex) {
//
//            logger.debug("Exception in Method getByStatusAndSchedule", ex);
//            return null;
//        }
    }
}

@@ -1385,45 +1385,8 @@
  %7B%0D%0A
-        logger.info(%22getByStatus%22);%0D%0A
     
@@ -1776,37 +1776,37 @@
          logger.
-debug
+error
 (%22Persistence or
@@ -1924,37 +1924,37 @@
          logger.
-debug
+error
 (%22Exception in M
@@ -2118,56 +2118,8 @@
  %7B%0D%0A
-        logger.info(%22getByStatusAndSchedule%22);%0D%0A
     
@@ -2147,18 +2147,16 @@
 us);%0D%0A%0D%0A
-//
         
@@ -2372,38 +2372,16 @@
 criteria
-%0D%0A                    
 .add(Res
@@ -2407,38 +2407,16 @@
 ateTo%22))
-%0D%0A                    
 .add(Res
@@ -2444,38 +2444,16 @@
 eFrom%22))
-%0D%0A                    
 .add(Res
@@ -2542,38 +2542,16 @@
 criteria
-%0D%0A                    
 .add(Res
@@ -2588,38 +2588,16 @@
 status))
-%0D%0A                    
 .add(Res
@@ -2635,30 +2635,8 @@
 le))
-%0D%0A                    
 .add
@@ -2889,18 +2889,16 @@
 Sdule;%0D%0A
-//
         
@@ -2928,30 +2928,26 @@
 tion he) %7B%0D%0A
-//%0D%0A//
+%0D%0A
             
@@ -2953,21 +2953,21 @@
  logger.
-debug
+error
 (%22Persis
@@ -3027,26 +3027,24 @@
 ule%22, he);%0D%0A
-//
             
@@ -3049,34 +3049,32 @@
   return null;%0D%0A
-//
         %7D catch 
@@ -3095,14 +3095,10 @@
  %7B%0D%0A
-//%0D%0A//
+%0D%0A
     
@@ -3112,21 +3112,21 @@
  logger.
-debug
+error
 (%22Except
@@ -3170,18 +3170,16 @@
 , ex);%0D%0A
-//
         
@@ -3200,10 +3200,8 @@
 l;%0D%0A
-//
     

Format GatewayRequestDAOImpl and added try and catch block and appropriate logging features