diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java index 8306125dfd3..bc70dcc2004 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java @@ -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 implements IDao, private Map, IFhirResourceDao> getDaos() { if (myResourceTypeToDao == null) { - Map, IFhirResourceDao> theResourceTypeToDao = new HashMap<>(); + Map, IFhirResourceDao> resourceTypeToDao = new HashMap<>(); + Map 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 extractSearchParamCoords(ResourceTable theEntity, IBaseResource theResource) { return mySearchParamExtractor.extractSearchParamCoords(theEntity, theResource); @@ -948,7 +959,9 @@ public abstract class BaseHapiFhirDao implements IDao, @Override public void setApplicationContext(ApplicationContext theApplicationContext) throws BeansException { - myApplicationContext = theApplicationContext; + if (myApplicationContext == null) { + myApplicationContext = theApplicationContext; + } } public void setConfig(DaoConfig theConfig) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java index 10fc0d040e8..6cff70e1f1e 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java @@ -1336,5 +1336,9 @@ public abstract class BaseHapiFhirResourceDao extends B } } + @PostConstruct + public void start() { + ourLog.info("Starting resource DAO for type: {}", getResourceName()); + } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java index 7f40beeead0..58d9d74ad1c 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirSystemDao.java @@ -305,7 +305,7 @@ public abstract class BaseHapiFhirSystemDao extends BaseHapiFhirDao