From 9c27e8e6dd3229784b9d79eda8a6d5816d30c7bf Mon Sep 17 00:00:00 2001 From: James Agnew Date: Thu, 4 Oct 2018 15:12:21 -0400 Subject: [PATCH] Fix an issue with the spring boot build --- .../java/ca/uhn/fhir/jpa/dao/DaoRegistry.java | 16 ++++++++++---- .../search/DatabaseBackedPagingProvider.java | 22 +++++-------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoRegistry.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoRegistry.java index dae6542ddf1..df11b1e8ba5 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoRegistry.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoRegistry.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.dao; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,14 +22,12 @@ package ca.uhn.fhir.jpa.dao; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeResourceDefinition; -import ca.uhn.fhir.rest.param.HasAndListParam; import org.apache.commons.lang3.Validate; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import javax.annotation.PostConstruct; import java.util.HashMap; import java.util.Map; @@ -39,12 +37,22 @@ public class DaoRegistry implements ApplicationContextAware { @Autowired private FhirContext myCtx; private volatile Map> myResourceNameToResourceDao; + private volatile IFhirSystemDao mySystemDao; @Override public void setApplicationContext(ApplicationContext theApplicationContext) throws BeansException { 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) { IFhirResourceDao retVal = getResourceNameToResourceDao().get(theResourceName); Validate.notNull(retVal, "No DAO exists for resource type %s - Have: %s", theResourceName, myResourceNameToResourceDao); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/DatabaseBackedPagingProvider.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/DatabaseBackedPagingProvider.java index d60b9864449..aedd0743dc9 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/DatabaseBackedPagingProvider.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/DatabaseBackedPagingProvider.java @@ -20,30 +20,17 @@ package ca.uhn.fhir.jpa.search; * #L% */ -import javax.persistence.EntityManager; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.PlatformTransactionManager; - -import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.dao.DaoRegistry; 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.server.BasePagingProvider; import ca.uhn.fhir.rest.server.IPagingProvider; +import org.springframework.beans.factory.annotation.Autowired; public class DatabaseBackedPagingProvider extends BasePagingProvider implements IPagingProvider { @Autowired - private FhirContext myContext; - @Autowired - private IFhirSystemDao myDao; - @Autowired - private EntityManager myEntityManager; - @Autowired - private PlatformTransactionManager myPlatformTransactionManager; - @Autowired - private ISearchResultDao mySearchResultDao; + private DaoRegistry myDaoRegistry; /** * Constructor @@ -63,7 +50,8 @@ public class DatabaseBackedPagingProvider extends BasePagingProvider implements @Override 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()) { return null; }