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