Avoid opening two transactions for paging requests
This commit is contained in:
parent
2b72bb6c2f
commit
722eab62f2
|
@ -34,8 +34,7 @@ import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
import org.springframework.transaction.TransactionStatus;
|
import org.springframework.transaction.TransactionStatus;
|
||||||
import org.springframework.transaction.support.TransactionCallback;
|
import org.springframework.transaction.support.*;
|
||||||
import org.springframework.transaction.support.TransactionTemplate;
|
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.jpa.dao.IDao;
|
import ca.uhn.fhir.jpa.dao.IDao;
|
||||||
|
@ -113,7 +112,7 @@ public class PersistedJpaBundleProvider implements IBundleProvider {
|
||||||
return retVal;
|
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();
|
ISearchBuilder sb = myDao.newSearchBuilder();
|
||||||
|
|
||||||
String resourceName = mySearchEntity.getResourceType();
|
String resourceName = mySearchEntity.getResourceType();
|
||||||
|
@ -175,22 +174,26 @@ public class PersistedJpaBundleProvider implements IBundleProvider {
|
||||||
|
|
||||||
TransactionTemplate template = new TransactionTemplate(myPlatformTransactionManager);
|
TransactionTemplate template = new TransactionTemplate(myPlatformTransactionManager);
|
||||||
|
|
||||||
return template.execute(new TransactionCallback<List<IBaseResource>>() {
|
template.execute(new TransactionCallbackWithoutResult() {
|
||||||
@Override
|
@Override
|
||||||
public List<IBaseResource> doInTransaction(TransactionStatus theStatus) {
|
protected void doInTransactionWithoutResult(TransactionStatus theStatus) {
|
||||||
ensureSearchEntityLoaded();
|
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() {
|
public String getUuid() {
|
||||||
|
|
|
@ -106,7 +106,7 @@ public class SearchCoordinatorSvcImpl implements ISearchCoordinatorSvc {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(propagation=Propagation.SUPPORTS)
|
@Transactional(propagation=Propagation.NEVER)
|
||||||
public List<Long> getResources(final String theUuid, int theFrom, int theTo) {
|
public List<Long> getResources(final String theUuid, int theFrom, int theTo) {
|
||||||
if (myNeverUseLocalSearchForUnitTests == false) {
|
if (myNeverUseLocalSearchForUnitTests == false) {
|
||||||
SearchTask task = myIdToSearchTask.get(theUuid);
|
SearchTask task = myIdToSearchTask.get(theUuid);
|
||||||
|
|
Loading…
Reference in New Issue