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.apache.ojb.broker.core.proxy.ProxyHelper;
20 import org.kuali.rice.krad.bo.ModuleConfiguration;
21 import org.kuali.rice.krad.dao.PersistenceDao;
22 import org.kuali.rice.krad.dao.impl.PersistenceDaoOjb;
23 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
24 import org.kuali.rice.krad.service.KualiModuleService;
25 import org.kuali.rice.krad.service.ModuleService;
26 import org.kuali.rice.krad.util.LegacyUtils;
27 import org.kuali.rice.krad.util.ObjectUtils;
28 import org.springframework.transaction.annotation.Transactional;
29
30 import java.util.HashMap;
31
32 @Deprecated
33 @Transactional
34 public class PersistenceDaoProxy implements PersistenceDao {
35 private PersistenceDao persistenceDaoOjb;
36 private static KualiModuleService kualiModuleService;
37 private static HashMap<String, PersistenceDao> persistenceDaoValues = new HashMap<String, PersistenceDao>();
38
39 public void setPersistenceDaoOjb(PersistenceDao persistenceDaoOjb) {
40 this.persistenceDaoOjb = persistenceDaoOjb;
41 }
42
43 private PersistenceDao getDao(Class clazz) {
44 ModuleService moduleService = getKualiModuleService().getResponsibleModuleService(clazz);
45 if (moduleService != null) {
46 ModuleConfiguration moduleConfig = moduleService.getModuleConfiguration();
47 String dataSourceName = "";
48 if (moduleConfig != null) {
49 dataSourceName = moduleConfig.getDataSourceName();
50 }
51
52 if (StringUtils.isNotEmpty(dataSourceName)) {
53 if (persistenceDaoValues.get(dataSourceName) != null) {
54 return persistenceDaoValues.get(dataSourceName);
55 } else {
56
57 PersistenceDaoOjb persistDaoOjb = new PersistenceDaoOjb();
58 persistDaoOjb.setJcdAlias(dataSourceName);
59
60 persistenceDaoValues.put(dataSourceName, persistDaoOjb);
61 return persistDaoOjb;
62 }
63
64 }
65 }
66 return persistenceDaoOjb;
67 }
68
69
70
71
72 public void clearCache() {
73 persistenceDaoOjb.clearCache();
74 }
75
76
77
78
79 public Object resolveProxy(Object o) {
80 return getDao(ObjectUtils.materializeClassForProxiedObject(o)).resolveProxy(o);
81 }
82
83
84
85
86 public void retrieveAllReferences(Object o) {
87 getDao(ObjectUtils.materializeClassForProxiedObject(o)).retrieveAllReferences(o);
88 }
89
90
91
92
93 public void retrieveReference(Object o, String referenceName) {
94 getDao(ObjectUtils.materializeClassForProxiedObject(o)).retrieveReference(o, referenceName);
95 }
96
97
98
99
100
101
102 public boolean isProxied(Object object) {
103
104 if (ProxyHelper.isProxy(object)) return true;
105 return false;
106 }
107
108 private static KualiModuleService getKualiModuleService() {
109 if (kualiModuleService == null) {
110 kualiModuleService = KRADServiceLocatorWeb.getKualiModuleService();
111 }
112 return kualiModuleService;
113 }
114 }