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