1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.criteria;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.criteria.GenericQueryResults;
20 import org.kuali.rice.core.api.criteria.LookupCustomizer;
21 import org.kuali.rice.core.api.criteria.QueryByCriteria;
22 import org.kuali.rice.krad.bo.ModuleConfiguration;
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
28 import java.util.Collections;
29 import java.util.HashMap;
30 import java.util.Map;
31
32 public class CriteriaLookupDaoProxy implements CriteriaLookupDao {
33 CriteriaLookupDao criteriaLookupDaoOjb;
34
35 private static KualiModuleService kualiModuleService;
36 private static Map<String, CriteriaLookupDao> lookupDaoValues = Collections.synchronizedMap(new HashMap<String, CriteriaLookupDao>());
37
38 public void setCriteriaLookupDaoOjb(CriteriaLookupDao lookupDaoOjb) {
39 this.criteriaLookupDaoOjb = lookupDaoOjb;
40 }
41
42 private CriteriaLookupDao getDao(Class clazz) {
43 ModuleService moduleService = getKualiModuleService().getResponsibleModuleService(clazz);
44 if (moduleService != null) {
45 ModuleConfiguration moduleConfig = moduleService.getModuleConfiguration();
46 String dataSourceName = "";
47 if (moduleConfig != null) {
48 dataSourceName = moduleConfig.getDataSourceName();
49 }
50
51 if (StringUtils.isNotEmpty(dataSourceName)) {
52 if (lookupDaoValues.get(dataSourceName) != null) {
53 return lookupDaoValues.get(dataSourceName);
54 } else {
55 CriteriaLookupDaoOjb classSpecificLookupDaoOjb = new CriteriaLookupDaoOjb();
56 classSpecificLookupDaoOjb.setJcdAlias(dataSourceName);
57 lookupDaoValues.put(dataSourceName, classSpecificLookupDaoOjb);
58 return classSpecificLookupDaoOjb;
59 }
60
61 }
62 }
63 return criteriaLookupDaoOjb;
64 }
65
66 @Override
67 public <T> GenericQueryResults<T> lookup(Class<T> queryClass, QueryByCriteria criteria) {
68 return getDao(queryClass).lookup(queryClass, criteria);
69 }
70
71 @Override
72 public <T> GenericQueryResults<T> lookup(Class<T> queryClass, QueryByCriteria criteria,
73 LookupCustomizer<T> customizer) {
74 return getDao(queryClass).lookup(queryClass, criteria, customizer);
75 }
76
77 private static KualiModuleService getKualiModuleService() {
78 if (kualiModuleService == null) {
79 kualiModuleService = KRADServiceLocatorWeb.getKualiModuleService();
80 }
81 return kualiModuleService;
82 }
83 }