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.core.api.CoreApiServiceLocator;
20  import org.kuali.rice.kns.service.KNSServiceLocator;
21  import org.kuali.rice.krad.bo.ModuleConfiguration;
22  import org.kuali.rice.krad.dao.LookupDao;
23  import org.kuali.rice.krad.dao.impl.LookupDaoOjb;
24  import org.kuali.rice.krad.service.KRADServiceLocator;
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.Collection;
32  import java.util.Collections;
33  import java.util.HashMap;
34  import java.util.Map;
35  
36  @Transactional
37  public class LookupDaoProxy implements LookupDao {
38      
39  	private LookupDao lookupDaoOjb;
40      private static KualiModuleService kualiModuleService;
41      private static Map<String, LookupDao> lookupDaoValues = Collections.synchronizedMap(new HashMap<String, LookupDao>());
42  	
43  	public void setLookupDaoOjb(LookupDao lookupDaoOjb) {
44  		this.lookupDaoOjb = lookupDaoOjb;
45  	}
46  	
47      private LookupDao getDao(Class clazz) {
48          ModuleService moduleService = getKualiModuleService().getResponsibleModuleService(clazz);
49          if (moduleService != null) {
50              ModuleConfiguration moduleConfig = moduleService.getModuleConfiguration();
51              String dataSourceName = "";
52              if (moduleConfig != null) {
53                  dataSourceName = moduleConfig.getDataSourceName();
54              }
55  
56              if (StringUtils.isNotEmpty(dataSourceName)) {
57                  if (lookupDaoValues.get(dataSourceName) != null) {
58                      return lookupDaoValues.get(dataSourceName);
59                  } else {
60                      LookupDaoOjb classSpecificLookupDaoOjb = new LookupDaoOjb();
61                      classSpecificLookupDaoOjb.setJcdAlias(dataSourceName);
62                      classSpecificLookupDaoOjb.setPersistenceStructureService(
63                              KNSServiceLocator.getPersistenceStructureService());
64                      classSpecificLookupDaoOjb.setDateTimeService(CoreApiServiceLocator.getDateTimeService());
65                      classSpecificLookupDaoOjb.setDataDictionaryService(
66                              KRADServiceLocatorWeb.getDataDictionaryService());
67                      lookupDaoValues.put(dataSourceName, classSpecificLookupDaoOjb);
68                      return classSpecificLookupDaoOjb;
69                  }
70  
71              }
72          }
73          return lookupDaoOjb;
74      }
75      
76  	
77  
78  
79  	public boolean createCriteria(Object example, String searchValue, String propertyName, Object criteria) {
80  		return getDao(example.getClass()).createCriteria(example, searchValue, propertyName, criteria);
81  	}
82  
83  	
84  
85  
86  	public boolean createCriteria(Object example, String searchValue, String propertyName, boolean caseInsensitive, boolean treatWildcardsAndOperatorsAsLiteral, Object criteria) {
87  		return getDao(example.getClass()).createCriteria(example, searchValue, propertyName, caseInsensitive,
88                  treatWildcardsAndOperatorsAsLiteral, criteria);
89  	}
90  
91      
92  
93  
94  
95  
96  
97  
98  
99  
100     public Collection findCollectionBySearchHelper(Class businessObjectClass, Map formProps, boolean unbounded,
101             boolean usePrimaryKeyValuesOnly) {
102         return getDao(businessObjectClass).findCollectionBySearchHelper(businessObjectClass, formProps, unbounded,
103                 usePrimaryKeyValuesOnly);
104     }
105 
106     
107 
108 
109 
110     public Collection findCollectionBySearchHelper(Class businessObjectClass, Map formProps, boolean unbounded,
111             boolean usePrimaryKeyValuesOnly, Integer searchResultsLimit) {
112         return getDao(businessObjectClass).findCollectionBySearchHelper(businessObjectClass, formProps, unbounded,
113                 usePrimaryKeyValuesOnly, searchResultsLimit);
114     }
115 
116 	
117 
118 
119 	public Long findCountByMap(Object example, Map formProps) {
120 		return getDao(example.getClass()).findCountByMap(example, formProps);
121 	}
122 
123     @Override
124     public <T extends Object> T findObjectByMap(Class<T> type, Map<String, String> formProps) {
125         return getDao(type).findObjectByMap(type, formProps);
126     }
127 
128 	private static KualiModuleService getKualiModuleService() {
129         if (kualiModuleService == null) {
130             kualiModuleService = KRADServiceLocatorWeb.getKualiModuleService();
131         }
132         return kualiModuleService;
133     }
134 }