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