1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.kuali.rice.kns.dao.proxy; |
18 |
|
|
19 |
|
import org.apache.commons.lang.StringUtils; |
20 |
|
import org.kuali.rice.core.api.config.ConfigurationException; |
21 |
|
import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; |
22 |
|
import org.kuali.rice.kns.bo.BusinessObject; |
23 |
|
import org.kuali.rice.kns.bo.ModuleConfiguration; |
24 |
|
import org.kuali.rice.kns.bo.PersistableBusinessObject; |
25 |
|
import org.kuali.rice.kns.dao.BusinessObjectDao; |
26 |
|
import org.kuali.rice.kns.dao.impl.BusinessObjectDaoJpa; |
27 |
|
import org.kuali.rice.kns.dao.impl.BusinessObjectDaoOjb; |
28 |
|
import org.kuali.rice.kns.service.KNSServiceLocator; |
29 |
|
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
30 |
|
import org.kuali.rice.kns.service.KualiModuleService; |
31 |
|
import org.kuali.rice.kns.service.ModuleService; |
32 |
|
import org.springframework.transaction.annotation.Transactional; |
33 |
|
|
34 |
|
import javax.persistence.EntityManager; |
35 |
|
import java.util.ArrayList; |
36 |
|
import java.util.Collection; |
37 |
|
import java.util.HashMap; |
38 |
|
import java.util.List; |
39 |
|
import java.util.Map; |
40 |
|
|
41 |
|
@Transactional |
|
|
| 0% |
Uncovered Elements: 99 (99) |
Complexity: 37 |
Complexity Density: 0.7 |
|
42 |
|
public class BusinessObjectDaoProxy implements BusinessObjectDao { |
43 |
|
|
44 |
|
private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BusinessObjectDaoProxy.class); |
45 |
|
|
46 |
|
private BusinessObjectDao businessObjectDaoJpa; |
47 |
|
private BusinessObjectDao businessObjectDaoOjb; |
48 |
|
private static KualiModuleService kualiModuleService; |
49 |
|
private static HashMap<String, BusinessObjectDao> boDaoValues = new HashMap<String, BusinessObjectDao>(); |
50 |
|
|
|
|
| 0% |
Uncovered Elements: 36 (36) |
Complexity: 10 |
Complexity Density: 0.45 |
|
51 |
0
|
private BusinessObjectDao getDao(Class clazz) {... |
52 |
0
|
ModuleService moduleService = getKualiModuleService().getResponsibleModuleService(clazz); |
53 |
0
|
if (moduleService != null) { |
54 |
0
|
ModuleConfiguration moduleConfig = moduleService.getModuleConfiguration(); |
55 |
0
|
String dataSourceName = ""; |
56 |
0
|
EntityManager entityManager = null; |
57 |
0
|
if (moduleConfig != null) { |
58 |
0
|
dataSourceName = moduleConfig.getDataSourceName(); |
59 |
0
|
entityManager = moduleConfig.getEntityManager(); |
60 |
|
} |
61 |
|
|
62 |
0
|
if (StringUtils.isNotEmpty(dataSourceName)) { |
63 |
0
|
if (boDaoValues.get(dataSourceName) != null) { |
64 |
0
|
return boDaoValues.get(dataSourceName); |
65 |
|
} else { |
66 |
0
|
if (OrmUtils.isJpaAnnotated(clazz) && OrmUtils.isJpaEnabled()) { |
67 |
|
|
68 |
0
|
if (entityManager != null) { |
69 |
0
|
BusinessObjectDaoJpa boDaoJpa = |
70 |
|
new BusinessObjectDaoJpa(entityManager, KNSServiceLocator.getPersistenceStructureService()); |
71 |
|
|
72 |
0
|
boDaoValues.put(dataSourceName, boDaoJpa); |
73 |
0
|
return boDaoJpa; |
74 |
|
} else { |
75 |
0
|
throw new ConfigurationException("EntityManager is null. EntityManager must be set in the Module Configuration bean in the appropriate spring beans xml. (see nested exception for details)."); |
76 |
|
} |
77 |
|
} else { |
78 |
|
|
79 |
0
|
BusinessObjectDaoOjb boDaoOjb = new BusinessObjectDaoOjb(KNSServiceLocator.getPersistenceStructureService()); |
80 |
0
|
boDaoOjb.setJcdAlias(dataSourceName); |
81 |
|
|
82 |
0
|
boDaoValues.put(dataSourceName, boDaoOjb); |
83 |
0
|
return boDaoOjb; |
84 |
|
} |
85 |
|
} |
86 |
|
|
87 |
|
} |
88 |
|
} |
89 |
|
|
90 |
0
|
return (OrmUtils.isJpaAnnotated(clazz) && OrmUtils.isJpaEnabled()) ? businessObjectDaoJpa : businessObjectDaoOjb; |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
@see |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
0
|
public int countMatching(Class clazz, Map<String, ?> fieldValues) {... |
97 |
0
|
return getDao(clazz).countMatching(clazz, fieldValues); |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
|
@see |
102 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
0
|
public int countMatching(Class clazz, Map<String, ?> positiveFieldValues, Map<String, ?> negativeFieldValues) {... |
104 |
0
|
return getDao(clazz).countMatching(clazz, positiveFieldValues, negativeFieldValues); |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
|
@see |
109 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
110 |
0
|
public void delete(PersistableBusinessObject bo) {... |
111 |
0
|
if (bo != null) { |
112 |
0
|
getDao(bo.getClass()).delete(bo); |
113 |
|
} |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
@see |
118 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
119 |
0
|
public void delete(List<? extends PersistableBusinessObject> boList) {... |
120 |
0
|
if (!boList.isEmpty()) { |
121 |
0
|
getDao(boList.get(0).getClass()).delete(boList); |
122 |
|
} |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
|
@see |
127 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
128 |
0
|
public void deleteMatching(Class clazz, Map<String, ?> fieldValues) {... |
129 |
0
|
getDao(clazz).deleteMatching(clazz, fieldValues); |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
@see |
134 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
135 |
0
|
public <T extends BusinessObject> Collection<T> findAll(Class<T> clazz) {... |
136 |
0
|
return getDao(clazz).findAll(clazz); |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
@see |
141 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
142 |
0
|
public <T extends BusinessObject> Collection<T> findAllActive(Class<T> clazz) {... |
143 |
0
|
return getDao(clazz).findAllActive(clazz); |
144 |
|
} |
145 |
|
|
146 |
|
|
147 |
|
@see |
148 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
149 |
0
|
public <T extends BusinessObject> Collection<T> findAllInactive(Class<T> clazz) {... |
150 |
0
|
return getDao(clazz).findAllInactive(clazz); |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
|
@see |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
0
|
public <T extends BusinessObject> Collection<T> findAllActiveOrderBy(Class<T> clazz, String sortField, boolean sortAscending) {... |
157 |
0
|
return getDao(clazz).findAllActiveOrderBy(clazz, sortField, sortAscending); |
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
|
@see |
162 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
163 |
0
|
public <T extends BusinessObject> Collection<T> findAllOrderBy(Class<T> clazz, String sortField, boolean sortAscending) {... |
164 |
0
|
return getDao(clazz).findAllOrderBy(clazz, sortField, sortAscending); |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
@see |
169 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
170 |
0
|
public <T extends BusinessObject> T findBySinglePrimaryKey(Class<T> clazz, Object primaryKey) {... |
171 |
0
|
return getDao(clazz).findBySinglePrimaryKey(clazz, primaryKey); |
172 |
|
} |
173 |
|
|
174 |
|
|
175 |
|
@see |
176 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
177 |
0
|
public <T extends BusinessObject> T findByPrimaryKey(Class<T> clazz, Map<String, ?> primaryKeys) {... |
178 |
0
|
return getDao(clazz).findByPrimaryKey(clazz, primaryKeys); |
179 |
|
} |
180 |
|
|
181 |
|
|
182 |
|
@see |
183 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
184 |
0
|
public <T extends BusinessObject> Collection<T> findMatching(Class<T> clazz, Map<String, ?> fieldValues) {... |
185 |
0
|
return getDao(clazz).findMatching(clazz, fieldValues); |
186 |
|
} |
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
@see |
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
@see |
204 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
205 |
0
|
public <T extends BusinessObject> Collection<T> findMatchingActive(Class<T> clazz, Map<String, ?> fieldValues) {... |
206 |
0
|
return getDao(clazz).findMatchingActive(clazz, fieldValues); |
207 |
|
} |
208 |
|
|
209 |
|
|
210 |
|
@see |
211 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
212 |
0
|
public <T extends BusinessObject> Collection<T> findMatchingOrderBy(Class<T> clazz, Map<String, ?> fieldValues, String sortField, boolean sortAscending) {... |
213 |
0
|
return getDao(clazz).findMatchingOrderBy(clazz, fieldValues, sortField, sortAscending); |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
|
@see |
218 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
219 |
0
|
public PersistableBusinessObject retrieve(PersistableBusinessObject object) {... |
220 |
0
|
return getDao(object.getClass()).retrieve(object); |
221 |
|
} |
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
@see |
226 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
227 |
0
|
public PersistableBusinessObject manageReadOnly(PersistableBusinessObject bo) {... |
228 |
0
|
return getDao(bo.getClass()).manageReadOnly(bo); |
229 |
|
} |
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
@see |
234 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
235 |
0
|
public <T extends BusinessObject> T findByPrimaryKeyUsingKeyObject(Class<T> clazz, Object pkObject) {... |
236 |
0
|
return getDao(clazz).findByPrimaryKeyUsingKeyObject(clazz, pkObject); |
237 |
|
} |
238 |
|
|
239 |
|
|
240 |
|
@see |
241 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
242 |
0
|
public PersistableBusinessObject save(PersistableBusinessObject bo) {... |
243 |
0
|
PersistableBusinessObject savedBo; |
244 |
0
|
savedBo = getDao(bo.getClass()).save(bo); |
245 |
0
|
return savedBo; |
246 |
|
} |
247 |
|
|
248 |
|
|
249 |
|
@see |
250 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
251 |
0
|
public List<? extends PersistableBusinessObject> save(List businessObjects) {... |
252 |
0
|
if (!businessObjects.isEmpty()) { |
253 |
0
|
return getDao(businessObjects.get(0).getClass()).save(businessObjects); |
254 |
|
} |
255 |
0
|
return new ArrayList<PersistableBusinessObject>(); |
256 |
|
} |
257 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
258 |
0
|
private static KualiModuleService getKualiModuleService() {... |
259 |
0
|
if (kualiModuleService == null) { |
260 |
0
|
kualiModuleService = KNSServiceLocatorWeb.getKualiModuleService(); |
261 |
|
} |
262 |
0
|
return kualiModuleService; |
263 |
|
} |
264 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
265 |
0
|
public void setBusinessObjectDaoJpa(BusinessObjectDao businessObjectDaoJpa) {... |
266 |
0
|
this.businessObjectDaoJpa = businessObjectDaoJpa; |
267 |
|
} |
268 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
269 |
0
|
public void setBusinessObjectDaoOjb(BusinessObjectDao businessObjectDaoOjb) {... |
270 |
0
|
this.businessObjectDaoOjb = businessObjectDaoOjb; |
271 |
|
} |
272 |
|
} |