From 7585256037a079db5b6d9e2785c2f1ea58e0862f Mon Sep 17 00:00:00 2001 From: James Agnew Date: Mon, 4 May 2015 11:08:01 -0700 Subject: [PATCH] Add some logging --- .../ca/uhn/fhir/rest/param/StringParam.java | 3 +++ .../java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java | 5 +++-- .../uhn/fhir/jpa/dao/BaseFhirResourceDao.java | 17 ++++++++++++----- .../jpa/provider/ResourceProviderDstu2Test.java | 2 +- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/StringParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/StringParam.java index db31031ad21..fc475699ae4 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/StringParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/StringParam.java @@ -106,6 +106,9 @@ public class StringParam extends BaseParam implements IQueryParameterType { if (myExact) { builder.append("exact", myExact); } + if (getMissing() != null) { + builder.append("missing", getMissing().booleanValue()); + } return builder.toString(); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java index 87bb868b057..17cc6848585 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java @@ -425,11 +425,9 @@ public abstract class BaseFhirDao implements IDao { // Get list of IDs searchHistoryCurrentVersion(theResourceName, theId, theSince, end.getValue(), limit, tuples); - assert tuples.size() < 2 || !tuples.get(tuples.size() - 2).getUpdated().before(tuples.get(tuples.size() - 1).getUpdated()) : tuples.toString(); ourLog.info("Retrieved {} history IDs from current versions in {} ms", tuples.size(), timer.getMillisAndRestart()); searchHistoryHistory(theResourceName, theId, theSince, end.getValue(), limit, tuples); - assert tuples.size() < 2 || !tuples.get(tuples.size() - 2).getUpdated().before(tuples.get(tuples.size() - 1).getUpdated()) : tuples.toString(); ourLog.info("Retrieved {} history IDs from previous versions in {} ms", tuples.size(), timer.getMillisAndRestart()); // Sort merged list @@ -1042,6 +1040,9 @@ public abstract class BaseFhirDao implements IDao { quantityParams = extractSearchParamQuantity(entity, theResource); dateParams = extractSearchParamDates(entity, theResource); + ourLog.info("Indexing resource: {}", entity.getId()); + ourLog.info("Storing string indexes: {}", stringParams); + tokenParams = new ArrayList(); for (BaseResourceIndexedSearchParam next : extractSearchParamTokens(entity, theResource)) { if (next instanceof ResourceIndexedSearchParamToken) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java index 78f60593619..e2acc3f090d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java @@ -366,25 +366,32 @@ public abstract class BaseFhirResourceDao extends BaseFhirD } private Set addPredicateParamMissing(Set thePids, String joinName, String theParamName, Class theParamTable) { + String resourceType = getContext().getResourceDefinition(getResourceType()).getName(); + CriteriaBuilder builder = myEntityManager.getCriteriaBuilder(); CriteriaQuery cq = builder.createQuery(Long.class); Root from = cq.from(ResourceTable.class); cq.select(from.get("myId").as(Long.class)); - + Subquery subQ = cq.subquery(Long.class); Root subQfrom = subQ.from(theParamTable); subQ.select(subQfrom.get("myResourcePid").as(Long.class)); - subQ.where(builder.equal(subQfrom.get("myParamName"), theParamName)); - + Predicate subQname = builder.equal(subQfrom.get("myParamName"), theParamName); + Predicate subQtype = builder.equal(subQfrom.get("myResourceType"), resourceType); + subQ.where(builder.and(subQtype, subQname)); + Predicate joinPredicate = builder.not(builder.in(from.get("myId")).value(subQ)); + Predicate typePredicate = builder.equal(from.get("myResourceType"), resourceType); if (thePids.size() > 0) { Predicate inPids = (from.get("myId").in(thePids)); - cq.where(builder.and(inPids, joinPredicate)); + cq.where(builder.and(inPids, typePredicate, joinPredicate)); } else { - cq.where(joinPredicate); + cq.where(builder.and(typePredicate, joinPredicate)); } + ourLog.info("Adding :missing qualifier for parameter '{}'", theParamName); + TypedQuery q = myEntityManager.createQuery(cq); List resultList = q.getResultList(); HashSet retVal = new HashSet(resultList); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java index c04e21ee3a8..c88aa5b6c83 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java @@ -359,7 +359,7 @@ public class ResourceProviderDstu2Test { List list = toIdListUnqualifiedVersionless(found); ourLog.info(methodName + ": " + list.toString()); assertThat(list, not(containsInRelativeOrder(orgNotMissing))); - assertThat(list, containsInRelativeOrder(orgMissing)); + assertThat("Wanted " + orgMissing + " but found: " + list, list, containsInRelativeOrder(orgMissing)); } }