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.kns.service.KNSServiceLocator;
20 import org.kuali.rice.krad.bo.BusinessObject;
21 import org.kuali.rice.krad.bo.ModuleConfiguration;
22 import org.kuali.rice.krad.bo.PersistableBusinessObject;
23 import org.kuali.rice.krad.dao.BusinessObjectDao;
24 import org.kuali.rice.krad.dao.impl.BusinessObjectDaoOjb;
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
64 BusinessObjectDaoOjb boDaoOjb = new BusinessObjectDaoOjb(
65 KNSServiceLocator.getPersistenceStructureService());
66 boDaoOjb.setJcdAlias(dataSourceName);
67
68 boDaoValues.put(dataSourceName, boDaoOjb);
69 return boDaoOjb;
70 }
71
72 }
73 }
74 return businessObjectDaoOjb;
75 }
76
77
78
79
80 public int countMatching(Class clazz, Map<String, ?> fieldValues) {
81 return getDao(clazz).countMatching(clazz, fieldValues);
82 }
83
84
85
86
87 public int countMatching(Class clazz, Map<String, ?> positiveFieldValues, Map<String, ?> negativeFieldValues) {
88 return getDao(clazz).countMatching(clazz, positiveFieldValues, negativeFieldValues);
89 }
90
91
92
93
94 public void delete(PersistableBusinessObject bo) {
95 if (bo != null) {
96 getDao(bo.getClass()).delete(bo);
97 }
98 }
99
100
101
102
103 public void delete(List<? extends PersistableBusinessObject> boList) {
104 if (!boList.isEmpty()) {
105 getDao(boList.get(0).getClass()).delete(boList);
106 }
107 }
108
109
110
111
112 public void deleteMatching(Class clazz, Map<String, ?> fieldValues) {
113 getDao(clazz).deleteMatching(clazz, fieldValues);
114 }
115
116
117
118
119 public <T extends BusinessObject> Collection<T> findAll(Class<T> clazz) {
120 return getDao(clazz).findAll(clazz);
121 }
122
123
124
125
126 public <T extends BusinessObject> Collection<T> findAllActive(Class<T> clazz) {
127 return getDao(clazz).findAllActive(clazz);
128 }
129
130
131
132
133 public <T extends BusinessObject> Collection<T> findAllInactive(Class<T> clazz) {
134 return getDao(clazz).findAllInactive(clazz);
135 }
136
137
138
139
140 public <T extends BusinessObject> Collection<T> findAllActiveOrderBy(Class<T> clazz, String sortField, boolean sortAscending) {
141 return getDao(clazz).findAllActiveOrderBy(clazz, sortField, sortAscending);
142 }
143
144
145
146
147 public <T extends BusinessObject> Collection<T> findAllOrderBy(Class<T> clazz, String sortField, boolean sortAscending) {
148 return getDao(clazz).findAllOrderBy(clazz, sortField, sortAscending);
149 }
150
151
152
153
154 public <T extends BusinessObject> T findBySinglePrimaryKey(Class<T> clazz, Object primaryKey) {
155 return getDao(clazz).findBySinglePrimaryKey(clazz, primaryKey);
156 }
157
158
159
160
161 public <T extends BusinessObject> T findByPrimaryKey(Class<T> clazz, Map<String, ?> primaryKeys) {
162 return getDao(clazz).findByPrimaryKey(clazz, primaryKeys);
163 }
164
165
166
167
168 public <T extends BusinessObject> Collection<T> findMatching(Class<T> clazz, Map<String, ?> fieldValues) {
169 return getDao(clazz).findMatching(clazz, fieldValues);
170 }
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189 public <T extends BusinessObject> Collection<T> findMatchingActive(Class<T> clazz, Map<String, ?> fieldValues) {
190 return getDao(clazz).findMatchingActive(clazz, fieldValues);
191 }
192
193
194
195
196 public <T extends BusinessObject> Collection<T> findMatchingOrderBy(Class<T> clazz, Map<String, ?> fieldValues, String sortField, boolean sortAscending) {
197 return getDao(clazz).findMatchingOrderBy(clazz, fieldValues, sortField, sortAscending);
198 }
199
200
201
202
203 public PersistableBusinessObject retrieve(PersistableBusinessObject object) {
204 return getDao(object.getClass()).retrieve(object);
205 }
206
207
208
209
210
211 public PersistableBusinessObject manageReadOnly(PersistableBusinessObject bo) {
212 return getDao(bo.getClass()).manageReadOnly(bo);
213 }
214
215
216
217
218
219 public <T extends BusinessObject> T findByPrimaryKeyUsingKeyObject(Class<T> clazz, Object pkObject) {
220 return getDao(clazz).findByPrimaryKeyUsingKeyObject(clazz, pkObject);
221 }
222
223
224
225
226 public PersistableBusinessObject save(PersistableBusinessObject bo) {
227 PersistableBusinessObject savedBo;
228 savedBo = getDao(bo.getClass()).save(bo);
229 return savedBo;
230 }
231
232
233
234
235 public List<? extends PersistableBusinessObject> save(List businessObjects) {
236 if (!businessObjects.isEmpty()) {
237 return getDao(businessObjects.get(0).getClass()).save(businessObjects);
238 }
239 return new ArrayList<PersistableBusinessObject>();
240 }
241
242 private static KualiModuleService getKualiModuleService() {
243 if (kualiModuleService == null) {
244 kualiModuleService = KRADServiceLocatorWeb.getKualiModuleService();
245 }
246 return kualiModuleService;
247 }
248
249 public void setBusinessObjectDaoOjb(BusinessObjectDao businessObjectDaoOjb) {
250 this.businessObjectDaoOjb = businessObjectDaoOjb;
251 }
252 }