Allow configuration of default page size in SimpleBundleProvider

This commit is contained in:
James Agnew 2018-07-27 18:34:12 +07:00
parent d04db790a3
commit f03d6b7c22
9 changed files with 58 additions and 12 deletions

View File

@ -19,13 +19,14 @@ cache:
install: /bin/true install: /bin/true
# This seems to be required to get travis to set Xmx4g, per https://github.com/travis-ci/travis-ci/issues/3893
before_script: before_script:
# This seems to be required to get travis to set Xmx4g, per https://github.com/travis-ci/travis-ci/issues/3893
- export MAVEN_SKIP_RC=true - export MAVEN_SKIP_RC=true
# Sometimes things get restored from the cache with bad permissions. See https://github.com/travis-ci/travis-ci/issues/9630
- sudo chmod -R 777 "$HOME/.m2/repository";
- sudo chown -R travis:travis "$HOME/.m2/repository";
script: script:
# - mvn -e -B clean install && cd hapi-fhir-ra && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID clean test jacoco:report coveralls:report # - mvn -e -B clean install && cd hapi-fhir-ra && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID clean test jacoco:report coveralls:report
# - mvn -Dci=true -e -B -P ALLMODULES,NOPARALLEL,ERRORPRONE clean install && cd hapi-fhir-jacoco && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID jacoco:report coveralls:report # - mvn -Dci=true -e -B -P ALLMODULES,NOPARALLEL,ERRORPRONE clean install && cd hapi-fhir-jacoco && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID jacoco:report coveralls:report
- sudo chmod -R 777 "$HOME/.m2/repository";
- sudo chown -R travis:travis "$HOME/.m2/repository";
- mvn -Dci=true -e -B -P ALLMODULES,REDUCED_JPA_TESTS,ERRORPRONE,JACOCO clean install && cd hapi-fhir-jacoco && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID jacoco:report coveralls:report; - mvn -Dci=true -e -B -P ALLMODULES,REDUCED_JPA_TESTS,ERRORPRONE,JACOCO clean install && cd hapi-fhir-jacoco && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID jacoco:report coveralls:report;

View File

