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.List; |
20 | |
|
21 | |
import javax.persistence.EntityManager; |
22 | |
import javax.persistence.PersistenceContext; |
23 | |
|
24 | |
import org.kuali.rice.core.database.platform.DatabasePlatform; |
25 | |
import org.kuali.rice.core.jpa.criteria.Criteria; |
26 | |
import org.kuali.rice.core.jpa.criteria.QueryByCriteria; |
27 | |
import org.kuali.rice.core.resourceloader.GlobalResourceLoader; |
28 | |
import org.kuali.rice.core.util.OrmUtils; |
29 | |
import org.kuali.rice.core.util.RiceConstants; |
30 | |
import org.kuali.rice.kew.rule.bo.RuleTemplate; |
31 | |
import org.kuali.rice.kew.rule.dao.RuleTemplateDAO; |
32 | |
|
33 | |
|
34 | |
|
35 | 0 | public class RuleTemplateDAOJpaImpl implements RuleTemplateDAO { |
36 | |
|
37 | |
@PersistenceContext(unitName="kew-unit") |
38 | |
private EntityManager entityManager; |
39 | |
|
40 | |
public List findAll() { |
41 | 0 | return entityManager.createNamedQuery("findAllOrderedByName").getResultList(); |
42 | |
} |
43 | |
|
44 | |
public RuleTemplate findByRuleTemplateName(String ruleTemplateName) { |
45 | |
|
46 | 0 | Criteria crit = new Criteria(RuleTemplate.class.getName()); |
47 | 0 | crit.eq("name", ruleTemplateName); |
48 | 0 | crit.orderBy("ruleTemplateId", false); |
49 | |
|
50 | 0 | List ruleTemplates = new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
51 | |
|
52 | 0 | if(ruleTemplates==null||ruleTemplates.size()==0){ |
53 | 0 | return null; |
54 | |
} |
55 | 0 | return (RuleTemplate) ruleTemplates.get(0); |
56 | |
} |
57 | |
|
58 | |
public List findByRuleTemplate(RuleTemplate ruleTemplate) { |
59 | 0 | Criteria crit = new Criteria(RuleTemplate.class.getName()); |
60 | 0 | if (ruleTemplate.getName() != null) { |
61 | 0 | crit.rawJpql("UPPER(RULE_TMPL_NM) like '"+ ruleTemplate.getName().toUpperCase() +"'"); |
62 | |
} |
63 | 0 | if (ruleTemplate.getDescription() != null) { |
64 | 0 | crit.rawJpql("UPPER(RULE_TMPL_DESC) like '"+ ruleTemplate.getDescription().toUpperCase()+"'"); |
65 | |
} |
66 | 0 | return new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
67 | |
} |
68 | |
|
69 | |
public void delete(Long ruleTemplateId) { |
70 | 0 | entityManager.remove(findByRuleTemplateId(ruleTemplateId)); |
71 | 0 | } |
72 | |
|
73 | |
public RuleTemplate findByRuleTemplateId(Long ruleTemplateId) { |
74 | 0 | return entityManager.find(RuleTemplate.class, ruleTemplateId); |
75 | |
} |
76 | |
|
77 | |
public void save(RuleTemplate ruleTemplate) { |
78 | 0 | if(ruleTemplate.getRuleTemplateId()==null){ |
79 | 0 | entityManager.persist(ruleTemplate); |
80 | |
}else{ |
81 | 0 | OrmUtils.merge(entityManager, ruleTemplate); |
82 | |
} |
83 | 0 | } |
84 | |
|
85 | |
public Long getNextRuleTemplateId() { |
86 | 0 | return getPlatform().getNextValSQL("KREW_RTE_TMPL_S", entityManager); |
87 | |
} |
88 | |
|
89 | |
protected DatabasePlatform getPlatform() { |
90 | 0 | return (DatabasePlatform)GlobalResourceLoader.getService(RiceConstants.DB_PLATFORM); |
91 | |
} |
92 | |
|
93 | |
public EntityManager getEntityManager() { |
94 | 0 | return this.entityManager; |
95 | |
} |
96 | |
|
97 | |
public void setEntityManager(EntityManager entityManager) { |
98 | 0 | this.entityManager = entityManager; |
99 | 0 | } |
100 | |
|
101 | |
|
102 | |
} |