Move getNextBatch into IResultIterator

This commit is contained in:
Tadgh 2020-08-01 13:00:55 -07:00
parent 1d6a26bf1d
commit 0a4d81eb85
3 changed files with 15 additions and 2 deletions

View File

@ -23,12 +23,15 @@ package ca.uhn.fhir.jpa.dao;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import java.io.Closeable;
import java.util.Collection;
import java.util.Iterator;
public interface IResultIterator extends Iterator<ResourcePersistentId>, Closeable {
int getSkippedCount();
int getNonSkippedCount();
int getNonSkippedCount();
Collection<ResourcePersistentId> getNextResultBatch(long theBatchSize);
}

View File

@ -1306,12 +1306,22 @@ public class SearchBuilder implements ISearchBuilder {
return myNonSkipCount;
}
@Override
public Collection<ResourcePersistentId> getNextResultBatch(long theBatchSize) {
Collection<ResourcePersistentId> batch = new ArrayList<>();
while (this.hasNext() && batch.size() < theBatchSize) {
batch.add(this.next());
}
return batch;
}
@Override
public void close() {
if (myResultsIterator != null) {
myResultsIterator.close();
}
}
}
private static class CountQueryIterator implements Iterator<Long> {

View File

@ -84,7 +84,7 @@ public class EmpiBatchSvcImpl implements IEmpiBatchSvc {
try (IResultIterator query = theSearchBuilder.createQuery(theSpMap, searchRuntimeDetails, null, RequestPartitionId.defaultPartition())) {
Collection<ResourcePersistentId> pidBatch;
do {
pidBatch = getPidBatch(query);
pidBatch = query.getNextResultBatch(BUFFER_SIZE);
total += loadPidsAndSubmitToEmpiChannel(theSearchBuilder, pidBatch);
} while (query.hasNext());
} catch (IOException theE) {