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