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