001    /**
002     * Copyright 2005-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.kew.rule.dao.impl;
017    
018    import java.util.List;
019    
020    import org.apache.ojb.broker.query.Criteria;
021    import org.apache.ojb.broker.query.QueryByCriteria;
022    import org.kuali.rice.kew.rule.bo.RuleAttribute;
023    import org.kuali.rice.kew.rule.dao.RuleAttributeDAO;
024    import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
025    
026    
027    public class RuleAttributeDAOOjbImpl extends PersistenceBrokerDaoSupport implements RuleAttributeDAO {
028    
029            private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RuleAttributeDAOOjbImpl.class);
030    
031            public void save(RuleAttribute ruleAttribute) {
032                    this.getPersistenceBrokerTemplate().store(ruleAttribute);
033            }
034    
035            public void delete(String ruleAttributeId) {
036                    this.getPersistenceBrokerTemplate().delete(findByRuleAttributeId(ruleAttributeId));
037            }
038    
039            public RuleAttribute findByRuleAttributeId(String ruleAttributeId) {
040                    RuleAttribute ruleAttribute = new RuleAttribute();
041                    ruleAttribute.setId(ruleAttributeId);
042                    return (RuleAttribute) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(ruleAttribute));
043            }
044    
045            public List<RuleAttribute> findByRuleAttribute(RuleAttribute ruleAttribute) {
046                    Criteria crit = new Criteria();
047                    if (ruleAttribute.getName() != null) {
048                            crit.addSql("UPPER(RULE_ATTRIB_NM) like '" + ruleAttribute.getName().toUpperCase() + "'");
049                    }
050                    if (ruleAttribute.getResourceDescriptor() != null) {
051                            crit.addSql("UPPER(RULE_ATTRIB_CLS_NM) like '" + ruleAttribute.getResourceDescriptor().toUpperCase() + "'");
052                    }
053                    if (ruleAttribute.getType() != null) {
054                            crit.addSql("UPPER(RULE_ATTRIB_TYP) like '" + ruleAttribute.getType().toUpperCase() + "'");
055                    }
056                    return (List<RuleAttribute>) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleAttribute.class, crit));
057    
058            }
059    
060            public List<RuleAttribute> getAllRuleAttributes() {
061                    return (List<RuleAttribute>) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleAttribute.class));
062            }
063    
064            public RuleAttribute findByName(String name) {
065                    LOG.debug("findByName name=" + name);
066                    Criteria crit = new Criteria();
067                    crit.addEqualTo("name", name);
068                    return (RuleAttribute) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(RuleAttribute.class, crit));
069            }
070    
071            public List<RuleAttribute> findByClassName(String classname) {
072                    Criteria crit = new Criteria();
073                    crit.addEqualTo("resourceDescriptor", classname);
074                    return (List<RuleAttribute>) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleAttribute.class, crit));
075            }
076    
077    }