1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 public class RuleTemplateDAOOjbImpl extends PersistenceBrokerDaoSupport implements RuleTemplateDAO {
35
36
37 public List<RuleTemplateBo> findAll() {
38 QueryByCriteria query = new QueryByCriteria(RuleTemplateBo.class);
39 query.addOrderByAscending("name");
40 return (List)this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
41 }
42
43 public RuleTemplateBo findByRuleTemplateName(String ruleTemplateName) {
44 Criteria crit = new Criteria();
45 crit.addEqualTo("name", ruleTemplateName);
46 QueryByCriteria query = new QueryByCriteria(RuleTemplateBo.class, crit);
47 query.addOrderByDescending("id");
48
49 Iterator ruleTemplates = this.getPersistenceBrokerTemplate().getCollectionByQuery(query).iterator();
50 while(ruleTemplates.hasNext()) {
51 return (RuleTemplateBo) ruleTemplates.next();
52 }
53 return null;
54 }
55
56 public List<RuleTemplateBo> findByRuleTemplate(RuleTemplateBo ruleTemplate) {
57 Criteria crit = new Criteria();
58 if (ruleTemplate.getName() != null) {
59 crit.addSql("UPPER(RULE_TMPL_NM) like '"+ ruleTemplate.getName().toUpperCase() +"'");
60 }
61 if (ruleTemplate.getDescription() != null) {
62 crit.addSql("UPPER(RULE_TMPL_DESC) like '"+ ruleTemplate.getDescription().toUpperCase()+"'");
63 }
64 return new ArrayList<RuleTemplateBo>(this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleTemplateBo.class, crit)));
65 }
66
67 public void delete(String ruleTemplateId) {
68 this.getPersistenceBrokerTemplate().delete(findByRuleTemplateId(ruleTemplateId));
69 }
70
71 public RuleTemplateBo findByRuleTemplateId(String ruleTemplateId) {
72 Criteria crit = new Criteria();
73 crit.addEqualTo("id", ruleTemplateId);
74 return (RuleTemplateBo) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(RuleTemplateBo.class, crit));
75 }
76
77 public void save(RuleTemplateBo ruleTemplate) {
78 this.getPersistenceBrokerTemplate().store(ruleTemplate);
79 }
80
81 public String getNextRuleTemplateId() {
82 return (String)this.getPersistenceBrokerTemplate().execute(new PersistenceBrokerCallback() {
83 public Object doInPersistenceBroker(PersistenceBroker broker) {
84 return String.valueOf(getPlatform().getNextValSQL("KREW_RTE_TMPL_S", broker));
85 }
86 });
87 }
88
89 protected DatabasePlatform getPlatform() {
90 return (DatabasePlatform)GlobalResourceLoader.getService(RiceConstants.DB_PLATFORM);
91 }
92
93
94 }