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