@ -23,6 +23,9 @@ package ca.uhn.fhir.jpa.entity;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.parser.IParser;
/**
* @see ResourceHistoryTable#ENCODING_COL_LENGTH
*/
public enum ResourceEncodingEnum { public enum ResourceEncodingEnum {
/* /*

View File

@ -43,6 +43,10 @@ public class ResourceHistoryTable extends BaseHasResource implements Serializabl
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static final String IDX_RESVER_ID_VER = "IDX_RESVER_ID_VER"; public static final String IDX_RESVER_ID_VER = "IDX_RESVER_ID_VER";
/**
* @see ResourceEncodingEnum
*/
public static final int ENCODING_COL_LENGTH = 5;
@Id @Id
@SequenceGenerator(name = "SEQ_RESOURCE_HISTORY_ID", sequenceName = "SEQ_RESOURCE_HISTORY_ID") @SequenceGenerator(name = "SEQ_RESOURCE_HISTORY_ID", sequenceName = "SEQ_RESOURCE_HISTORY_ID")
@ -67,7 +71,7 @@ public class ResourceHistoryTable extends BaseHasResource implements Serializabl
@OptimisticLock(excluded = true) @OptimisticLock(excluded = true)
private byte[] myResource; private byte[] myResource;
@Column(name = "RES_ENCODING", nullable = false, length = 5) @Column(name = "RES_ENCODING", nullable = false, length = ENCODING_COL_LENGTH)
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
@OptimisticLock(excluded = true) @OptimisticLock(excluded = true)
private ResourceEncodingEnum myEncoding; private ResourceEncodingEnum myEncoding;

View File

@ -61,6 +61,7 @@ import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionCallbackWithoutResult; import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate; import org.springframework.transaction.support.TransactionTemplate;
import javax.annotation.Nullable;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
@ -408,7 +409,11 @@ public class SearchCoordinatorSvcImpl implements ISearchCoordinatorSvc {
myManagedTxManager = theTxManager; myManagedTxManager = theTxManager;
} }
static Pageable toPage(final int theFromIndex, int theToIndex) { /**
* Creates a {@link Pageable} using a start and end index
*/
@SuppressWarnings("WeakerAccess")
public static @Nullable Pageable toPage(final int theFromIndex, int theToIndex) {
int pageSize = theToIndex - theFromIndex; int pageSize = theToIndex - theFromIndex;
if (pageSize < 1) { if (pageSize < 1) {
return null; return null;

View File

@ -31,6 +31,7 @@ public class SimpleBundleProvider implements IBundleProvider {
private final List<IBaseResource> myList; private final List<IBaseResource> myList;
private final String myUuid; private final String myUuid;
private Integer myPreferredPageSize;
public SimpleBundleProvider(List<IBaseResource> theList) { public SimpleBundleProvider(List<IBaseResource> theList) {
this(theList, null); this(theList, null);
@ -69,9 +70,20 @@ public class SimpleBundleProvider implements IBundleProvider {
return myUuid; return myUuid;
} }
/**
* Defaults to null
*/
@Override @Override
public Integer preferredPageSize() { public Integer preferredPageSize() {
return null; return myPreferredPageSize;
}
/**
* Sets the preferred page size to be returned by {@link #preferredPageSize()}.
* Default is <code>null</code>.
*/
public void setPreferredPageSize(Integer thePreferredPageSize) {
myPreferredPageSize = thePreferredPageSize;
} }
@Override @Override

View File

@ -65,8 +65,8 @@ public class HashMapResourceProvider<T extends IBaseResource> implements IResour
private final Class<T> myResourceType; private final Class<T> myResourceType;
private final FhirContext myFhirContext; private final FhirContext myFhirContext;
private final String myResourceName; private final String myResourceName;
protected Map<String, TreeMap<Long, T>> myIdToVersionToResourceMap = new HashMap<>(); protected Map<String, TreeMap<Long, T>> myIdToVersionToResourceMap = new LinkedHashMap<>();
protected Map<String, LinkedList<T>> myIdToHistory = new HashMap<>(); protected Map<String, LinkedList<T>> myIdToHistory = new LinkedHashMap<>();
protected LinkedList<T> myTypeHistory = new LinkedList<>(); protected LinkedList<T> myTypeHistory = new LinkedList<>();
private long myNextId; private long myNextId;
private AtomicLong myDeleteCount = new AtomicLong(0); private AtomicLong myDeleteCount = new AtomicLong(0);

View File

@ -0,0 +1,18 @@
package ca.uhn.fhir.rest.server;
import org.junit.Test;
import static org.junit.Assert.*;
public class SimpleBundleProviderTest {
@Test
public void testPreferredPageSize() {
SimpleBundleProvider p = new SimpleBundleProvider();
assertEquals(null, p.preferredPageSize());
p.setPreferredPageSize(100);
assertEquals(100, p.preferredPageSize().intValue());
}
}

View File

@ -164,7 +164,9 @@
<![CDATA[<code>_id</code>]]> search parameter now has the <![CDATA[<code>_id</code>]]> search parameter now has the
search parameter marked as "required". This means that additional search parameter marked as "required". This means that additional
search methods can be added in subclasses without their intended search methods can be added in subclasses without their intended
searches being routed to the searchById method. searches being routed to the searchById method. Also, the resource
map now uses a LinkedHashMap, so searches return a predictable
order for unit tests.
</action> </action>
<action type="fix"> <action type="fix">
Fixed a bug when creating a custom search parameter in the JPA Fixed a bug when creating a custom search parameter in the JPA
@ -209,7 +211,8 @@
</action> </action>
<action type="add"> <action type="add">
SimpleBundleProvider has been modified to optionally allow calling SimpleBundleProvider has been modified to optionally allow calling
code to specify a search UUID code to specify a search UUID, and a field to allow the preferred
page size to be configured.
</action> </action>
</release> </release>
<release version="3.4.0" date="2018-05-28"> <release version="3.4.0" date="2018-05-28">