1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.edl.impl.dao.impl;
17
18 import java.util.ArrayList;
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.edl.impl.bo.EDocLiteAssociation;
28 import org.kuali.rice.edl.impl.bo.EDocLiteDefinition;
29 import org.kuali.rice.edl.impl.dao.EDocLiteDAO;
30
31
32
33
34
35
36 public class EDocLiteDAOJpaImpl implements EDocLiteDAO {
37 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(EDocLiteDAOJpaImpl.class);
38
39 private static final String ACTIVE_IND_CRITERIA = "activeInd";
40 private static final String NAME_CRITERIA = "name";
41
42 @PersistenceContext(unitName = "kew-unit")
43 private EntityManager entityManager;
44
45
46
47
48
49
50 public void saveEDocLiteDefinition(final EDocLiteDefinition edocLiteData) {
51 if (edocLiteData.getEDocLiteDefId() == null) {
52 entityManager.persist(edocLiteData);
53 } else {
54 OrmUtils.merge(entityManager, edocLiteData);
55 }
56 }
57
58
59
60
61
62
63 public void saveEDocLiteAssociation(final EDocLiteAssociation assoc) {
64 if (assoc.getEdocLiteAssocId() == null) {
65 entityManager.persist(assoc);
66 } else {
67 OrmUtils.merge(entityManager, assoc);
68 }
69 }
70
71
72
73
74
75
76 public EDocLiteDefinition getEDocLiteDefinition(final String defName) {
77 final Criteria crit = new Criteria(EDocLiteDefinition.class.getName());
78 crit.eq(NAME_CRITERIA, defName);
79 crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE);
80 return (EDocLiteDefinition) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult();
81 }
82
83
84
85
86
87
88 public EDocLiteAssociation getEDocLiteAssociation(final String docTypeName) {
89 final Criteria crit = new Criteria(EDocLiteAssociation.class.getName());
90 crit.eq("edlName", docTypeName);
91 crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE);
92 return (EDocLiteAssociation) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult();
93 }
94
95
96
97
98
99
100 @SuppressWarnings("unchecked")
101 public List<String> getEDocLiteDefinitions() {
102 final Criteria crit = new Criteria(EDocLiteDefinition.class.getName());
103 crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE);
104
105 final List<EDocLiteDefinition> defs = (List<EDocLiteDefinition>) new QueryByCriteria(entityManager, crit).toQuery().getResultList();
106 final ArrayList<String> names = new ArrayList<String>(defs.size());
107 for (EDocLiteDefinition def : defs) {
108 names.add(def.getName());
109 }
110 return names;
111 }
112
113
114
115
116
117
118 @SuppressWarnings("unchecked")
119 public List<EDocLiteAssociation> getEDocLiteAssociations() {
120 final Criteria crit = new Criteria(EDocLiteAssociation.class.getName());
121 crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE);
122 return (List<EDocLiteAssociation>) new QueryByCriteria(entityManager, crit).toQuery().getResultList();
123 }
124
125
126
127
128
129
130 @SuppressWarnings("unchecked")
131 public List<EDocLiteAssociation> search(final EDocLiteAssociation edocLite) {
132 final Criteria crit = new Criteria(EDocLiteAssociation.class.getName());
133 if (edocLite.getActiveInd() != null) {
134 crit.eq(ACTIVE_IND_CRITERIA, edocLite.getActiveInd());
135 }
136 if (edocLite.getDefinition() != null) {
137 crit.like("UPPER(definition)", "%" + edocLite.getDefinition().toUpperCase() + "%");
138 }
139 if (edocLite.getEdlName() != null) {
140 crit.like("UPPER(edlName)", "%" + edocLite.getEdlName().toUpperCase() + "%");
141 }
142 if (edocLite.getStyle() != null) {
143 crit.like("UPPER(style)", "%" + edocLite.getStyle().toUpperCase() + "%");
144 }
145 return (List<EDocLiteAssociation>) new QueryByCriteria(entityManager, crit).toQuery().getResultList();
146 }
147
148
149
150
151
152
153 public EDocLiteAssociation getEDocLiteAssociation(final Long associationId) {
154 final Criteria crit = new Criteria(EDocLiteAssociation.class.getName());
155 crit.eq("edocLiteAssocId", associationId);
156 return (EDocLiteAssociation) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult();
157 }
158
159 public EntityManager getEntityManager() {
160 return this.entityManager;
161 }
162
163 public void setEntityManager(EntityManager entityManager) {
164 this.entityManager = entityManager;
165 }
166 }