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.springframework.transaction.annotation.Transactional;
29
30 import java.util.ArrayList;
31 import java.util.Collection;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35
36
37
38
39 @Deprecated
40 @Transactional
41 public class BusinessObjectDaoProxy implements BusinessObjectDao {
42
43 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BusinessObjectDaoProxy.class);
44
45 private BusinessObjectDao businessObjectDaoOjb;
46 private static KualiModuleService kualiModuleService;
47 private static HashMap<String, BusinessObjectDao> boDaoValues = new HashMap<String, BusinessObjectDao>();
48
49 private BusinessObjectDao getDao(Class clazz) {
50 ModuleService moduleService = getKualiModuleService().getResponsibleModuleService(clazz);
51 if (moduleService != null) {
52 ModuleConfiguration moduleConfig = moduleService.getModuleConfiguration();
53 String dataSourceName = "";
54 if (moduleConfig != null) {
55 dataSourceName = moduleConfig.getDataSourceName();
56 }
57
58 if (StringUtils.isNotEmpty(dataSourceName)) {
59 if (boDaoValues.get(dataSourceName) != null) {
60 return boDaoValues.get(dataSourceName);
61 } else {
62
63 BusinessObjectDaoOjb boDaoOjb = new BusinessObjectDaoOjb(
64 KNSServiceLocator.getPersistenceStructureService());
65 boDaoOjb.setJcdAlias(dataSourceName);
66
67 boDaoValues.put(dataSourceName, boDaoOjb);
68 return boDaoOjb;
69 }
70
71 }
72 }
73 return businessObjectDaoOjb;
74 }
75
76
77
78
79 public int countMatching(Class clazz, Map<String, ?> fieldValues) {
80 return getDao(clazz).countMatching(clazz, fieldValues);
81 }
82
83
84
85
86 public int countMatching(Class clazz, Map<String, ?> positiveFieldValues, Map<String, ?> negativeFieldValues) {
87 return getDao(clazz).countMatching(clazz, positiveFieldValues, negativeFieldValues);
88 }
89
90
91
92
93 public void delete(Object bo) {
94 if (bo != null) {
95 getDao(bo.getClass()).delete(bo);
96 }
97 }
98
99
100
101
102 public void delete(List<? extends PersistableBusinessObject> boList) {
103 if (!boList.isEmpty()) {
104 getDao(boList.get(0).getClass()).delete(boList);
105 }
106 }
107
108
109
110
111 public void deleteMatching(Class clazz, Map<String, ?> fieldValues) {
112 getDao(clazz).deleteMatching(clazz, fieldValues);
113 }
114
115
116
117
118 public <T extends BusinessObject> Collection<T> findAll(Class<T> clazz) {
119 return getDao(clazz).findAll(clazz);
120 }
121
122
123
124
125 public <T extends BusinessObject> Collection<T> findAllActive(Class<T> clazz) {
126 return getDao(clazz).findAllActive(clazz);
127 }
128
129
130
131
132 public <T extends BusinessObject> Collection<T> findAllInactive(Class<T> clazz) {
133 return getDao(clazz).findAllInactive(clazz);
134 }
135
136
137
138
139 public <T extends BusinessObject> Collection<T> findAllActiveOrderBy(Class<T> clazz, String sortField, boolean sortAscending) {
140 return getDao(clazz).findAllActiveOrderBy(clazz, sortField, sortAscending);
141 }
142
143
144
145
146 public <T extends BusinessObject> Collection<T> findAllOrderBy(Class<T> clazz, String sortField, boolean sortAscending) {
147 return getDao(clazz).findAllOrderBy(clazz, sortField, sortAscending);
148 }
149
150
151
152
153 public <T extends BusinessObject> T findBySinglePrimaryKey(Class<T> clazz, Object primaryKey) {
154 return getDao(clazz).findBySinglePrimaryKey(clazz, primaryKey);
155 }
156
157
158
159
160 public <T extends BusinessObject> T findByPrimaryKey(Class<T> clazz, Map<String, ?> primaryKeys) {
161 return getDao(clazz).findByPrimaryKey(clazz, primaryKeys);
162 }
163
164
165
166
167 public <T extends BusinessObject> Collection<T> findMatching(Class<T> clazz, Map<String, ?> fieldValues) {
168 return getDao(clazz).findMatching(clazz, fieldValues);
169 }
170
171
172
173
174 public <T extends BusinessObject> Collection<T> findMatchingActive(Class<T> clazz, Map<String, ?> fieldValues) {
175 return getDao(clazz).findMatchingActive(clazz, fieldValues);
176 }
177
178
179
180
181 public <T extends BusinessObject> Collection<T> findMatchingOrderBy(Class<T> clazz, Map<String, ?> fieldValues, String sortField, boolean sortAscending) {
182 return getDao(clazz).findMatchingOrderBy(clazz, fieldValues, sortField, sortAscending);
183 }
184
185
186
187
188 public Object retrieve(Object object) {
189 return getDao(object.getClass()).retrieve(object);
190 }
191
192
193
194
195
196 public PersistableBusinessObject manageReadOnly(PersistableBusinessObject bo) {
197 return getDao(bo.getClass()).manageReadOnly(bo);
198 }
199
200
201
202
203
204 public <T extends BusinessObject> T findByPrimaryKeyUsingKeyObject(Class<T> clazz, Object pkObject) {
205 return getDao(clazz).findByPrimaryKeyUsingKeyObject(clazz, pkObject);
206 }
207
208
209
210
211 public PersistableBusinessObject save(PersistableBusinessObject bo) {
212 PersistableBusinessObject savedBo;
213 savedBo = getDao(bo.getClass()).save(bo);
214 return savedBo;
215 }
216
217
218
219
220 public List<? extends PersistableBusinessObject> save(List businessObjects) {
221 if (!businessObjects.isEmpty()) {
222 return getDao(businessObjects.get(0).getClass()).save(businessObjects);
223 }
224 return new ArrayList<PersistableBusinessObject>();
225 }
226
227 private static KualiModuleService getKualiModuleService() {
228 if (kualiModuleService == null) {
229 kualiModuleService = KRADServiceLocatorWeb.getKualiModuleService();
230 }
231 return kualiModuleService;
232 }
233
234 public void setBusinessObjectDaoOjb(BusinessObjectDao businessObjectDaoOjb) {
235 this.businessObjectDaoOjb = businessObjectDaoOjb;
236 }
237 }