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