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