From 722eab62f2b392486f5fcd142293914f98effe3d Mon Sep 17 00:00:00 2001 From: James Agnew Date: Thu, 20 Jul 2017 14:03:11 -0400 Subject: [PATCH] Avoid opening two transactions for paging requests --- .../search/PersistedJpaBundleProvider.java | 33 ++++++++++--------- .../jpa/search/SearchCoordinatorSvcImpl.java | 2 +- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/PersistedJpaBundleProvider.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/PersistedJpaBundleProvider.java index d077dea033a..9145a745ab1 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/PersistedJpaBundleProvider.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/PersistedJpaBundleProvider.java @@ -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 doSearchOrEverythingInTransaction(final int theFromIndex, final int theToIndex) { + protected List 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>() { + template.execute(new TransactionCallbackWithoutResult() { @Override - public List 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>() { + @Override + public List doInTransaction(TransactionStatus theStatus) { + return doHistoryInTransaction(theFromIndex, theToIndex); + } + }); + case SEARCH: + case EVERYTHING: + default: + return doSearchOrEverything(theFromIndex, theToIndex); + } } public String getUuid() { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java index 8aa917a79e3..8e1e447de63 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImpl.java @@ -106,7 +106,7 @@ public class SearchCoordinatorSvcImpl implements ISearchCoordinatorSvc { } @Override - @Transactional(propagation=Propagation.SUPPORTS) + @Transactional(propagation=Propagation.NEVER) public List getResources(final String theUuid, int theFrom, int theTo) { if (myNeverUseLocalSearchForUnitTests == false) { SearchTask task = myIdToSearchTask.get(theUuid);