| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.kns.dao.proxy; |
| 18 | |
|
| 19 | |
import org.apache.commons.lang.StringUtils; |
| 20 | |
import org.kuali.rice.core.api.config.ConfigurationException; |
| 21 | |
import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; |
| 22 | |
import org.kuali.rice.kns.bo.ModuleConfiguration; |
| 23 | |
import org.kuali.rice.kns.dao.LookupDao; |
| 24 | |
import org.kuali.rice.kns.dao.impl.LookupDaoJpa; |
| 25 | |
import org.kuali.rice.kns.dao.impl.LookupDaoOjb; |
| 26 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
| 27 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
| 28 | |
import org.kuali.rice.kns.service.KualiModuleService; |
| 29 | |
import org.kuali.rice.kns.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(KNSServiceLocator.getPersistenceStructureService()); |
| 75 | 0 | classSpecificLookupDaoJpa.setDateTimeService(KNSServiceLocator.getDateTimeService()); |
| 76 | 0 | lookupDaoValues.put(dataSourceName, classSpecificLookupDaoJpa); |
| 77 | 0 | return classSpecificLookupDaoJpa; |
| 78 | |
} else { |
| 79 | 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)."); |
| 80 | |
} |
| 81 | |
} else { |
| 82 | 0 | LookupDaoOjb classSpecificLookupDaoOjb = new LookupDaoOjb(); |
| 83 | 0 | classSpecificLookupDaoOjb.setJcdAlias(dataSourceName); |
| 84 | 0 | classSpecificLookupDaoOjb.setPersistenceStructureService(KNSServiceLocator.getPersistenceStructureService()); |
| 85 | 0 | classSpecificLookupDaoOjb.setDateTimeService(KNSServiceLocator.getDateTimeService()); |
| 86 | 0 | classSpecificLookupDaoOjb.setBusinessObjectDictionaryService(KNSServiceLocatorWeb.getBusinessObjectDictionaryService()); |
| 87 | 0 | lookupDaoValues.put(dataSourceName, classSpecificLookupDaoOjb); |
| 88 | 0 | return classSpecificLookupDaoOjb; |
| 89 | |
} |
| 90 | |
} |
| 91 | |
|
| 92 | |
} |
| 93 | |
} |
| 94 | |
|
| 95 | 0 | return (OrmUtils.isJpaAnnotated(clazz) && OrmUtils.isJpaEnabled()) ? lookupDaoJpa : lookupDaoOjb; |
| 96 | |
} |
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
public boolean createCriteria(Object example, String searchValue, String propertyName, Object criteria) { |
| 102 | 0 | return getDao(example.getClass()).createCriteria(example, searchValue, propertyName, criteria); |
| 103 | |
} |
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
public boolean createCriteria(Object example, String searchValue, String propertyName, boolean caseInsensitive, boolean treatWildcardsAndOperatorsAsLiteral, Object criteria) { |
| 109 | 0 | return getDao(example.getClass()).createCriteria(example, searchValue, propertyName, caseInsensitive, treatWildcardsAndOperatorsAsLiteral, criteria); |
| 110 | |
} |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
public Collection findCollectionBySearchHelper(Class example, Map formProps, boolean unbounded, boolean usePrimaryKeyValuesOnly) { |
| 116 | 0 | return getDao(example).findCollectionBySearchHelper(example, formProps, unbounded, usePrimaryKeyValuesOnly); |
| 117 | |
} |
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
public Collection findCollectionBySearchHelper(Class example, Map formProps, boolean unbounded, boolean usePrimaryKeyValuesOnly, Object additionalCriteria) { |
| 123 | 0 | return getDao(example).findCollectionBySearchHelper(example, formProps, unbounded, usePrimaryKeyValuesOnly, additionalCriteria); |
| 124 | |
} |
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
public Long findCountByMap(Object example, Map formProps) { |
| 130 | 0 | return getDao(example.getClass()).findCountByMap(example, formProps); |
| 131 | |
} |
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
public Object findObjectByMap(Object example, Map formProps) { |
| 137 | 0 | return getDao(example.getClass()).findObjectByMap(example, formProps); |
| 138 | |
} |
| 139 | |
|
| 140 | |
private static KualiModuleService getKualiModuleService() { |
| 141 | 0 | if (kualiModuleService == null) { |
| 142 | 0 | kualiModuleService = KNSServiceLocatorWeb.getKualiModuleService(); |
| 143 | |
} |
| 144 | 0 | return kualiModuleService; |
| 145 | |
} |
| 146 | |
} |