View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ken.dao.impl;
17  
18  import org.apache.log4j.Logger;
19  import org.apache.ojb.broker.query.Criteria;
20  import org.kuali.rice.core.api.util.RiceConstants;
21  import org.kuali.rice.core.framework.persistence.dao.GenericDao;
22  import org.kuali.rice.ken.bo.NotificationMessageDelivery;
23  import org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao;
24  import org.kuali.rice.ken.util.NotificationConstants;
25  import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
26  
27  import java.sql.Timestamp;
28  import java.util.Collection;
29  
30  /**
31   * This is a description of what this class does - g1zhang don't forget to fill this in. 
32   * 
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   *
35   */
36  public class NotificationMessegeDeliveryDaoOjb extends PersistenceBrokerDaoSupport implements
37  		NotificationMessegeDeliveryDao {
38  
39  	private static final Logger LOG = Logger.getLogger(NotificationDaoOjb.class);
40  	
41  	/**
42  	 * This overridden method ...
43  	 * 
44  	 * @see org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao#getUndeliveredMessageDelivers()
45  	 */
46  	@Override
47  	public Collection getUndeliveredMessageDelivers(GenericDao businessObjectDao) {
48  		
49  		//LOG.info("************************calling OJBNotificationMessegeDeliveryDao.getUndeliveredMessageDelivers************************ ");
50  		
51          Criteria criteria = new Criteria();
52          criteria.addEqualTo(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.UNDELIVERED);
53          criteria.addIsNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE);
54          Collection<NotificationMessageDelivery> messageDeliveries = businessObjectDao.findMatching(NotificationMessageDelivery.class, criteria, true, RiceConstants.NO_WAIT);
55  
56          return messageDeliveries;
57  	}
58  
59  	/**
60  	 * This overridden method ...
61  	 * 
62  	 * @see org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao#getMessageDeliveriesForAutoRemoval(org.kuali.rice.core.framework.persistence.dao.GenericDao)
63  	 */
64  	@Override
65  	public Collection<NotificationMessageDelivery> getMessageDeliveriesForAutoRemoval(Timestamp tm, GenericDao businessObjectDao) {
66  		
67  		//LOG.info("************************calling OJBNotificationMessegeDeliveryDao.getMessageDeliveriesForAutoRemoval************************ ");
68  		
69          // get all UNDELIVERED/DELIVERED notification notification message delivery records with associated notifications that have and autoRemovalDateTime <= current
70          Criteria criteria_STATUS = new Criteria();
71          criteria_STATUS.addEqualTo(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.DELIVERED);
72  
73          Criteria criteria_UNDELIVERED = new Criteria();
74          criteria_UNDELIVERED.addEqualTo(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.UNDELIVERED);
75  
76          // now OR the above two together
77          criteria_STATUS.addOrCriteria(criteria_UNDELIVERED);
78  
79          Criteria fullQueryCriteria = new Criteria();
80          fullQueryCriteria.addIsNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE);
81          fullQueryCriteria.addLessOrEqualThan(NotificationConstants.BO_PROPERTY_NAMES.NOTIFICATION_AUTO_REMOVE_DATE_TIME, tm);
82          fullQueryCriteria.addAndCriteria(criteria_STATUS);
83  
84          Collection<NotificationMessageDelivery> messageDeliveries = businessObjectDao.findMatching(NotificationMessageDelivery.class, fullQueryCriteria, true, RiceConstants.NO_WAIT);
85       
86          return messageDeliveries;
87  	}
88  
89  	/**
90  	 * This overridden method ...
91  	 * 
92  	 * @see org.kuali.rice.ken.dao.NotificationMessegeDeliveryDao#getLockedDeliveries(java.lang.Class, org.kuali.rice.core.framework.persistence.dao.GenericDao)
93  	 */
94  	@Override
95  	public Collection<NotificationMessageDelivery> getLockedDeliveries(
96  			Class clazz, GenericDao dao) {
97          Criteria criteria = new Criteria();
98          criteria.addNotNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE);
99          Collection<NotificationMessageDelivery> lockedDeliveries = dao.findMatching(clazz, criteria);
100         
101         return lockedDeliveries;
102 	}
103 
104 }