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.core.api.config.ConfigurationException; |
21 | |
import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; |
22 | |
import org.kuali.rice.krad.bo.ModuleConfiguration; |
23 | |
import org.kuali.rice.krad.dao.LookupDao; |
24 | |
import org.kuali.rice.krad.dao.impl.LookupDaoJpa; |
25 | |
import org.kuali.rice.krad.dao.impl.LookupDaoOjb; |
26 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
27 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
28 | |
import org.kuali.rice.krad.service.KualiModuleService; |
29 | |
import org.kuali.rice.krad.service.ModuleService; |
30 | |
import org.springframework.transaction.annotation.Transactional; |
31 | |
|
32 | |
import javax.persistence.EntityManager; |
33 | |
import java.util.Collection; |
34 | |
import java.util.Collections; |
35 | |
import java.util.HashMap; |
36 | |
import java.util.Map; |
37 | |
|
38 | |
@Transactional |
39 | 0 | public class LookupDaoProxy implements LookupDao { |
40 | |
|
41 | |
private LookupDao lookupDaoJpa; |
42 | |
private LookupDao lookupDaoOjb; |
43 | |
private static KualiModuleService kualiModuleService; |
44 | 0 | private static Map<String, LookupDao> lookupDaoValues = Collections.synchronizedMap(new HashMap<String, LookupDao>()); |
45 | |
|
46 | |
public void setLookupDaoJpa(LookupDao lookupDaoJpa) { |
47 | 0 | this.lookupDaoJpa = lookupDaoJpa; |
48 | 0 | } |
49 | |
|
50 | |
public void setLookupDaoOjb(LookupDao lookupDaoOjb) { |
51 | 0 | this.lookupDaoOjb = lookupDaoOjb; |
52 | 0 | } |
53 | |
|
54 | |
private LookupDao getDao(Class clazz) { |
55 | 0 | ModuleService moduleService = getKualiModuleService().getResponsibleModuleService(clazz); |
56 | 0 | if (moduleService != null) { |
57 | 0 | ModuleConfiguration moduleConfig = moduleService.getModuleConfiguration(); |
58 | 0 | String dataSourceName = ""; |
59 | 0 | EntityManager entityManager = null; |
60 | 0 | if (moduleConfig != null) { |
61 | 0 | dataSourceName = moduleConfig.getDataSourceName(); |
62 | 0 | entityManager = moduleConfig.getEntityManager(); |
63 | |
} |
64 | |
|
65 | 0 | if (StringUtils.isNotEmpty(dataSourceName)) { |
66 | 0 | if (lookupDaoValues.get(dataSourceName) != null) { |
67 | 0 | return lookupDaoValues.get(dataSourceName); |
68 | |
} else { |
69 | 0 | if (OrmUtils.isJpaAnnotated(clazz) && OrmUtils.isJpaEnabled()) { |
70 | |
|
71 | 0 | LookupDaoJpa classSpecificLookupDaoJpa = new LookupDaoJpa(); |
72 | 0 | if (entityManager != null) { |
73 | 0 | classSpecificLookupDaoJpa.setEntityManager(entityManager); |
74 | 0 | classSpecificLookupDaoJpa.setPersistenceStructureService( |
75 | |
KRADServiceLocator.getPersistenceStructureService()); |
76 | 0 | classSpecificLookupDaoJpa.setDateTimeService(CoreApiServiceLocator.getDateTimeService()); |
77 | 0 | lookupDaoValues.put(dataSourceName, classSpecificLookupDaoJpa); |
78 | 0 | return classSpecificLookupDaoJpa; |
79 | |
} else { |
80 | 0 | throw new ConfigurationException("EntityManager is null. EntityManager must be set in the Module Configuration bean in the appropriate spring beans xml. (see nested exception for details)."); |
81 | |
} |
82 | |
} else { |
83 | 0 | LookupDaoOjb classSpecificLookupDaoOjb = new LookupDaoOjb(); |
84 | 0 | classSpecificLookupDaoOjb.setJcdAlias(dataSourceName); |
85 | 0 | classSpecificLookupDaoOjb.setPersistenceStructureService( |
86 | |
KRADServiceLocator.getPersistenceStructureService()); |
87 | 0 | classSpecificLookupDaoOjb.setDateTimeService(CoreApiServiceLocator.getDateTimeService()); |
88 | 0 | classSpecificLookupDaoOjb.setDataDictionaryService( |
89 | |
KRADServiceLocatorWeb.getDataDictionaryService()); |
90 | 0 | lookupDaoValues.put(dataSourceName, classSpecificLookupDaoOjb); |
91 | 0 | return classSpecificLookupDaoOjb; |
92 | |
} |
93 | |
} |
94 | |
|
95 | |
} |
96 | |
} |
97 | |
|
98 | 0 | return (OrmUtils.isJpaAnnotated(clazz) && OrmUtils.isJpaEnabled()) ? lookupDaoJpa : lookupDaoOjb; |
99 | |
} |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
public boolean createCriteria(Object example, String searchValue, String propertyName, Object criteria) { |
105 | 0 | return getDao(example.getClass()).createCriteria(example, searchValue, propertyName, criteria); |
106 | |
} |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
public boolean createCriteria(Object example, String searchValue, String propertyName, boolean caseInsensitive, boolean treatWildcardsAndOperatorsAsLiteral, Object criteria) { |
112 | 0 | return getDao(example.getClass()).createCriteria(example, searchValue, propertyName, caseInsensitive, |
113 | |
treatWildcardsAndOperatorsAsLiteral, criteria); |
114 | |
} |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
public Collection findCollectionBySearchHelper(Class example, Map formProps, boolean unbounded, boolean usePrimaryKeyValuesOnly) { |
120 | 0 | return getDao(example).findCollectionBySearchHelper(example, formProps, unbounded, usePrimaryKeyValuesOnly); |
121 | |
} |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
public Long findCountByMap(Object example, Map formProps) { |
127 | 0 | return getDao(example.getClass()).findCountByMap(example, formProps); |
128 | |
} |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
public Object findObjectByMap(Object example, Map formProps) { |
134 | 0 | return getDao(example.getClass()).findObjectByMap(example, formProps); |
135 | |
} |
136 | |
|
137 | |
private static KualiModuleService getKualiModuleService() { |
138 | 0 | if (kualiModuleService == null) { |
139 | 0 | kualiModuleService = KRADServiceLocatorWeb.getKualiModuleService(); |
140 | |
} |
141 | 0 | return kualiModuleService; |
142 | |
} |
143 | |
} |