Remove newSearchBuilder() from BaseHapiFhirDao

This commit is contained in:
Ken Stevens 2020-01-24 12:19:08 -05:00
parent 39c7642d8c
commit 16cb9a74e4
8 changed files with 32 additions and 17 deletions

View File

@ -327,6 +327,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> extends BaseStora
} }
} }
// FIXME KHS remove this method
public <R extends IBaseResource> IFhirResourceDao<R> getDao(Class<R> theType) { public <R extends IBaseResource> IFhirResourceDao<R> getDao(Class<R> theType) {
return myDaoRegistry.getResourceDaoOrNull(theType); return myDaoRegistry.getResourceDaoOrNull(theType);
} }

View File

@ -75,6 +75,7 @@ import org.springframework.stereotype.Component;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType; import javax.persistence.PersistenceContextType;
@ -102,8 +103,8 @@ public class SearchBuilder implements ISearchBuilder {
private static final List<ResourcePersistentId> EMPTY_LONG_LIST = Collections.unmodifiableList(new ArrayList<>()); private static final List<ResourcePersistentId> EMPTY_LONG_LIST = Collections.unmodifiableList(new ArrayList<>());
private static final Logger ourLog = LoggerFactory.getLogger(SearchBuilder.class); private static final Logger ourLog = LoggerFactory.getLogger(SearchBuilder.class);
private static ResourcePersistentId NO_MORE = new ResourcePersistentId(-1L); private static ResourcePersistentId NO_MORE = new ResourcePersistentId(-1L);
private final boolean myDontUseHashesForSearch; @Autowired
private final DaoConfig myDaoConfig; private DaoConfig myDaoConfig;
@Autowired @Autowired
protected IInterceptorBroadcaster myInterceptorBroadcaster; protected IInterceptorBroadcaster myInterceptorBroadcaster;
@Autowired @Autowired
@ -125,7 +126,7 @@ public class SearchBuilder implements ISearchBuilder {
private List<ResourcePersistentId> myAlsoIncludePids; private List<ResourcePersistentId> myAlsoIncludePids;
private CriteriaBuilder myBuilder; private CriteriaBuilder myBuilder;
private BaseHapiFhirDao<?> myCallingDao; private IDao myCallingDao;
private SearchParameterMap myParams; private SearchParameterMap myParams;
private String mySearchUuid; private String mySearchUuid;
private int myFetchSize; private int myFetchSize;
@ -139,12 +140,10 @@ public class SearchBuilder implements ISearchBuilder {
/** /**
* Constructor * Constructor
*/ */
SearchBuilder(BaseHapiFhirDao<?> theDao, String theResourceName, Class<? extends IBaseResource> theResourceType) { SearchBuilder(IDao theDao, String theResourceName, Class<? extends IBaseResource> theResourceType) {
myCallingDao = theDao; myCallingDao = theDao;
myDaoConfig = theDao.getConfig();
myResourceName = theResourceName; myResourceName = theResourceName;
myResourceType = theResourceType; myResourceType = theResourceType;
myDontUseHashesForSearch = myDaoConfig.getDisableHashBasedSearches();
} }
@Override @Override
@ -435,7 +434,7 @@ public class SearchBuilder implements ISearchBuilder {
if (param.getParamType() == RestSearchParameterTypeEnum.REFERENCE) { if (param.getParamType() == RestSearchParameterTypeEnum.REFERENCE) {
theQueryRoot.addPredicate(join.get("mySourcePath").as(String.class).in(param.getPathsSplit())); theQueryRoot.addPredicate(join.get("mySourcePath").as(String.class).in(param.getPathsSplit()));
} else { } else {
if (myDontUseHashesForSearch) { if (myDaoConfig.getDisableHashBasedSearches()) {
Predicate joinParam1 = theBuilder.equal(join.get("myParamName"), theSort.getParamName()); Predicate joinParam1 = theBuilder.equal(join.get("myParamName"), theSort.getParamName());
theQueryRoot.addPredicate(joinParam1); theQueryRoot.addPredicate(joinParam1);
} else { } else {
@ -892,10 +891,15 @@ public class SearchBuilder implements ISearchBuilder {
return myResourceName; return myResourceName;
} }
public BaseHapiFhirDao<?> getCallingDao() { public IDao getCallingDao() {
return myCallingDao; return myCallingDao;
} }
@VisibleForTesting
public void setDaoConfigForUnitTest(DaoConfig theDaoConfig) {
myDaoConfig = theDaoConfig;
}
public class IncludesIterator extends BaseIterator<ResourcePersistentId> implements Iterator<ResourcePersistentId> { public class IncludesIterator extends BaseIterator<ResourcePersistentId> implements Iterator<ResourcePersistentId> {
private final RequestDetails myRequest; private final RequestDetails myRequest;

View File

@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.dao.predicate;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.dao.BaseHapiFhirDao; import ca.uhn.fhir.jpa.dao.BaseHapiFhirDao;
import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.IDao;
import ca.uhn.fhir.jpa.dao.SearchBuilder; import ca.uhn.fhir.jpa.dao.SearchBuilder;
import ca.uhn.fhir.jpa.model.entity.BaseResourceIndexedSearchParam; import ca.uhn.fhir.jpa.model.entity.BaseResourceIndexedSearchParam;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamDate; import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamDate;
@ -31,7 +32,7 @@ abstract class BasePredicateBuilder {
DaoConfig myDaoConfig; DaoConfig myDaoConfig;
boolean myDontUseHashesForSearch; boolean myDontUseHashesForSearch;
final BaseHapiFhirDao<?> myCallingDao; final IDao myCallingDao;
final CriteriaBuilder myBuilder; final CriteriaBuilder myBuilder;
final QueryRoot myQueryRoot; final QueryRoot myQueryRoot;
final Class<? extends IBaseResource> myResourceType; final Class<? extends IBaseResource> myResourceType;

View File

@ -1,10 +1,7 @@
package ca.uhn.fhir.jpa.dao.predicate; package ca.uhn.fhir.jpa.dao.predicate;
import ca.uhn.fhir.context.*; import ca.uhn.fhir.context.*;
import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; import ca.uhn.fhir.jpa.dao.*;
import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.dao.SearchBuilder;
import ca.uhn.fhir.jpa.dao.index.IdHelperService; import ca.uhn.fhir.jpa.dao.index.IdHelperService;
import ca.uhn.fhir.jpa.model.cross.ResourcePersistentId; import ca.uhn.fhir.jpa.model.cross.ResourcePersistentId;
import ca.uhn.fhir.jpa.model.entity.*; import ca.uhn.fhir.jpa.model.entity.*;
@ -50,6 +47,8 @@ class PredicateBuilderReference extends BasePredicateBuilder {
ISearchParamRegistry mySearchParamRegistry; ISearchParamRegistry mySearchParamRegistry;
@Autowired @Autowired
MatchUrlService myMatchUrlService; MatchUrlService myMatchUrlService;
@Autowired
DaoRegistry myDaoRegistry;
private final PredicateBuilder myPredicateBuilder; private final PredicateBuilder myPredicateBuilder;
@ -263,7 +262,7 @@ class PredicateBuilderReference extends BasePredicateBuilder {
RuntimeResourceDefinition typeDef = myContext.getResourceDefinition(nextType); RuntimeResourceDefinition typeDef = myContext.getResourceDefinition(nextType);
String subResourceName = typeDef.getName(); String subResourceName = typeDef.getName();
IFhirResourceDao<?> dao = myCallingDao.getDao(nextType); IDao dao = myDaoRegistry.getResourceDao(nextType);
if (dao == null) { if (dao == null) {
ourLog.debug("Don't have a DAO for type {}", nextType.getSimpleName()); ourLog.debug("Don't have a DAO for type {}", nextType.getSimpleName());
continue; continue;

View File

@ -1,5 +1,7 @@
package ca.uhn.fhir.jpa.dao.predicate; package ca.uhn.fhir.jpa.dao.predicate;
import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.DaoRegistry;
import ca.uhn.fhir.jpa.dao.SearchBuilder; import ca.uhn.fhir.jpa.dao.SearchBuilder;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamString; import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamString;
import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.jpa.model.entity.ResourceTable;
@ -10,6 +12,7 @@ import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException; import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -23,6 +26,8 @@ import java.util.List;
@Component @Component
@Scope("prototype") @Scope("prototype")
class PredicateBuilderString extends BasePredicateBuilder implements IPredicateBuilder { class PredicateBuilderString extends BasePredicateBuilder implements IPredicateBuilder {
@Autowired
DaoConfig myDaoConfig;
PredicateBuilderString(SearchBuilder theSearchBuilder) { PredicateBuilderString(SearchBuilder theSearchBuilder) {
super(theSearchBuilder); super(theSearchBuilder);
@ -139,7 +144,7 @@ class PredicateBuilderString extends BasePredicateBuilder implements IPredicateB
String likeExpression; String likeExpression;
if ((theParameter instanceof StringParam) && if ((theParameter instanceof StringParam) &&
(((((StringParam) theParameter).isContains()) && (((((StringParam) theParameter).isContains()) &&
(myCallingDao.getConfig().isAllowContainsSearches())) || (myDaoConfig.isAllowContainsSearches())) ||
(operation == SearchFilterParser.CompareOperation.co))) { (operation == SearchFilterParser.CompareOperation.co))) {
likeExpression = createLeftAndRightMatchLikeExpression(normalizedString); likeExpression = createLeftAndRightMatchLikeExpression(normalizedString);
} else if ((operation != SearchFilterParser.CompareOperation.ne) && } else if ((operation != SearchFilterParser.CompareOperation.ne) &&

View File

@ -565,6 +565,11 @@ public class SearchCoordinatorSvcImpl implements ISearchCoordinatorSvc {
myInterceptorBroadcaster = theInterceptorBroadcaster; myInterceptorBroadcaster = theInterceptorBroadcaster;
} }
@VisibleForTesting
public void setSearchBuilderFactoryForUnitTest(SearchBuilderFactory theSearchBuilderFactory) {
mySearchBuilderFactory = theSearchBuilderFactory;
}
/** /**
* A search task is a Callable task that runs in * A search task is a Callable task that runs in
* a thread pool to handle an individual search. One instance * a thread pool to handle an individual search. One instance

View File

@ -27,9 +27,8 @@ public class SearchBuilderTest {
@Test @Test
public void testIncludeIterator() { public void testIncludeIterator() {
BaseHapiFhirDao<?> mockDao = mock(BaseHapiFhirDao.class); BaseHapiFhirDao<?> mockDao = mock(BaseHapiFhirDao.class);
when(mockDao.getConfig()).thenReturn(new DaoConfig());
SearchBuilder searchBuilder = new SearchBuilder(mockDao, null, null); SearchBuilder searchBuilder = new SearchBuilder(mockDao, null, null);
searchBuilder.setDaoConfigForUnitTest(new DaoConfig());
searchBuilder.setParamsForUnitTest(new SearchParameterMap()); searchBuilder.setParamsForUnitTest(new SearchParameterMap());
EntityManager mockEntityManager = mock(EntityManager.class); EntityManager mockEntityManager = mock(EntityManager.class);
searchBuilder.setEntityManagerForUnitTest(mockEntityManager); searchBuilder.setEntityManagerForUnitTest(mockEntityManager);

View File

@ -93,6 +93,7 @@ public class SearchCoordinatorSvcImplTest {
mySvc.setSearchCacheServicesForUnitTest(mySearchCacheSvc, mySearchResultCacheSvc); mySvc.setSearchCacheServicesForUnitTest(mySearchCacheSvc, mySearchResultCacheSvc);
mySvc.setDaoRegistryForUnitTest(myDaoRegistry); mySvc.setDaoRegistryForUnitTest(myDaoRegistry);
mySvc.setInterceptorBroadcasterForUnitTest(myInterceptorBroadcaster); mySvc.setInterceptorBroadcasterForUnitTest(myInterceptorBroadcaster);
mySvc.setSearchBuilderFactoryForUnitTest(mySearchBuilderFactory);
DaoConfig daoConfig = new DaoConfig(); DaoConfig daoConfig = new DaoConfig();
mySvc.setDaoConfigForUnitTest(daoConfig); mySvc.setDaoConfigForUnitTest(daoConfig);