001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.routetemplate.dao;
018:
019: import java.util.Iterator;
020: import java.util.List;
021:
022: import org.apache.ojb.broker.PersistenceBroker;
023: import org.apache.ojb.broker.query.Criteria;
024: import org.apache.ojb.broker.query.QueryByCriteria;
025: import org.kuali.rice.resourceloader.GlobalResourceLoader;
026: import org.springmodules.orm.ojb.PersistenceBrokerCallback;
027: import org.springmodules.orm.ojb.PersistenceBrokerTemplate;
028: import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
029:
030: import edu.iu.uis.eden.KEWServiceLocator;
031: import edu.iu.uis.eden.database.platform.Platform;
032: import edu.iu.uis.eden.routetemplate.RuleTemplate;
033:
034: public class RuleTemplateDAOOjbImpl extends PersistenceBrokerDaoSupport
035: implements RuleTemplateDAO {
036:
037: public List findAll() {
038: QueryByCriteria query = new QueryByCriteria(RuleTemplate.class);
039: query.addOrderByAscending("name");
040: return (List) this .getPersistenceBrokerTemplate()
041: .getCollectionByQuery(query);
042: }
043:
044: public RuleTemplate findByRuleTemplateName(String ruleTemplateName) {
045: Criteria crit = new Criteria();
046: crit.addEqualTo("name", ruleTemplateName);
047: QueryByCriteria query = new QueryByCriteria(RuleTemplate.class,
048: crit);
049: query.addOrderByDescending("ruleTemplateId");
050:
051: Iterator ruleTemplates = this .getPersistenceBrokerTemplate()
052: .getCollectionByQuery(query).iterator();
053: while (ruleTemplates.hasNext()) {
054: return (RuleTemplate) ruleTemplates.next();
055: }
056: return null;
057: }
058:
059: public List findByRuleTemplate(RuleTemplate ruleTemplate) {
060: Criteria crit = new Criteria();
061: if (ruleTemplate.getName() != null) {
062: crit.addSql("UPPER(RULE_TMPL_NM) like '"
063: + ruleTemplate.getName().toUpperCase() + "'");
064: }
065: if (ruleTemplate.getDescription() != null) {
066: crit
067: .addSql("UPPER(RULE_TMPL_DESC) like '"
068: + ruleTemplate.getDescription()
069: .toUpperCase() + "'");
070: }
071: return (List) this .getPersistenceBrokerTemplate()
072: .getCollectionByQuery(
073: new QueryByCriteria(RuleTemplate.class, crit));
074: }
075:
076: public void delete(Long ruleTemplateId) {
077: this .getPersistenceBrokerTemplate().delete(
078: findByRuleTemplateId(ruleTemplateId));
079: }
080:
081: public RuleTemplate findByRuleTemplateId(Long ruleTemplateId) {
082: Criteria crit = new Criteria();
083: crit.addEqualTo("ruleTemplateId", ruleTemplateId);
084: return (RuleTemplate) this .getPersistenceBrokerTemplate()
085: .getObjectByQuery(
086: new QueryByCriteria(RuleTemplate.class, crit));
087: }
088:
089: public void save(RuleTemplate ruleTemplate) {
090: this .getPersistenceBrokerTemplate().store(ruleTemplate);
091: }
092:
093: public Long getNextRuleTemplateId() {
094: return (Long) this .getPersistenceBrokerTemplate().execute(
095: new PersistenceBrokerCallback() {
096: public Object doInPersistenceBroker(
097: PersistenceBroker broker) {
098: return getPlatform().getNextValSQL(
099: "SEQ_ROUTE_TEMPLATE", broker);
100: }
101: });
102: }
103:
104: protected Platform getPlatform() {
105: return (Platform) GlobalResourceLoader
106: .getService(KEWServiceLocator.DB_PLATFORM);
107: }
108:
109: }
|