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) {
return myDaoRegistry.getResourceDaoOrNull(theType);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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