Coverage Report - org.kuali.rice.kew.rule.dao.impl.RuleAttributeDAOJpaImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
RuleAttributeDAOJpaImpl
0%
0/26
0%
0/10
1.556
 
 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.framework.persistence.jpa.OrmUtils;
 25  
 import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria;
 26  
 import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria;
 27  
 import org.kuali.rice.kew.rule.bo.RuleAttribute;
 28  
 import org.kuali.rice.kew.rule.dao.RuleAttributeDAO;
 29  
 
 30  
 
 31  0
 public class RuleAttributeDAOJpaImpl implements RuleAttributeDAO {
 32  
 
 33  
     @PersistenceContext
 34  
     private EntityManager entityManager;
 35  
 
 36  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RuleAttributeDAOJpaImpl.class);
 37  
    
 38  
     /**
 39  
          * @return the entityManager
 40  
          */
 41  
         public EntityManager getEntityManager() {
 42  0
                 return this.entityManager;
 43  
         }
 44  
 
 45  
         /**
 46  
          * @param entityManager the entityManager to set
 47  
          */
 48  
         public void setEntityManager(EntityManager entityManager) {
 49  0
                 this.entityManager = entityManager;
 50  0
         }
 51  
 
 52  
         public void save(RuleAttribute ruleAttribute) {
 53  0
         if (ruleAttribute.getRuleAttributeId() == null) {
 54  0
             entityManager.persist(ruleAttribute);
 55  
         } else {
 56  0
             OrmUtils.merge(entityManager, ruleAttribute);
 57  
         }
 58  0
     }
 59  
 
 60  
     public void delete(String ruleAttributeId) {
 61  0
         entityManager.remove(findByRuleAttributeId(ruleAttributeId));
 62  0
     }
 63  
 
 64  
     public RuleAttribute findByRuleAttributeId(String ruleAttributeId) {
 65  0
         return (RuleAttribute) entityManager.createNamedQuery("RuleAttribute.FindById").setParameter("ruleAttributeId", ruleAttributeId).getSingleResult();
 66  
     }
 67  
 
 68  
     public List<RuleAttribute> findByRuleAttribute(RuleAttribute ruleAttribute) {
 69  0
         Criteria crit = new Criteria("RuleAttribute", "ra");
 70  
 
 71  0
         if (ruleAttribute.getName() != null) {
 72  0
             crit.rawJpql("UPPER(RULE_ATTRIB_NM) like '" + ruleAttribute.getName().toUpperCase() + "'");
 73  
         }
 74  
 
 75  0
         if (ruleAttribute.getClassName() != null) {
 76  0
             crit.rawJpql("UPPER(RULE_ATTRIB_CLS_NM) like '" + ruleAttribute.getClassName().toUpperCase() + "'");
 77  
         }
 78  0
         if (ruleAttribute.getType() != null) {
 79  0
             crit.rawJpql("UPPER(RULE_ATTRIB_TYP) like '" + ruleAttribute.getType().toUpperCase() + "'");
 80  
         }
 81  0
         return new QueryByCriteria(entityManager, crit).toQuery().getResultList();
 82  
 
 83  
     }
 84  
 
 85  
     public List<RuleAttribute> getAllRuleAttributes() {
 86  0
         return  entityManager.createNamedQuery("RuleAttribute.GetAllRuleAttributes").getResultList();
 87  
     }
 88  
 
 89  
     public RuleAttribute findByName(String name) {
 90  0
         LOG.debug("findByName name=" + name);
 91  0
         return (RuleAttribute) entityManager.createNamedQuery("RuleAttribute.FindByName").setParameter("name", name).getSingleResult();
 92  
     }
 93  
 
 94  
     public RuleAttribute findByClassName(String classname) {
 95  0
         LOG.debug("findByClassName classname=" + classname);
 96  
 
 97  
         //FIXME: This query is returning multiple rows, which one should it return
 98  0
         List<RuleAttribute> ruleAttributes = entityManager.createNamedQuery("RuleAttribute.FindByClassName").setParameter("className", classname).getResultList();
 99  
 
 100  0
         return (ruleAttributes.size() > 0 ? ruleAttributes.get(0) : null); 
 101  
     }
 102  
 
 103  
 }