More perf work
This commit is contained in:
parent
4bf97e836a
commit
61a61cddee
|
@ -1,5 +1,7 @@
|
|||
package ca.uhn.fhir.jpa.dao;
|
||||
|
||||
import static java.util.Collections.newSetFromMap;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR JPA Server
|
||||
|
@ -21,9 +23,11 @@ package ca.uhn.fhir.jpa.dao;
|
|||
*/
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import ca.uhn.fhir.jpa.dao.SearchParameterMap.QueryParameterTypeComparator;
|
||||
import ca.uhn.fhir.model.api.IQueryParameterAnd;
|
||||
import ca.uhn.fhir.model.api.IQueryParameterOr;
|
||||
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||
|
@ -32,9 +36,31 @@ import ca.uhn.fhir.rest.api.SortSpec;
|
|||
import ca.uhn.fhir.rest.param.DateParam;
|
||||
import ca.uhn.fhir.rest.param.DateRangeParam;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.ObjectUtil;
|
||||
|
||||
public class SearchParameterMap extends LinkedHashMap<String, List<List<? extends IQueryParameterType>>> {
|
||||
|
||||
public class QueryParameterTypeComparator implements Comparator<IQueryParameterType> {
|
||||
|
||||
@Override
|
||||
public int compare(IQueryParameterType theO1, IQueryParameterType theO2) {
|
||||
int retVal = 0;
|
||||
|
||||
if (theO1.getMissing() == null && theO2.getMissing() == null) {
|
||||
// neither are missing
|
||||
} else if (theO1.getMissing() == null) {
|
||||
retVal = -1;
|
||||
} else if (theO2.getMissing() == null) {
|
||||
retVal = 1;
|
||||
} else if (!ObjectUtil.equals(theO1.getMissing(), theO2.getMissing())) {
|
||||
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer myCount;
|
||||
|
@ -279,4 +305,24 @@ public class SearchParameterMap extends LinkedHashMap<String, List<List<? extend
|
|||
}
|
||||
}
|
||||
|
||||
public String toQueryString() {
|
||||
StringBuilder b = new StringBuilder();
|
||||
|
||||
ArrayList<String> keys = new ArrayList<String>(keySet());
|
||||
Collections.sort(keys);
|
||||
for (String nextKey : keys) {
|
||||
|
||||
List<List<? extends IQueryParameterType>> nextValuesAnds = get(nextKey);
|
||||
for (List<? extends IQueryParameterType> nextValuesAnd : nextValuesAnds) {
|
||||
for (List<? extends IQueryParameterType> nextValuesOrs : nextValuesAnds) {
|
||||
|
||||
nextValuesOrs = new ArrayList<IQueryParameterType>(nextValuesOrs);
|
||||
Collections.sort(nextValuesOrs, new QueryParameterTypeComparator());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package ca.uhn.fhir.jpa.provider;
|
||||
|
||||
import static java.util.Collections.addAll;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
|
||||
import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum;
|
||||
import ca.uhn.fhir.rest.param.*;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class SearchParameterMapTest {
|
||||
|
@ -16,6 +19,25 @@ public class SearchParameterMapTest {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testToQueryString() {
|
||||
SearchParameterMap map = new SearchParameterMap();
|
||||
|
||||
StringAndListParam familyAnd = new StringAndListParam()
|
||||
.addAnd(new StringOrListParam().add(new StringParam("ZZZ?").setExact(true)))
|
||||
.addAnd(new StringOrListParam().add(new StringParam("homer")).add(new StringParam("jay")))
|
||||
.addAnd(new StringOrListParam().add(new StringParam("simpson")).add(new StringParam("bouvier")));
|
||||
map.add("name", familyAnd);
|
||||
|
||||
DateAndListParam birthdateAnd = new DateAndListParam()
|
||||
.addAnd(new DateOrListParam().add(new DateParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, "2001")))
|
||||
.addAnd(new DateOrListParam().add(new DateParam(ParamPrefixEnum.LESSTHAN, "2002")));
|
||||
map.add("birthdate", birthdateAnd);
|
||||
|
||||
String queryString = map.toQueryString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@link Search} uses these ordinals so they shouldn't get out of order
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue