1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.edl.dao.impl; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import javax.persistence.EntityManager; |
22 | |
import javax.persistence.NoResultException; |
23 | |
import javax.persistence.PersistenceContext; |
24 | |
|
25 | |
import org.kuali.rice.core.jpa.criteria.Criteria; |
26 | |
import org.kuali.rice.core.jpa.criteria.QueryByCriteria; |
27 | |
import org.kuali.rice.core.util.OrmUtils; |
28 | |
import org.kuali.rice.kew.edl.bo.EDocLiteAssociation; |
29 | |
import org.kuali.rice.kew.edl.bo.EDocLiteDefinition; |
30 | |
import org.kuali.rice.kew.edl.bo.EDocLiteStyle; |
31 | |
import org.kuali.rice.kew.edl.dao.EDocLiteDAO; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | public class EDocLiteDAOJpaImpl implements EDocLiteDAO { |
39 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(EDocLiteDAOJpaImpl.class); |
40 | |
|
41 | |
private static final String ACTIVE_IND_CRITERIA = "activeInd"; |
42 | |
private static final String NAME_CRITERIA = "name"; |
43 | |
|
44 | |
@PersistenceContext(unitName = "kew-unit") |
45 | |
private EntityManager entityManager; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public void saveEDocLiteStyle(final EDocLiteStyle styleData) { |
53 | 0 | if (styleData.getEdocLiteStyleId() == null) { |
54 | 0 | entityManager.persist(styleData); |
55 | |
} else { |
56 | 0 | OrmUtils.merge(entityManager, styleData); |
57 | |
} |
58 | 0 | } |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public void saveEDocLiteDefinition(final EDocLiteDefinition edocLiteData) { |
66 | 0 | if (edocLiteData.getEDocLiteDefId() == null) { |
67 | 0 | entityManager.persist(edocLiteData); |
68 | |
} else { |
69 | 0 | OrmUtils.merge(entityManager, edocLiteData); |
70 | |
} |
71 | 0 | } |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public void saveEDocLiteAssociation(final EDocLiteAssociation assoc) { |
79 | 0 | if (assoc.getEdocLiteAssocId() == null) { |
80 | 0 | entityManager.persist(assoc); |
81 | |
} else { |
82 | 0 | OrmUtils.merge(entityManager, assoc); |
83 | |
} |
84 | 0 | } |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public EDocLiteStyle getEDocLiteStyle(final String styleName) { |
92 | 0 | final Criteria crit = new Criteria(EDocLiteStyle.class.getName()); |
93 | |
|
94 | 0 | crit.eq(NAME_CRITERIA, styleName); |
95 | 0 | crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE); |
96 | |
|
97 | |
try { |
98 | 0 | return (EDocLiteStyle) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult(); |
99 | 0 | } catch (NoResultException e) { |
100 | 0 | return null; |
101 | |
} |
102 | |
} |
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
public EDocLiteDefinition getEDocLiteDefinition(final String defName) { |
110 | 0 | final Criteria crit = new Criteria(EDocLiteDefinition.class.getName()); |
111 | 0 | crit.eq(NAME_CRITERIA, defName); |
112 | 0 | crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE); |
113 | |
try { |
114 | 0 | return (EDocLiteDefinition) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult(); |
115 | 0 | } catch (NoResultException e) { |
116 | 0 | return null; |
117 | |
} |
118 | |
} |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
public EDocLiteAssociation getEDocLiteAssociation(final String docTypeName) { |
126 | 0 | final Criteria crit = new Criteria(EDocLiteAssociation.class.getName()); |
127 | 0 | crit.eq("edlName", docTypeName); |
128 | 0 | crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE); |
129 | |
try { |
130 | 0 | return (EDocLiteAssociation) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult(); |
131 | 0 | } catch (NoResultException e) { |
132 | 0 | return null; |
133 | |
} |
134 | |
} |
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
public List<String> getEDocLiteStyleNames() { |
142 | 0 | final List<EDocLiteStyle> styles = getEDocLiteStyles(); |
143 | 0 | final List<String> styleNames = new ArrayList<String>(styles.size()); |
144 | 0 | for (EDocLiteStyle style : styles) { |
145 | 0 | styleNames.add(style.getName()); |
146 | |
} |
147 | 0 | return styleNames; |
148 | |
} |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
@SuppressWarnings("unchecked") |
156 | |
public List<EDocLiteStyle> getEDocLiteStyles() { |
157 | 0 | final Criteria crit = new Criteria(EDocLiteStyle.class.getName()); |
158 | 0 | crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE); |
159 | |
|
160 | 0 | return (List<EDocLiteStyle>) new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
161 | |
|
162 | |
} |
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
@SuppressWarnings("unchecked") |
170 | |
public List<String> getEDocLiteDefinitions() { |
171 | 0 | final Criteria crit = new Criteria(EDocLiteDefinition.class.getName()); |
172 | 0 | crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE); |
173 | |
|
174 | 0 | final List<EDocLiteDefinition> defs = (List<EDocLiteDefinition>) new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
175 | 0 | final ArrayList<String> names = new ArrayList<String>(defs.size()); |
176 | 0 | for (EDocLiteDefinition def : defs) { |
177 | 0 | names.add(def.getName()); |
178 | |
} |
179 | 0 | return names; |
180 | |
} |
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
@SuppressWarnings("unchecked") |
188 | |
public List<EDocLiteAssociation> getEDocLiteAssociations() { |
189 | 0 | final Criteria crit = new Criteria(EDocLiteAssociation.class.getName()); |
190 | 0 | crit.eq(ACTIVE_IND_CRITERIA, Boolean.TRUE); |
191 | 0 | return (List<EDocLiteAssociation>) new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
192 | |
} |
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
@SuppressWarnings("unchecked") |
200 | |
public List<EDocLiteAssociation> search(final EDocLiteAssociation edocLite) { |
201 | 0 | final Criteria crit = new Criteria(EDocLiteAssociation.class.getName()); |
202 | 0 | if (edocLite.getActiveInd() != null) { |
203 | 0 | crit.eq(ACTIVE_IND_CRITERIA, edocLite.getActiveInd()); |
204 | |
} |
205 | 0 | if (edocLite.getDefinition() != null) { |
206 | 0 | crit.like("UPPER(definition)", "%" + edocLite.getDefinition().toUpperCase() + "%"); |
207 | |
} |
208 | 0 | if (edocLite.getEdlName() != null) { |
209 | 0 | crit.like("UPPER(edlName)", "%" + edocLite.getEdlName().toUpperCase() + "%"); |
210 | |
} |
211 | 0 | if (edocLite.getStyle() != null) { |
212 | 0 | crit.like("UPPER(style)", "%" + edocLite.getStyle().toUpperCase() + "%"); |
213 | |
} |
214 | 0 | return (List<EDocLiteAssociation>) new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
215 | |
} |
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
public EDocLiteAssociation getEDocLiteAssociation(final Long associationId) { |
223 | 0 | final Criteria crit = new Criteria(EDocLiteAssociation.class.getName()); |
224 | 0 | crit.eq("edocLiteAssocId", associationId); |
225 | |
try { |
226 | 0 | return (EDocLiteAssociation) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult(); |
227 | 0 | } catch (NoResultException e) { |
228 | 0 | return null; |
229 | |
} |
230 | |
} |
231 | |
|
232 | |
public EntityManager getEntityManager() { |
233 | 0 | return this.entityManager; |
234 | |
} |
235 | |
|
236 | |
public void setEntityManager(EntityManager entityManager) { |
237 | 0 | this.entityManager = entityManager; |
238 | 0 | } |
239 | |
} |