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-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.kew.rule.dao.impl;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 20  
 import org.kuali.rice.core.api.util.RiceConstants;
 21  
 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
 22  
 import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria;
 23  
 import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria;
 24  
 import org.kuali.rice.core.framework.persistence.platform.DatabasePlatform;
 25  
 import org.kuali.rice.kew.rule.bo.RuleTemplateBo;
 26  
 import org.kuali.rice.kew.rule.dao.RuleTemplateDAO;
 27  
 
 28  
 import javax.persistence.EntityManager;
 29  
 import javax.persistence.PersistenceContext;
 30  
 import java.util.List;
 31  
 
 32  
 
 33  
 
 34  0
 public class RuleTemplateDAOJpaImpl implements RuleTemplateDAO {
 35  
 
 36  
         @PersistenceContext(unitName="kew-unit")
 37  
         private EntityManager entityManager;
 38  
         
 39  
     public List<RuleTemplateBo> findAll() {
 40  0
         return entityManager.createNamedQuery("findAllOrderedByName").getResultList();
 41  
     }
 42  
 
 43  
     public RuleTemplateBo findByRuleTemplateName(String ruleTemplateName) {
 44  0
         if (StringUtils.isBlank(ruleTemplateName)) {
 45  0
                 return null;
 46  
         }
 47  
             
 48  0
             Criteria crit = new Criteria(RuleTemplateBo.class.getName());
 49  0
         crit.eq("name", ruleTemplateName);
 50  0
         crit.orderBy("ruleTemplateId", false);
 51  
         
 52  0
         List ruleTemplates =  new QueryByCriteria(entityManager, crit).toQuery().getResultList();
 53  
         
 54  0
         if(ruleTemplates==null||ruleTemplates.size()==0){
 55  0
                 return null;
 56  
         }
 57  0
         return (RuleTemplateBo) ruleTemplates.get(0);
 58  
     }
 59  
 
 60  
     public List<RuleTemplateBo> findByRuleTemplate(RuleTemplateBo ruleTemplate) {
 61  0
         Criteria crit = new Criteria(RuleTemplateBo.class.getName());
 62  0
         if (ruleTemplate.getName() != null) {
 63  0
           crit.rawJpql("UPPER(RULE_TMPL_NM) like '"+ ruleTemplate.getName().toUpperCase() +"'");
 64  
         }
 65  0
         if (ruleTemplate.getDescription() != null) {
 66  0
           crit.rawJpql("UPPER(RULE_TMPL_DESC) like '"+ ruleTemplate.getDescription().toUpperCase()+"'");
 67  
         }
 68  0
         return new QueryByCriteria(entityManager, crit).toQuery().getResultList();
 69  
     }
 70  
 
 71  
     public void delete(String ruleTemplateId) {
 72  0
             entityManager.remove(findByRuleTemplateId(ruleTemplateId));
 73  0
     }
 74  
 
 75  
     public RuleTemplateBo findByRuleTemplateId(String ruleTemplateId) {
 76  0
         return entityManager.find(RuleTemplateBo.class, ruleTemplateId);
 77  
      }
 78  
 
 79  
     public void save(RuleTemplateBo ruleTemplate) {
 80  0
             if(ruleTemplate.getId()==null){
 81  0
                     entityManager.persist(ruleTemplate);
 82  
             }else{
 83  0
                     OrmUtils.merge(entityManager, ruleTemplate);
 84  
             }
 85  0
     }
 86  
 
 87  
     public String getNextRuleTemplateId() {
 88  0
        return String.valueOf(getPlatform().getNextValSQL("KREW_RTE_TMPL_S", entityManager));
 89  
     }
 90  
 
 91  
     protected DatabasePlatform getPlatform() {
 92  0
             return (DatabasePlatform)GlobalResourceLoader.getService(RiceConstants.DB_PLATFORM);
 93  
     }
 94  
 
 95  
     public EntityManager getEntityManager() {
 96  0
         return this.entityManager;
 97  
     }
 98  
 
 99  
     public void setEntityManager(EntityManager entityManager) {
 100  0
         this.entityManager = entityManager;
 101  0
     }
 102  
 
 103  
 
 104  
 }