Fix an issue with the spring boot build

This commit is contained in:
James Agnew 2018-10-04 15:12:21 -04:00
parent e0cb0a8188
commit 9c27e8e6dd
2 changed files with 17 additions and 21 deletions

View File

@ -22,14 +22,12 @@ package ca.uhn.fhir.jpa.dao;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.rest.param.HasAndListParam;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
import javax.annotation.PostConstruct;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -39,12 +37,22 @@ public class DaoRegistry implements ApplicationContextAware {
@Autowired @Autowired
private FhirContext myCtx; private FhirContext myCtx;
private volatile Map<String, IFhirResourceDao<?>> myResourceNameToResourceDao; private volatile Map<String, IFhirResourceDao<?>> myResourceNameToResourceDao;
private volatile IFhirSystemDao<?, ?> mySystemDao;
@Override @Override
public void setApplicationContext(ApplicationContext theApplicationContext) throws BeansException { public void setApplicationContext(ApplicationContext theApplicationContext) throws BeansException {
myAppCtx = theApplicationContext; myAppCtx = theApplicationContext;
} }
public IFhirSystemDao<?, ?> getSystemDao() {
IFhirSystemDao<?, ?> retVal = mySystemDao;
if (retVal == null) {
retVal = myAppCtx.getBean(IFhirSystemDao.class);
mySystemDao = retVal;
}
return retVal;
}
public IFhirResourceDao<?> getResourceDao(String theResourceName) { public IFhirResourceDao<?> getResourceDao(String theResourceName) {
IFhirResourceDao<?> retVal = getResourceNameToResourceDao().get(theResourceName); IFhirResourceDao<?> retVal = getResourceNameToResourceDao().get(theResourceName);
Validate.notNull(retVal, "No DAO exists for resource type %s - Have: %s", theResourceName, myResourceNameToResourceDao); Validate.notNull(retVal, "No DAO exists for resource type %s - Have: %s", theResourceName, myResourceNameToResourceDao);

View File

@ -20,30 +20,17 @@ package ca.uhn.fhir.jpa.search;
* #L% * #L%
*/ */
import javax.persistence.EntityManager; import ca.uhn.fhir.jpa.dao.DaoRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.PlatformTransactionManager;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.dao.data.ISearchResultDao;
import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.server.BasePagingProvider; import ca.uhn.fhir.rest.server.BasePagingProvider;
import ca.uhn.fhir.rest.server.IPagingProvider; import ca.uhn.fhir.rest.server.IPagingProvider;
import org.springframework.beans.factory.annotation.Autowired;
public class DatabaseBackedPagingProvider extends BasePagingProvider implements IPagingProvider { public class DatabaseBackedPagingProvider extends BasePagingProvider implements IPagingProvider {
@Autowired @Autowired
private FhirContext myContext; private DaoRegistry myDaoRegistry;
@Autowired
private IFhirSystemDao<?, ?> myDao;
@Autowired
private EntityManager myEntityManager;
@Autowired
private PlatformTransactionManager myPlatformTransactionManager;
@Autowired
private ISearchResultDao mySearchResultDao;
/** /**
* Constructor * Constructor
@ -63,7 +50,8 @@ public class DatabaseBackedPagingProvider extends BasePagingProvider implements
@Override @Override
public synchronized IBundleProvider retrieveResultList(String theId) { public synchronized IBundleProvider retrieveResultList(String theId) {
PersistedJpaBundleProvider provider = new PersistedJpaBundleProvider(theId, myDao); IFhirSystemDao<?, ?> systemDao = myDaoRegistry.getSystemDao();
PersistedJpaBundleProvider provider = new PersistedJpaBundleProvider(theId, systemDao);
if (!provider.ensureSearchEntityLoaded()) { if (!provider.ensureSearchEntityLoaded()) {
return null; return null;
} }