Avoid opening two transactions for paging requests

This commit is contained in:
James Agnew 2017-07-20 14:03:11 -04:00
parent 2b72bb6c2f
commit 722eab62f2
2 changed files with 19 additions and 16 deletions

View File

@ -34,8 +34,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.transaction.support.*;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.dao.IDao;
@ -113,7 +112,7 @@ public class PersistedJpaBundleProvider implements IBundleProvider {
return retVal;
}
protected List<IBaseResource> doSearchOrEverythingInTransaction(final int theFromIndex, final int theToIndex) {
protected List<IBaseResource> doSearchOrEverything(final int theFromIndex, final int theToIndex) {
ISearchBuilder sb = myDao.newSearchBuilder();
String resourceName = mySearchEntity.getResourceType();
@ -175,22 +174,26 @@ public class PersistedJpaBundleProvider implements IBundleProvider {
TransactionTemplate template = new TransactionTemplate(myPlatformTransactionManager);
return template.execute(new TransactionCallback<List<IBaseResource>>() {
template.execute(new TransactionCallbackWithoutResult() {
@Override
public List<IBaseResource> doInTransaction(TransactionStatus theStatus) {
protected void doInTransactionWithoutResult(TransactionStatus theStatus) {
ensureSearchEntityLoaded();
switch (mySearchEntity.getSearchType()) {
case HISTORY:
return doHistoryInTransaction(theFromIndex, theToIndex);
case SEARCH:
case EVERYTHING:
default:
return doSearchOrEverythingInTransaction(theFromIndex, theToIndex);
}
}
});
switch (mySearchEntity.getSearchType()) {
case HISTORY:
return template.execute(new TransactionCallback<List<IBaseResource>>() {
@Override
public List<IBaseResource> doInTransaction(TransactionStatus theStatus) {
return doHistoryInTransaction(theFromIndex, theToIndex);
}
});
case SEARCH:
case EVERYTHING:
default:
return doSearchOrEverything(theFromIndex, theToIndex);
}
}
public String getUuid() {

View File

@ -106,7 +106,7 @@ public class SearchCoordinatorSvcImpl implements ISearchCoordinatorSvc {
}
@Override
@Transactional(propagation=Propagation.SUPPORTS)
@Transactional(propagation=Propagation.NEVER)
public List<Long> getResources(final String theUuid, int theFrom, int theTo) {
if (myNeverUseLocalSearchForUnitTests == false) {
SearchTask task = myIdToSearchTask.get(theUuid);