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.ModuleConfiguration;
20 import org.kuali.rice.krad.dao.BusinessObjectDao;
21 import org.kuali.rice.krad.dao.DocumentDao;
22 import org.kuali.rice.krad.dao.impl.DocumentDaoOjb;
23 import org.kuali.rice.krad.document.Document;
24 import org.kuali.rice.krad.service.DocumentAdHocService;
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.List;
32 import java.util.Map;
33 import java.util.concurrent.ConcurrentHashMap;
34
35 @Transactional
36 public class DocumentDaoProxy implements DocumentDao {
37
38 private DocumentDao documentDaoOjb;
39
40 private static KualiModuleService kualiModuleService;
41 private static Map<String, DocumentDao> documentDaoValues = new ConcurrentHashMap<String, DocumentDao>();
42
43 private DocumentDao getDao(Class<? extends Document> 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 (documentDaoValues.get(dataSourceName) != null) {
54 return documentDaoValues.get(dataSourceName);
55 }
56
57 DocumentDaoOjb documentDaoOjbInstance =
58 new DocumentDaoOjb(
59 this.documentDaoOjb.getBusinessObjectDao(),
60 this.documentDaoOjb.getDocumentAdHocService());
61
62
63 documentDaoOjbInstance.setJcdAlias(dataSourceName);
64
65 documentDaoValues.put(dataSourceName, documentDaoOjbInstance);
66 return documentDaoOjbInstance;
67
68 }
69
70 }
71
72 return documentDaoOjb;
73 }
74
75
76
77
78 @Override
79 public <T extends Document> T save(T document) {
80 return getDao(document.getClass()).save(document);
81 }
82
83
84
85
86 @Override
87 public <T extends Document> T findByDocumentHeaderId(Class<T> clazz, String id) {
88 return getDao(clazz).findByDocumentHeaderId(clazz, id);
89 }
90
91
92
93
94 @Override
95 public <T extends Document> List<T> findByDocumentHeaderIds(Class<T> clazz, List<String> idList) {
96 return getDao(clazz).findByDocumentHeaderIds(clazz, idList);
97 }
98
99
100
101
102 @Override
103 public BusinessObjectDao getBusinessObjectDao() {
104 return documentDaoOjb.getBusinessObjectDao();
105 }
106
107
108
109
110 @Override
111 public DocumentAdHocService getDocumentAdHocService() {
112 return documentDaoOjb.getDocumentAdHocService();
113 }
114
115 public void setDocumentDaoOjb(DocumentDao documentDaoOjb) {
116 this.documentDaoOjb = documentDaoOjb;
117 }
118
119 private synchronized static KualiModuleService getKualiModuleService() {
120 if (kualiModuleService == null) {
121 kualiModuleService = KRADServiceLocatorWeb.getKualiModuleService();
122 }
123 return kualiModuleService;
124 }
125
126 }