Coverage Report - org.kuali.rice.kew.rule.dao.impl.RuleTemplateDAOOjbImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
RuleTemplateDAOOjbImpl
0%
0/27
0%
0/6
1.444
RuleTemplateDAOOjbImpl$1
0%
0/2
N/A
1.444
 
 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.ojb.broker.PersistenceBroker;
 19  
 import org.apache.ojb.broker.query.Criteria;
 20  
 import org.apache.ojb.broker.query.QueryByCriteria;
 21  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 22  
 import org.kuali.rice.core.api.util.RiceConstants;
 23  
 import org.kuali.rice.core.framework.persistence.platform.DatabasePlatform;
 24  
 import org.kuali.rice.kew.rule.bo.RuleTemplateBo;
 25  
 import org.kuali.rice.kew.rule.dao.RuleTemplateDAO;
 26  
 import org.springmodules.orm.ojb.PersistenceBrokerCallback;
 27  
 import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
 28  
 
 29  
 import java.util.ArrayList;
 30  
 import java.util.Iterator;
 31  
 import java.util.List;
 32  
 
 33  
 
 34  0
 public class RuleTemplateDAOOjbImpl extends PersistenceBrokerDaoSupport implements RuleTemplateDAO {
 35  
 
 36  
 
 37  
     public List<RuleTemplateBo> findAll() {
 38  0
         QueryByCriteria query = new QueryByCriteria(RuleTemplateBo.class);
 39  0
         query.addOrderByAscending("name");
 40  0
         return (List)this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
 41  
     }
 42  
 
 43  
     public RuleTemplateBo findByRuleTemplateName(String ruleTemplateName) {
 44  0
         Criteria crit = new Criteria();
 45  0
         crit.addEqualTo("name", ruleTemplateName);
 46  0
         QueryByCriteria query = new QueryByCriteria(RuleTemplateBo.class, crit);
 47  0
         query.addOrderByDescending("id");
 48  
 
 49  0
         Iterator ruleTemplates = this.getPersistenceBrokerTemplate().getCollectionByQuery(query).iterator();
 50  0
         while(ruleTemplates.hasNext()) {
 51  0
             return (RuleTemplateBo) ruleTemplates.next();
 52  
         }
 53  0
         return null;
 54  
     }
 55  
 
 56  
     public List<RuleTemplateBo> findByRuleTemplate(RuleTemplateBo ruleTemplate) {
 57  0
         Criteria crit = new Criteria();
 58  0
         if (ruleTemplate.getName() != null) {
 59  0
           crit.addSql("UPPER(RULE_TMPL_NM) like '"+ ruleTemplate.getName().toUpperCase() +"'");
 60  
         }
 61  0
         if (ruleTemplate.getDescription() != null) {
 62  0
           crit.addSql("UPPER(RULE_TMPL_DESC) like '"+ ruleTemplate.getDescription().toUpperCase()+"'");
 63  
         }
 64  0
         return new ArrayList<RuleTemplateBo>(this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleTemplateBo.class, crit)));
 65  
     }
 66  
 
 67  
     public void delete(String ruleTemplateId) {
 68  0
             this.getPersistenceBrokerTemplate().delete(findByRuleTemplateId(ruleTemplateId));
 69  0
     }
 70  
 
 71  
     public RuleTemplateBo findByRuleTemplateId(String ruleTemplateId) {
 72  0
         Criteria crit = new Criteria();
 73  0
         crit.addEqualTo("id", ruleTemplateId);
 74  0
         return (RuleTemplateBo) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(RuleTemplateBo.class, crit));
 75  
     }
 76  
 
 77  
     public void save(RuleTemplateBo ruleTemplate) {
 78  0
             this.getPersistenceBrokerTemplate().store(ruleTemplate);
 79  0
     }
 80  
 
 81  
     public String getNextRuleTemplateId() {
 82  0
         return (String)this.getPersistenceBrokerTemplate().execute(new PersistenceBrokerCallback() {
 83  
             public Object doInPersistenceBroker(PersistenceBroker broker) {
 84  0
                       return String.valueOf(getPlatform().getNextValSQL("KREW_RTE_TMPL_S", broker));
 85  
             }
 86  
         });
 87  
     }
 88  
 
 89  
     protected DatabasePlatform getPlatform() {
 90  0
             return (DatabasePlatform)GlobalResourceLoader.getService(RiceConstants.DB_PLATFORM);
 91  
     }
 92  
 
 93  
 
 94  
 }