This commit is contained in:
Ken Stevens 2020-01-23 19:12:05 -05:00
parent 99949629a8
commit e031ad203e
15 changed files with 22 additions and 37 deletions

View File

@ -213,9 +213,8 @@ public class BulkDataExportSvcImpl implements IBulkDataExportSvc {
ourLog.info("Bulk export assembling export of type {} for job {}", nextType, theJobUuid);
ISearchBuilder sb = dao.newSearchBuilder();
Class<? extends IBaseResource> nextTypeClass = myContext.getResourceDefinition(nextType).getImplementingClass();
sb.setType(nextTypeClass, nextType);
ISearchBuilder sb = dao.newSearchBuilder(nextType, nextTypeClass);
SearchParameterMap map = new SearchParameterMap();
map.setLoadSynchronous(true);
@ -225,8 +224,6 @@ public class BulkDataExportSvcImpl implements IBulkDataExportSvc {
IResultIterator resultIterator = sb.createQuery(map, new SearchRuntimeDetails(null, theJobUuid), null);
storeResultsToFiles(nextCollection, sb, resultIterator, jobResourceCounter, jobStopwatch);
}
job.setStatus(BulkJobStatusEnum.COMPLETE);

View File

@ -456,8 +456,8 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> extends BaseStora
// TODO KHS inject a searchBuilderFactory into callers of this method and delete this method
@Override
public SearchBuilder newSearchBuilder() {
return mySearchBuilderFactory.newSearchBuilder(this);
public SearchBuilder newSearchBuilder(String theResourceName, Class<? extends IBaseResource> theResourceType) {
return mySearchBuilderFactory.newSearchBuilder(this, theResourceName, theResourceType);
}
public void notifyInterceptors(RestOperationTypeEnum theOperationType, ActionRequestDetails theRequestDetails) {

View File

@ -1126,8 +1126,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
@Override
public Set<ResourcePersistentId> searchForIds(SearchParameterMap theParams, RequestDetails theRequest) {
SearchBuilder builder = newSearchBuilder();
builder.setType(getResourceType(), getResourceName());
SearchBuilder builder = newSearchBuilder(getResourceName(), getResourceType());
// FIXME: fail if too many results

View File

@ -48,7 +48,7 @@ public interface IDao {
*/
void injectDependenciesIntoBundleProvider(PersistedJpaBundleProvider theProvider);
ISearchBuilder newSearchBuilder();
ISearchBuilder newSearchBuilder(String theResourceName, Class<? extends IBaseResource> theResourceType);
IBaseResource toResource(BaseHasResource theEntity, boolean theForHistoryOperation);

View File

@ -54,8 +54,6 @@ public interface ISearchBuilder {
*/
void setFetchSize(int theFetchSize);
void setType(Class<? extends IBaseResource> theResourceType, String theResourceName);
void setPreviouslyAddedResourcePids(List<ResourcePersistentId> thePreviouslyAddedResourcePids);
}

View File

@ -127,21 +127,23 @@ public class SearchBuilder implements ISearchBuilder {
private CriteriaBuilder myBuilder;
private BaseHapiFhirDao<?> myCallingDao;
private SearchParameterMap myParams;
private String myResourceName;
private Class<? extends IBaseResource> myResourceType;
private String mySearchUuid;
private int myFetchSize;
private Integer myMaxResultsToFetch;
private Set<ResourcePersistentId> myPidSet;
private PredicateBuilder myPredicateBuilder;
private final QueryRoot myQueryRoot = new QueryRoot();
private final String myResourceName;
private final Class<? extends IBaseResource> myResourceType;
/**
* Constructor
*/
SearchBuilder(BaseHapiFhirDao<?> theDao) {
SearchBuilder(BaseHapiFhirDao<?> theDao, String theResourceName, Class<? extends IBaseResource> theResourceType) {
myCallingDao = theDao;
myDaoConfig = theDao.getConfig();
myResourceName = theResourceName;
myResourceType = theResourceType;
myDontUseHashesForSearch = myDaoConfig.getDisableHashBasedSearches();
}
@ -860,13 +862,6 @@ public class SearchBuilder implements ISearchBuilder {
myFetchSize = theFetchSize;
}
// FIXME KHS move this into constructor and make these final
@Override
public void setType(Class<? extends IBaseResource> theResourceType, String theResourceName) {
myResourceType = theResourceType;
myResourceName = theResourceName;
}
@VisibleForTesting
void setParamsForUnitTest(SearchParameterMap theParams) {
myParams = theParams;

View File

@ -20,11 +20,12 @@ package ca.uhn.fhir.jpa.dao;
* #L%
*/
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.springframework.beans.factory.annotation.Lookup;
import org.springframework.stereotype.Service;
@Service
public abstract class SearchBuilderFactory {
@Lookup
public abstract SearchBuilder newSearchBuilder(BaseHapiFhirDao theBaseHapiFhirResourceDao);
public abstract SearchBuilder newSearchBuilder(BaseHapiFhirDao theBaseHapiFhirResourceDao, String theResourceName, Class<? extends IBaseResource> theResourceType);
}

View File

@ -36,7 +36,7 @@ public class PredicateBuilder {
}
void addPredicateCoords(String theResourceName, String theParamName, List<? extends IQueryParameterType> theNextAnd) {
myPredicateBuilderCoords.addPredicate(theResourceName, theParamName, theNextAnd);
myPredicateBuilderCoords.addPredicate(theResourceName, theParamName, theNextAnd, null);
}
Predicate addPredicateDate(String theResourceName, String theParamName, List<? extends IQueryParameterType> theNextAnd, SearchFilterParser.CompareOperation theOperation) {

View File

@ -502,7 +502,6 @@ class PredicateBuilderReference extends BasePredicateBuilder {
// TODO: we clear the predicates below because the filter builds up
// its own collection of predicates. It'd probably be good at some
// point to do something more fancy...
// FIXME KHS
ArrayList<Predicate> holdPredicates = new ArrayList<>(myQueryRoot.getPredicates());
Predicate filterPredicate = processFilter(filter, theResourceName, theRequest);

View File

@ -4,6 +4,7 @@ import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamDate;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import javax.persistence.criteria.*;
import java.util.Collections;
import java.util.List;
import java.util.Stack;
@ -60,7 +61,6 @@ public class QueryRoot {
top().clearPredicates();
}
// FIXME KHS don't leak
List<Predicate> getPredicates() {
return top().getPredicates();
}

View File

@ -5,6 +5,7 @@ import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import javax.persistence.criteria.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class QueryRootEntry {
@ -54,9 +55,8 @@ public class QueryRootEntry {
myPredicates.clear();
}
// FIXME KHS don't leak
List<Predicate> getPredicates() {
return myPredicates;
return Collections.unmodifiableList(myPredicates);
}
public void where(Predicate theAnd) {

View File

@ -170,11 +170,9 @@ public class PersistedJpaBundleProvider implements IBundleProvider {
// No resources to fetch (e.g. we did a _summary=count search)
return Collections.emptyList();
}
final ISearchBuilder sb = myDao.newSearchBuilder();
String resourceName = mySearchEntity.getResourceType();
Class<? extends IBaseResource> resourceType = myContext.getResourceDefinition(resourceName).getImplementingClass();
sb.setType(resourceType, resourceName);
final ISearchBuilder sb = myDao.newSearchBuilder(resourceName, resourceType);
final List<ResourcePersistentId> pidsSubList = mySearchCoordinatorSvc.getResources(myUuid, theFromIndex, theToIndex, myRequest);

View File

@ -286,8 +286,7 @@ public class SearchCoordinatorSvcImpl implements ISearchCoordinatorSvc {
ourLog.debug("Registering new search {}", searchUuid);
Class<? extends IBaseResource> resourceTypeClass = myContext.getResourceDefinition(theResourceType).getImplementingClass();
final ISearchBuilder sb = theCallingDao.newSearchBuilder();
sb.setType(resourceTypeClass, theResourceType);
final ISearchBuilder sb = theCallingDao.newSearchBuilder(theResourceType, resourceTypeClass);
sb.setFetchSize(mySyncSize);
final Integer loadSynchronousUpTo = getLoadSynchronousUpToOrNull(theCacheControlDirective);
@ -645,8 +644,7 @@ public class SearchCoordinatorSvcImpl implements ISearchCoordinatorSvc {
private ISearchBuilder newSearchBuilder() {
Class<? extends IBaseResource> resourceTypeClass = myContext.getResourceDefinition(myResourceType).getImplementingClass();
ISearchBuilder sb = myCallingDao.newSearchBuilder();
sb.setType(resourceTypeClass, myResourceType);
ISearchBuilder sb = myCallingDao.newSearchBuilder(myResourceType, resourceTypeClass);
return sb;
}

View File

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

View File

@ -77,7 +77,7 @@ public class SearchCoordinatorSvcImplTest {
@After
public void after() {
System.clearProperty(SearchCoordinatorSvcImpl.UNIT_TEST_CAPTURE_STACK);
verify(myCallingDao, atMost(myExpectedNumberOfSearchBuildersCreated)).newSearchBuilder();
verify(myCallingDao, atMost(myExpectedNumberOfSearchBuildersCreated)).newSearchBuilder(any(), any());
}
@Before
@ -97,7 +97,7 @@ public class SearchCoordinatorSvcImplTest {
DaoConfig daoConfig = new DaoConfig();
mySvc.setDaoConfigForUnitTest(daoConfig);
when(myCallingDao.newSearchBuilder()).thenReturn(mySearchBuilder);
when(myCallingDao.newSearchBuilder(any(), any())).thenReturn(mySearchBuilder);
when(myTxManager.getTransaction(any())).thenReturn(mock(TransactionStatus.class));