View Javadoc

1   /**
2    * Copyright 2005-2012 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 java.util.List;
19  
20  import org.apache.ojb.broker.query.Criteria;
21  import org.apache.ojb.broker.query.QueryByCriteria;
22  import org.kuali.rice.kew.rule.bo.RuleAttribute;
23  import org.kuali.rice.kew.rule.dao.RuleAttributeDAO;
24  import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
25  
26  
27  public class RuleAttributeDAOOjbImpl extends PersistenceBrokerDaoSupport implements RuleAttributeDAO {
28  
29  	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RuleAttributeDAOOjbImpl.class);
30  
31  	public void save(RuleAttribute ruleAttribute) {
32  		this.getPersistenceBrokerTemplate().store(ruleAttribute);
33  	}
34  
35  	public void delete(String ruleAttributeId) {
36  		this.getPersistenceBrokerTemplate().delete(findByRuleAttributeId(ruleAttributeId));
37  	}
38  
39  	public RuleAttribute findByRuleAttributeId(String ruleAttributeId) {
40  		RuleAttribute ruleAttribute = new RuleAttribute();
41  		ruleAttribute.setId(ruleAttributeId);
42  		return (RuleAttribute) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(ruleAttribute));
43  	}
44  
45  	public List<RuleAttribute> findByRuleAttribute(RuleAttribute ruleAttribute) {
46  		Criteria crit = new Criteria();
47  		if (ruleAttribute.getName() != null) {
48  			crit.addSql("UPPER(RULE_ATTRIB_NM) like '" + ruleAttribute.getName().toUpperCase() + "'");
49  		}
50  		if (ruleAttribute.getResourceDescriptor() != null) {
51  			crit.addSql("UPPER(RULE_ATTRIB_CLS_NM) like '" + ruleAttribute.getResourceDescriptor().toUpperCase() + "'");
52  		}
53  		if (ruleAttribute.getType() != null) {
54  			crit.addSql("UPPER(RULE_ATTRIB_TYP) like '" + ruleAttribute.getType().toUpperCase() + "'");
55  		}
56  		return (List<RuleAttribute>) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleAttribute.class, crit));
57  
58  	}
59  
60  	public List<RuleAttribute> getAllRuleAttributes() {
61  		return (List<RuleAttribute>) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleAttribute.class));
62  	}
63  
64  	public RuleAttribute findByName(String name) {
65  		LOG.debug("findByName name=" + name);
66  		Criteria crit = new Criteria();
67  		crit.addEqualTo("name", name);
68  		return (RuleAttribute) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(RuleAttribute.class, crit));
69  	}
70  
71  	public List<RuleAttribute> findByClassName(String classname) {
72  		Criteria crit = new Criteria();
73  		crit.addEqualTo("resourceDescriptor", classname);
74  		return (List<RuleAttribute>) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleAttribute.class, crit));
75  	}
76  
77  }