Prevent a crash if the application context has been set incorrectly in
embedded deployments
This commit is contained in:
parent
6788eb992d
commit
583437d656
|
@ -58,6 +58,7 @@ import ca.uhn.fhir.util.*;
|
|||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.hash.HashFunction;
|
||||
import com.google.common.hash.Hashing;
|
||||
|
@ -85,6 +86,7 @@ import org.springframework.stereotype.Repository;
|
|||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.persistence.*;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
|
@ -727,23 +729,32 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao,
|
|||
|
||||
private Map<Class<? extends IBaseResource>, IFhirResourceDao<?>> getDaos() {
|
||||
if (myResourceTypeToDao == null) {
|
||||
Map<Class<? extends IBaseResource>, IFhirResourceDao<?>> theResourceTypeToDao = new HashMap<>();
|
||||
Map<Class<? extends IBaseResource>, IFhirResourceDao<?>> resourceTypeToDao = new HashMap<>();
|
||||
|
||||
Map<String, IFhirResourceDao> daos = myApplicationContext.getBeansOfType(IFhirResourceDao.class, false, false);
|
||||
|
||||
String[] beanNames = myApplicationContext.getBeanNamesForType(IFhirResourceDao.class);
|
||||
|
||||
for (IFhirResourceDao<?> next : daos.values()) {
|
||||
theResourceTypeToDao.put(next.getResourceType(), next);
|
||||
resourceTypeToDao.put(next.getResourceType(), next);
|
||||
}
|
||||
|
||||
if (this instanceof IFhirResourceDao<?>) {
|
||||
IFhirResourceDao<?> thiz = (IFhirResourceDao<?>) this;
|
||||
theResourceTypeToDao.put(thiz.getResourceType(), thiz);
|
||||
resourceTypeToDao.put(thiz.getResourceType(), thiz);
|
||||
}
|
||||
|
||||
myResourceTypeToDao = theResourceTypeToDao;
|
||||
myResourceTypeToDao = resourceTypeToDao;
|
||||
}
|
||||
|
||||
return Collections.unmodifiableMap(myResourceTypeToDao);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void startClearCaches() {
|
||||
myResourceTypeToDao = null;
|
||||
}
|
||||
|
||||
|
||||
protected Set<ResourceIndexedSearchParamCoords> extractSearchParamCoords(ResourceTable theEntity, IBaseResource theResource) {
|
||||
return mySearchParamExtractor.extractSearchParamCoords(theEntity, theResource);
|
||||
|
@ -948,7 +959,9 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao,
|
|||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext theApplicationContext) throws BeansException {
|
||||
myApplicationContext = theApplicationContext;
|
||||
if (myApplicationContext == null) {
|
||||
myApplicationContext = theApplicationContext;
|
||||
}
|
||||
}
|
||||
|
||||
public void setConfig(DaoConfig theConfig) {
|
||||
|
|
|
@ -1336,5 +1336,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
}
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void start() {
|
||||
ourLog.info("Starting resource DAO for type: {}", getResourceName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -305,7 +305,7 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
|
|||
|
||||
final IBaseResource resource = toResource(resourceTable, false);
|
||||
|
||||
@SuppressWarnings("rawtypes") final IFhirResourceDao dao = getDao(resource.getClass());
|
||||
@SuppressWarnings("rawtypes") final IFhirResourceDao dao = getDaoOrThrowException(resource.getClass());
|
||||
dao.reindex(resource, resourceTable);
|
||||
return null;
|
||||
|
||||
|
|
Loading…
Reference in New Issue