001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.ken.dao.impl;
017
018import org.apache.log4j.Logger;
019import org.apache.ojb.broker.query.Criteria;
020import org.kuali.rice.core.api.util.RiceConstants;
021import org.kuali.rice.core.framework.persistence.dao.GenericDao;
022import org.kuali.rice.ken.bo.NotificationMessageDelivery;
023import org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao;
024import org.kuali.rice.ken.util.NotificationConstants;
025import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
026
027import java.sql.Timestamp;
028import java.util.Collection;
029
030/**
031 * This is a description of what this class does - g1zhang don't forget to fill this in. 
032 * 
033 * @author Kuali Rice Team (rice.collab@kuali.org)
034 *
035 */
036public class NotificationMessegeDeliveryDaoOjb extends PersistenceBrokerDaoSupport implements
037                NotificationMessegeDeliveryDao {
038
039        private static final Logger LOG = Logger.getLogger(NotificationDaoOjb.class);
040        
041        /**
042         * This overridden method ...
043         * 
044         * @see org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao#getUndeliveredMessageDelivers()
045         */
046        @Override
047        public Collection getUndeliveredMessageDelivers(GenericDao businessObjectDao) {
048                
049                //LOG.info("************************calling OJBNotificationMessegeDeliveryDao.getUndeliveredMessageDelivers************************ ");
050                
051        Criteria criteria = new Criteria();
052        criteria.addEqualTo(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.UNDELIVERED);
053        criteria.addIsNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE);
054        Collection<NotificationMessageDelivery> messageDeliveries = businessObjectDao.findMatching(NotificationMessageDelivery.class, criteria, true, RiceConstants.NO_WAIT);
055
056        return messageDeliveries;
057        }
058
059        /**
060         * This overridden method ...
061         * 
062         * @see org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao#getMessageDeliveriesForAutoRemoval(org.kuali.rice.core.framework.persistence.dao.GenericDao)
063         */
064        @Override
065        public Collection<NotificationMessageDelivery> getMessageDeliveriesForAutoRemoval(Timestamp tm, GenericDao businessObjectDao) {
066                
067                //LOG.info("************************calling OJBNotificationMessegeDeliveryDao.getMessageDeliveriesForAutoRemoval************************ ");
068                
069        // get all UNDELIVERED/DELIVERED notification notification message delivery records with associated notifications that have and autoRemovalDateTime <= current
070        Criteria criteria_STATUS = new Criteria();
071        criteria_STATUS.addEqualTo(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.DELIVERED);
072
073        Criteria criteria_UNDELIVERED = new Criteria();
074        criteria_UNDELIVERED.addEqualTo(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.UNDELIVERED);
075
076        // now OR the above two together
077        criteria_STATUS.addOrCriteria(criteria_UNDELIVERED);
078
079        Criteria fullQueryCriteria = new Criteria();
080        fullQueryCriteria.addIsNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE);
081        fullQueryCriteria.addLessOrEqualThan(NotificationConstants.BO_PROPERTY_NAMES.NOTIFICATION_AUTO_REMOVE_DATE_TIME, tm);
082        fullQueryCriteria.addAndCriteria(criteria_STATUS);
083
084        Collection<NotificationMessageDelivery> messageDeliveries = businessObjectDao.findMatching(NotificationMessageDelivery.class, fullQueryCriteria, true, RiceConstants.NO_WAIT);
085     
086        return messageDeliveries;
087        }
088
089        /**
090         * This overridden method ...
091         * 
092         * @see org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao#getLockedDeliveries(java.lang.Class, org.kuali.rice.core.framework.persistence.dao.GenericDao)
093         */
094        @Override
095        public Collection<NotificationMessageDelivery> getLockedDeliveries(
096                        Class clazz, GenericDao dao) {
097        Criteria criteria = new Criteria();
098        criteria.addNotNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE);
099        Collection<NotificationMessageDelivery> lockedDeliveries = dao.findMatching(clazz, criteria);
100        
101        return lockedDeliveries;
102        }
103
104}