Coverage Report - org.kuali.rice.kew.rule.dao.impl.RuleTemplateDAOJpaImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
RuleTemplateDAOJpaImpl
0%
0/29
0%
0/12
1.8
 
 1  
 /*
 2  
  * Copyright 2005-2008 The Kuali Foundation
 3  
  * 
 4  
  * 
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  * 
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.rule.dao.impl;
 18  
 
 19  
 import java.util.List;
 20  
 
 21  
 import javax.persistence.EntityManager;
 22  
 import javax.persistence.PersistenceContext;
 23  
 
 24  
 import org.apache.commons.lang.StringUtils;
 25  
 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
 26  
 import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria;
 27  
 import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria;
 28  
 import org.kuali.rice.core.framework.persistence.platform.DatabasePlatform;
 29  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 30  
 import org.kuali.rice.core.util.RiceConstants;
 31  
 import org.kuali.rice.kew.rule.bo.RuleTemplate;
 32  
 import org.kuali.rice.kew.rule.dao.RuleTemplateDAO;
 33  
 
 34  
 
 35  
 
 36  0
 public class RuleTemplateDAOJpaImpl implements RuleTemplateDAO {
 37  
 
 38  
         @PersistenceContext(unitName="kew-unit")
 39  
         private EntityManager entityManager;
 40  
         
 41  
     public List findAll() {
 42  0
         return entityManager.createNamedQuery("findAllOrderedByName").getResultList();
 43  
     }
 44  
 
 45  
     public RuleTemplate findByRuleTemplateName(String ruleTemplateName) {
 46  0
         if (StringUtils.isBlank(ruleTemplateName)) {
 47  0
                 return null;
 48  
         }
 49  
             
 50  0
             Criteria crit = new Criteria(RuleTemplate.class.getName());
 51  0
         crit.eq("name", ruleTemplateName);
 52  0
         crit.orderBy("ruleTemplateId", false);
 53  
         
 54  0
         List ruleTemplates =  new QueryByCriteria(entityManager, crit).toQuery().getResultList();
 55  
         
 56  0
         if(ruleTemplates==null||ruleTemplates.size()==0){
 57  0
                 return null;
 58  
         }
 59  0
         return (RuleTemplate) ruleTemplates.get(0);
 60  
     }
 61  
 
 62  
     public List findByRuleTemplate(RuleTemplate ruleTemplate) {
 63  0
         Criteria crit = new Criteria(RuleTemplate.class.getName());
 64  0
         if (ruleTemplate.getName() != null) {
 65  0
           crit.rawJpql("UPPER(RULE_TMPL_NM) like '"+ ruleTemplate.getName().toUpperCase() +"'");
 66  
         }
 67  0
         if (ruleTemplate.getDescription() != null) {
 68  0
           crit.rawJpql("UPPER(RULE_TMPL_DESC) like '"+ ruleTemplate.getDescription().toUpperCase()+"'");
 69  
         }
 70  0
         return new QueryByCriteria(entityManager, crit).toQuery().getResultList();
 71  
     }
 72  
 
 73  
     public void delete(Long ruleTemplateId) {
 74  0
             entityManager.remove(findByRuleTemplateId(ruleTemplateId));
 75  0
     }
 76  
 
 77  
     public RuleTemplate findByRuleTemplateId(Long ruleTemplateId) {
 78  0
         return entityManager.find(RuleTemplate.class, ruleTemplateId);
 79  
      }
 80  
 
 81  
     public void save(RuleTemplate ruleTemplate) {
 82  0
             if(ruleTemplate.getRuleTemplateId()==null){
 83  0
                     entityManager.persist(ruleTemplate);
 84  
             }else{
 85  0
                     OrmUtils.merge(entityManager, ruleTemplate);
 86  
             }
 87  0
     }
 88  
 
 89  
     public Long getNextRuleTemplateId() {
 90  0
        return getPlatform().getNextValSQL("KREW_RTE_TMPL_S", entityManager);
 91  
     }
 92  
 
 93  
     protected DatabasePlatform getPlatform() {
 94  0
             return (DatabasePlatform)GlobalResourceLoader.getService(RiceConstants.DB_PLATFORM);
 95  
     }
 96  
 
 97  
     public EntityManager getEntityManager() {
 98  0
         return this.entityManager;
 99  
     }
 100  
 
 101  
     public void setEntityManager(EntityManager entityManager) {
 102  0
         this.entityManager = entityManager;
 103  0
     }
 104  
 
 105  
 
 106  
 }