Coverage Report - org.kuali.rice.ksb.messaging.dao.impl.MessageQueueDAOOjbImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
MessageQueueDAOOjbImpl
0%
0/67
0%
0/24
2.444
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.ksb.messaging.dao.impl;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.apache.ojb.broker.query.Criteria;
 20  
 import org.apache.ojb.broker.query.QueryByCriteria;
 21  
 import org.kuali.rice.core.api.config.CoreConfigHelper;
 22  
 import org.kuali.rice.core.api.util.RiceUtilities;
 23  
 import org.kuali.rice.ksb.messaging.PersistedMessageBO;
 24  
 import org.kuali.rice.ksb.messaging.PersistedMessagePayload;
 25  
 import org.kuali.rice.ksb.messaging.dao.MessageQueueDAO;
 26  
 import org.kuali.rice.ksb.util.KSBConstants;
 27  
 import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
 28  
 
 29  
 import javax.xml.namespace.QName;
 30  
 import java.util.List;
 31  
 import java.util.Map;
 32  
 
 33  
 
 34  0
 public class MessageQueueDAOOjbImpl extends PersistenceBrokerDaoSupport implements MessageQueueDAO {
 35  
 
 36  0
         private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MessageQueueDAOOjbImpl.class);
 37  
 
 38  
         public void remove(PersistedMessageBO routeQueue) {
 39  0
                 if (LOG.isDebugEnabled()) {
 40  0
                         LOG.debug("Removing message " + routeQueue);
 41  
                 }
 42  0
                 Criteria crit = new Criteria();
 43  0
                 crit.addEqualTo("routeQueueId", routeQueue.getRouteQueueId());
 44  0
                 getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(PersistedMessageBO.class, crit));
 45  
 
 46  0
                 crit = new Criteria();
 47  0
                 crit.addEqualTo("routeQueueId", routeQueue.getPayload().getRouteQueueId());
 48  0
                 getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(PersistedMessagePayload.class, crit));
 49  0
         }
 50  
 
 51  
         public void save(PersistedMessageBO routeQueue) {
 52  0
                 if (LOG.isDebugEnabled()) {
 53  0
                         LOG.debug("Persisting message " + routeQueue);
 54  
                 }
 55  0
                 getPersistenceBrokerTemplate().store(routeQueue);
 56  0
                 routeQueue.getPayload().setRouteQueueId(routeQueue.getRouteQueueId());
 57  0
                 getPersistenceBrokerTemplate().store(routeQueue.getPayload());
 58  0
         }
 59  
 
 60  
         @SuppressWarnings("unchecked")
 61  
         public List<PersistedMessageBO> findAll() {
 62  0
                 if (LOG.isDebugEnabled()) {
 63  0
                         LOG.debug("Returning all persisted messages");
 64  
                 }
 65  0
         return (List<PersistedMessageBO>) getPersistenceBrokerTemplate().getCollectionByQuery(
 66  
                 new QueryByCriteria(PersistedMessageBO.class));
 67  
         }
 68  
 
 69  
         @SuppressWarnings("unchecked")
 70  
         public List<PersistedMessageBO> findAll(int maxRows) {
 71  0
                 if (LOG.isDebugEnabled()) {
 72  0
                         LOG.debug("Finding next " + maxRows + " messages");
 73  
                 }
 74  0
                 QueryByCriteria query = new QueryByCriteria(PersistedMessageBO.class);
 75  0
                 query.setStartAtIndex(0);
 76  0
                 query.setEndAtIndex(maxRows);
 77  0
                 return (List<PersistedMessageBO>) getPersistenceBrokerTemplate().getCollectionByQuery(query);
 78  
         }
 79  
 
 80  
         @SuppressWarnings("unchecked")
 81  
     public List<PersistedMessageBO> findByValues(Map<String, String> criteriaValues, int maxRows) {
 82  0
                 Criteria crit = new Criteria();
 83  0
                 String value = null;
 84  0
                 for (String key : criteriaValues.keySet()) {
 85  0
                         value = criteriaValues.get(key);
 86  0
                         if (StringUtils.isBlank(key) && StringUtils.isBlank(value)) {
 87  0
                 throw new IllegalArgumentException("Either the key or value was blank in criteriaValues (" + key + "="
 88  
                         + value + ")");
 89  
                         }
 90  
 
 91  
                         // auto-wildcard the statement
 92  0
             if (!key.equals("routeQueueId")) {
 93  0
                         if (value.contains("*")) {
 94  0
                                 value = value.replace("*", "%");
 95  
                         } else {
 96  0
                                 value = value.concat("%");
 97  
                         }
 98  
             }
 99  0
                 if (!StringUtils.containsOnly(value, "%")) {
 100  0
                         crit.addLike(key, value);
 101  
                 }
 102  
         }
 103  0
         QueryByCriteria query = new QueryByCriteria(PersistedMessageBO.class, crit);
 104  0
         query.setFetchSize(maxRows);
 105  0
         query.setStartAtIndex(0);
 106  0
         query.setEndAtIndex(maxRows);
 107  0
         return (List<PersistedMessageBO>) getPersistenceBrokerTemplate().getCollectionByQuery(query);
 108  
     }
 109  
 
 110  
         public PersistedMessageBO findByRouteQueueId(Long routeQueueId) {
 111  0
                 Criteria criteria = new Criteria();
 112  0
                 criteria.addEqualTo("routeQueueId", routeQueueId);
 113  0
         return (PersistedMessageBO) getPersistenceBrokerTemplate().getObjectByQuery(
 114  
                 new QueryByCriteria(PersistedMessageBO.class, criteria));
 115  
         }
 116  
 
 117  
     public PersistedMessagePayload findByPersistedMessageByRouteQueueId(Long routeQueueId) {
 118  0
         Criteria criteria = new Criteria();
 119  0
         criteria.addEqualTo("routeQueueId", routeQueueId);
 120  0
         return (PersistedMessagePayload) getPersistenceBrokerTemplate().getObjectByQuery(
 121  
                 new QueryByCriteria(PersistedMessagePayload.class, criteria));
 122  
         }
 123  
 
 124  
         @SuppressWarnings("unchecked")
 125  
         public List<PersistedMessageBO> getNextDocuments(Integer maxDocuments) {
 126  0
                 Criteria crit = new Criteria();
 127  0
                 String applicationId = CoreConfigHelper.getApplicationId();
 128  0
                 crit.addEqualTo("applicationId", applicationId);
 129  0
                 crit.addNotEqualTo("queueStatus", KSBConstants.ROUTE_QUEUE_EXCEPTION);
 130  0
                 crit.addEqualTo("ipNumber", RiceUtilities.getIpNumber());
 131  
 
 132  0
                 QueryByCriteria query = new QueryByCriteria(PersistedMessageBO.class, crit);
 133  0
                 query.addOrderByAscending("queuePriority");
 134  0
                 query.addOrderByAscending("routeQueueId");
 135  0
                 query.addOrderByAscending("queueDate");
 136  0
                 if (maxDocuments != null)
 137  0
                         query.setEndAtIndex(maxDocuments.intValue());
 138  0
                 return (List) getPersistenceBrokerTemplate().getCollectionByQuery(query);
 139  
         }
 140  
 
 141  
         @SuppressWarnings("unchecked")
 142  
         public List<PersistedMessageBO> findByServiceName(QName serviceName, String methodName) {
 143  0
                 if (LOG.isDebugEnabled()) {
 144  0
                         LOG.debug("Finding messages for service name " + serviceName);
 145  
                 }
 146  0
                 Criteria crit = new Criteria();
 147  0
                 crit.addEqualTo("serviceName", serviceName.toString());
 148  0
                 crit.addEqualTo("methodName", methodName);
 149  0
         return (List<PersistedMessageBO>) getPersistenceBrokerTemplate().getCollectionByQuery(
 150  
                 new QueryByCriteria(PersistedMessageBO.class, crit));
 151  
         }
 152  
 
 153  
 }