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.framework.persistence.jpa.OrmUtils;
25 import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria;
26 import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria;
27 import org.kuali.rice.kew.rule.bo.RuleAttribute;
28 import org.kuali.rice.kew.rule.dao.RuleAttributeDAO;
29
30
31 public class RuleAttributeDAOJpaImpl implements RuleAttributeDAO {
32
33 @PersistenceContext
34 private EntityManager entityManager;
35
36 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RuleAttributeDAOJpaImpl.class);
37
38
39
40
41 public EntityManager getEntityManager() {
42 return this.entityManager;
43 }
44
45
46
47
48 public void setEntityManager(EntityManager entityManager) {
49 this.entityManager = entityManager;
50 }
51
52 public void save(RuleAttribute ruleAttribute) {
53 if (ruleAttribute.getRuleAttributeId() == null) {
54 entityManager.persist(ruleAttribute);
55 } else {
56 OrmUtils.merge(entityManager, ruleAttribute);
57 }
58 }
59
60 public void delete(Long ruleAttributeId) {
61 entityManager.remove(findByRuleAttributeId(ruleAttributeId));
62 }
63
64 public RuleAttribute findByRuleAttributeId(Long ruleAttributeId) {
65 return (RuleAttribute) entityManager.createNamedQuery("RuleAttribute.FindById").setParameter("ruleAttributeId", ruleAttributeId).getSingleResult();
66 }
67
68 public List findByRuleAttribute(RuleAttribute ruleAttribute) {
69 Criteria crit = new Criteria("RuleAttribute", "ra");
70
71 if (ruleAttribute.getName() != null) {
72 crit.rawJpql("UPPER(RULE_ATTRIB_NM) like '" + ruleAttribute.getName().toUpperCase() + "'");
73 }
74
75 if (ruleAttribute.getClassName() != null) {
76 crit.rawJpql("UPPER(RULE_ATTRIB_CLS_NM) like '" + ruleAttribute.getClassName().toUpperCase() + "'");
77 }
78 if (ruleAttribute.getType() != null) {
79 crit.rawJpql("UPPER(RULE_ATTRIB_TYP) like '" + ruleAttribute.getType().toUpperCase() + "'");
80 }
81 return new QueryByCriteria(entityManager, crit).toQuery().getResultList();
82
83 }
84
85 public List getAllRuleAttributes() {
86 return entityManager.createNamedQuery("RuleAttribute.GetAllRuleAttributes").getResultList();
87 }
88
89 public RuleAttribute findByName(String name) {
90 LOG.debug("findByName name=" + name);
91 return (RuleAttribute) entityManager.createNamedQuery("RuleAttribute.FindByName").setParameter("name", name).getSingleResult();
92 }
93
94 public RuleAttribute findByClassName(String classname) {
95 LOG.debug("findByClassName classname=" + classname);
96
97
98 List<RuleAttribute> ruleAttributes = entityManager.createNamedQuery("RuleAttribute.FindByClassName").setParameter("className", classname).getResultList();
99
100 return (ruleAttributes.size() > 0 ? ruleAttributes.get(0) : null);
101 }
102
103 }