Coverage Report - org.kuali.rice.ksb.messaging.dao.impl.MessageQueueDAOJpaImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
MessageQueueDAOJpaImpl
0%
0/56
0%
0/20
2
 
 1  
 /*
 2  
  * Copyright 2006-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  
 
 17  
 package org.kuali.rice.ksb.messaging.dao.impl;
 18  
 
 19  
 import java.util.List;
 20  
 import java.util.Map;
 21  
 
 22  
 import javax.persistence.EntityManager;
 23  
 import javax.persistence.PersistenceContext;
 24  
 import javax.persistence.Query;
 25  
 import javax.xml.namespace.QName;
 26  
 
 27  
 import org.kuali.rice.core.api.config.CoreConfigHelper;
 28  
 import org.kuali.rice.core.api.exception.RiceRuntimeException;
 29  
 import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria;
 30  
 import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria;
 31  
 import org.kuali.rice.core.util.RiceUtilities;
 32  
 import org.kuali.rice.ksb.messaging.PersistedMessageBO;
 33  
 import org.kuali.rice.ksb.messaging.PersistedMessagePayload;
 34  
 import org.kuali.rice.ksb.messaging.dao.MessageQueueDAO;
 35  
 import org.kuali.rice.ksb.util.KSBConstants;
 36  
 
 37  
 
 38  0
 public class MessageQueueDAOJpaImpl implements MessageQueueDAO {
 39  
     
 40  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MessageQueueDAOJpaImpl.class);
 41  
     
 42  
     @PersistenceContext
 43  
     private EntityManager entityManager;
 44  
     
 45  
     @SuppressWarnings("unchecked")
 46  
     public List<PersistedMessageBO> findAll() {
 47  0
         if (LOG.isDebugEnabled()) {
 48  0
             LOG.debug("Returning all persisted messages");
 49  
         }
 50  
         
 51  0
         Query query = entityManager.createNamedQuery("PersistedMessageBO.FindAll");
 52  0
         return (List<PersistedMessageBO>) query.getResultList();
 53  
     }
 54  
 
 55  
     @SuppressWarnings("unchecked")
 56  
     public List<PersistedMessageBO> findAll(int maxRows) {
 57  0
         if (LOG.isDebugEnabled()) {
 58  0
             LOG.debug("Finding next " + maxRows + " messages");
 59  
         }
 60  
         
 61  0
         Query query = entityManager.createNamedQuery("PersistedMessageBO.FindAll");
 62  0
         query.setMaxResults(maxRows);
 63  
         
 64  0
         return (List<PersistedMessageBO>) query.getResultList();
 65  
     }
 66  
 
 67  
     
 68  
     public PersistedMessagePayload findByPersistedMessageByRouteQueueId(Long routeQueueId) {
 69  0
         return (PersistedMessagePayload) entityManager.find(PersistedMessagePayload.class, routeQueueId);
 70  
     }
 71  
 
 72  
     
 73  
     public PersistedMessageBO findByRouteQueueId(Long routeQueueId) {
 74  0
         return (PersistedMessageBO) entityManager.find(PersistedMessageBO.class, routeQueueId);
 75  
     }
 76  
 
 77  
     @SuppressWarnings("unchecked")
 78  
     public List<PersistedMessageBO> findByServiceName(QName serviceName, String methodName) {
 79  0
         if (LOG.isDebugEnabled()) {
 80  0
             LOG.debug("Finding messages for service name " + serviceName);
 81  
         }
 82  
         
 83  0
         Query query = entityManager.createNamedQuery("PersistedMessageBO.FindByServiceName");
 84  0
         query.setParameter("serviceName", serviceName.toString());
 85  0
         query.setParameter("methodName", methodName);
 86  
         
 87  0
         return (List<PersistedMessageBO>) query.getResultList();
 88  
     }
 89  
 
 90  
     @SuppressWarnings("unchecked")
 91  
     public List<PersistedMessageBO> findByValues(Map<String, String> criteriaValues, int maxRows) {
 92  0
         Criteria criteria = new Criteria(PersistedMessageBO.class.getName());
 93  0
         for(Map.Entry<String, String> entry : criteriaValues.entrySet()) {
 94  0
             criteria.eq(entry.getKey(), entry.getValue());
 95  
         }
 96  
         
 97  0
         QueryByCriteria query = new QueryByCriteria(entityManager, criteria);
 98  
         
 99  0
         return query.toQuery().getResultList();
 100  
     }
 101  
 
 102  
     @SuppressWarnings("unchecked")
 103  
     public List<PersistedMessageBO> getNextDocuments(Integer maxDocuments) {
 104  0
         String applicationId = CoreConfigHelper.getApplicationId();
 105  
         
 106  0
         Query query = entityManager.createNamedQuery("PersistedMessageBO.GetNextDocuments");
 107  0
         query.setParameter("applicationId", applicationId);
 108  0
         query.setParameter("queueStatus", KSBConstants.ROUTE_QUEUE_EXCEPTION);
 109  0
         query.setParameter("ipNumber", RiceUtilities.getIpNumber());
 110  
         
 111  0
         if (maxDocuments != null)
 112  0
             query.setMaxResults(maxDocuments);
 113  
         
 114  0
         return (List<PersistedMessageBO>) query.getResultList();
 115  
     }
 116  
 
 117  
     
 118  
     public void remove(PersistedMessageBO routeQueue) {
 119  0
         if (LOG.isDebugEnabled()) {
 120  0
             LOG.debug("Removing message " + routeQueue);
 121  
         }
 122  0
         if (routeQueue.getRouteQueueId() == null) {
 123  0
             throw new RiceRuntimeException("can't delete a PersistedMessageBO with no id");
 124  
         }
 125  
         
 126  0
         routeQueue = entityManager.merge(routeQueue);
 127  0
         entityManager.remove(routeQueue);
 128  
 
 129  0
         if (routeQueue.getPayload() != null) {
 130  0
             PersistedMessagePayload payload =  entityManager.merge(routeQueue.getPayload());
 131  0
             entityManager.remove(payload);
 132  
         }
 133  0
     }
 134  
 
 135  
     
 136  
     public void save(PersistedMessageBO routeQueue) {
 137  0
         if (LOG.isDebugEnabled()) {
 138  0
             LOG.debug("Persisting message " + routeQueue);
 139  
         }
 140  0
         PersistedMessageBO jpaInstance = entityManager.merge(routeQueue);
 141  0
         Long routeQueueId = jpaInstance.getRouteQueueId();
 142  0
         Integer verNo = jpaInstance.getLockVerNbr();
 143  0
         routeQueue.setRouteQueueId(routeQueueId);
 144  0
         routeQueue.setLockVerNbr(verNo);
 145  
 
 146  0
         if (routeQueue.getPayload() != null) {
 147  0
             routeQueue.getPayload().setRouteQueueId(routeQueueId);
 148  0
             entityManager.merge(routeQueue.getPayload());
 149  
         }
 150  0
     }
 151  
 
 152  
     public EntityManager getEntityManager() {
 153  0
         return this.entityManager;
 154  
     }
 155  
 
 156  
     public void setEntityManager(EntityManager entityManager) {
 157  0
         this.entityManager = entityManager;
 158  0
     }
 159  
 
 160  
 }