From dada2179663bc48bb3f4fdab283d9a4b0f538ea7 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 5 May 2020 11:11:24 -0400 Subject: [PATCH] Clean up hash code calculation (#1830) * Clean up hash code calculation * Test fixes * Test fix * Test fixes * Compile fix * Test fix --- .../dao/index/DaoSearchParamSynchronizer.java | 10 ++-- .../dao/r4/FhirResourceDaoR4UpdateTest.java | 33 +++++++++++ .../dao/r4/SearchParamExtractorR4Test.java | 16 +++--- .../BaseResourceIndexedSearchParam.java | 9 --- .../ResourceIndexedSearchParamCoords.java | 27 ++++----- .../ResourceIndexedSearchParamDate.java | 41 ++++++------- .../ResourceIndexedSearchParamNumber.java | 29 ++++++---- .../ResourceIndexedSearchParamQuantity.java | 52 ++++++++--------- .../ResourceIndexedSearchParamString.java | 43 +++++++------- .../ResourceIndexedSearchParamToken.java | 57 ++++++++----------- .../entity/ResourceIndexedSearchParamUri.java | 32 +++++------ ...esourceIndexedSearchParamQuantityTest.java | 1 + .../ResourceIndexedSearchParamStringTest.java | 6 ++ .../ResourceIndexedSearchParamTokenTest.java | 2 + .../ResourceIndexedSearchParamUriTest.java | 1 + .../extractor/BaseSearchParamExtractor.java | 4 +- .../ResourceIndexedSearchParams.java | 7 +-- .../extractor/SearchParamExtractorDstu2.java | 6 +- .../extractor/SearchParamExtractorDstu3.java | 5 +- .../extractor/SearchParamExtractorR4.java | 5 +- .../extractor/SearchParamExtractorR5.java | 6 +- .../fhir/jpa/searchparam/IndexStressTest.java | 3 +- .../SearchParamExtractorDstu3Test.java | 16 +++--- .../SearchParamExtractorMegaTest.java | 9 +-- 24 files changed, 227 insertions(+), 193 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/index/DaoSearchParamSynchronizer.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/index/DaoSearchParamSynchronizer.java index 11910a1e6ff..fb7ff3be39e 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/index/DaoSearchParamSynchronizer.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/index/DaoSearchParamSynchronizer.java @@ -61,17 +61,19 @@ public class DaoSearchParamSynchronizer { } private void synchronize(ResourceIndexedSearchParams theParams, ResourceTable theEntity, AddRemoveCount theAddRemoveCount, Collection theNewParms, Collection theExistingParms) { + for (T next : theNewParms) { + next.setPartitionId(theEntity.getPartitionId()); + next.calculateHashes(); + } + List quantitiesToRemove = subtract(theExistingParms, theNewParms); List quantitiesToAdd = subtract(theNewParms, theExistingParms); tryToReuseIndexEntities(quantitiesToRemove, quantitiesToAdd); + for (T next : quantitiesToRemove) { myEntityManager.remove(next); theEntity.getParamsQuantity().remove(next); } - for (T next : quantitiesToAdd) { - next.setPartitionId(theEntity.getPartitionId()); - } - theParams.calculateHashes(theNewParms); for (T next : quantitiesToAdd) { myEntityManager.merge(next); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java index ecc4961b9b7..94674ee4610 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java @@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.dao.r4; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.model.cross.ResourcePersistentId; import ca.uhn.fhir.jpa.model.entity.ResourceHistoryTable; +import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamString; import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.util.TestUtil; @@ -85,6 +86,38 @@ public class FhirResourceDaoR4UpdateTest extends BaseJpaR4Test { } + /** + * Just in case any hash values are missing + */ + @Test + public void testCreateAndUpdateStringAndTokenWhereHashesAreNull() { + Patient p = new Patient(); + p.addIdentifier().setSystem("sys1").setValue("val1"); + p.addName().setFamily("FAMILY1"); + IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + + runInTransaction(()->{ + myEntityManager.createQuery("UPDATE ResourceIndexedSearchParamString s SET s.myHashIdentity = null").executeUpdate(); + myEntityManager.createQuery("UPDATE ResourceIndexedSearchParamString s SET s.myHashExact = null").executeUpdate(); + myEntityManager.createQuery("UPDATE ResourceIndexedSearchParamString s SET s.myHashNormalizedPrefix = null").executeUpdate(); + myEntityManager.createQuery("UPDATE ResourceIndexedSearchParamToken s SET s.myHashIdentity = null").executeUpdate(); + myEntityManager.createQuery("UPDATE ResourceIndexedSearchParamToken s SET s.myHashSystem = null").executeUpdate(); + myEntityManager.createQuery("UPDATE ResourceIndexedSearchParamToken s SET s.myHashValue = null").executeUpdate(); + myEntityManager.createQuery("UPDATE ResourceIndexedSearchParamToken s SET s.myHashSystemAndValue = null").executeUpdate(); + }); + + p = new Patient(); + p.setId(id); + p.addIdentifier().setSystem("sys2").setValue("val2"); + p.addName().setFamily("FAMILY2"); + myPatientDao.update(p); + + SearchParameterMap map = new SearchParameterMap(); + map.setLoadSynchronous(true); + map.add(Patient.SP_FAMILY, new StringParam("FAMILY2")); + Patient newPatient = (Patient) myPatientDao.search(map).getResources(0,1).get(0); + assertEquals("FAMILY2", newPatient.getName().get(0).getFamily()); + } @Test public void testUpdateNotModifiedDoesNotAffectDates() { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4Test.java index 87d30dc8172..74f4e13f3ee 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4Test.java @@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.dao.r4; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeSearchParam; +import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; import ca.uhn.fhir.context.support.IValidationSupport; import ca.uhn.fhir.jpa.model.config.PartitionSettings; import ca.uhn.fhir.jpa.model.entity.BaseResourceIndexedSearchParam; @@ -17,7 +18,6 @@ import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum; import ca.uhn.fhir.util.TestUtil; import com.google.common.collect.Sets; -import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.Consent; @@ -65,7 +65,7 @@ public class SearchParamExtractorR4Test { Observation obs = new Observation(); obs.addCategory().addCoding().setSystem("SYSTEM").setCode("CODE"); - SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), ourCtx, ourValidationSupport, mySearchParamRegistry); + SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), ourCtx, ourValidationSupport, mySearchParamRegistry, new PartitionSettings()); extractor.setPartitionConfigForUnitTest(new PartitionSettings()); Set tokens = extractor.extractSearchParamTokens(obs); assertEquals(1, tokens.size()); @@ -80,7 +80,7 @@ public class SearchParamExtractorR4Test { SearchParameter sp = new SearchParameter(); sp.addUseContext().setCode(new Coding().setSystem("http://system").setCode("code")); - SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), ourCtx, ourValidationSupport, mySearchParamRegistry); + SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), ourCtx, ourValidationSupport, mySearchParamRegistry, new PartitionSettings()); extractor.setPartitionConfigForUnitTest(new PartitionSettings()); Set tokens = extractor.extractSearchParamTokens(sp); assertEquals(1, tokens.size()); @@ -95,7 +95,7 @@ public class SearchParamExtractorR4Test { Encounter enc = new Encounter(); enc.addLocation().setLocation(new Reference("Location/123")); - SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), ourCtx, ourValidationSupport, mySearchParamRegistry); + SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), ourCtx, ourValidationSupport, mySearchParamRegistry, new PartitionSettings()); RuntimeSearchParam param = mySearchParamRegistry.getActiveSearchParam("Encounter", "location"); assertNotNull(param); ISearchParamExtractor.SearchParamSet links = extractor.extractResourceLinks(enc); @@ -110,7 +110,7 @@ public class SearchParamExtractorR4Test { Consent consent = new Consent(); consent.setSource(new Reference().setReference("Consent/999")); - SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), ourCtx, ourValidationSupport, mySearchParamRegistry); + SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), ourCtx, ourValidationSupport, mySearchParamRegistry, new PartitionSettings()); extractor.setPartitionConfigForUnitTest(new PartitionSettings()); RuntimeSearchParam param = mySearchParamRegistry.getActiveSearchParam("Consent", Consent.SP_SOURCE_REFERENCE); assertNotNull(param); @@ -126,7 +126,7 @@ public class SearchParamExtractorR4Test { Patient p = new Patient(); p.addIdentifier().setSystem("sys").setValue("val"); - SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), ourCtx, ourValidationSupport, mySearchParamRegistry); + SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), ourCtx, ourValidationSupport, mySearchParamRegistry, new PartitionSettings()); extractor.setPartitionConfigForUnitTest(new PartitionSettings()); RuntimeSearchParam param = mySearchParamRegistry.getActiveSearchParam("Patient", Patient.SP_IDENTIFIER); assertNotNull(param); @@ -149,7 +149,7 @@ public class SearchParamExtractorR4Test { Patient patient = new Patient(); patient.addExtension("http://patext", new Reference("Organization/AAA")); - SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), ourCtx, ourValidationSupport, mySearchParamRegistry); + SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), ourCtx, ourValidationSupport, mySearchParamRegistry, new PartitionSettings()); ISearchParamExtractor.SearchParamSet links = extractor.extractResourceLinks(patient); assertEquals(1, links.size()); @@ -165,7 +165,7 @@ public class SearchParamExtractorR4Test { .setCode(new CodeableConcept().addCoding(new Coding().setSystem("http://foo").setCode("code2"))) .setValue(new Quantity().setSystem("http://bar").setCode("code2").setValue(200)); - SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), ourCtx, ourValidationSupport, mySearchParamRegistry); + SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), ourCtx, ourValidationSupport, mySearchParamRegistry, new PartitionSettings()); Set links = extractor.extractSearchParamQuantity(o1); ourLog.info("Links:\n {}", links.stream().map(t -> t.toString()).collect(Collectors.joining("\n "))); assertEquals(4, links.size()); diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/BaseResourceIndexedSearchParam.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/BaseResourceIndexedSearchParam.java index b8bc0aca701..346fdf5340f 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/BaseResourceIndexedSearchParam.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/BaseResourceIndexedSearchParam.java @@ -85,13 +85,6 @@ public abstract class BaseResourceIndexedSearchParam extends BaseResourceIndex { @Transient private transient PartitionSettings myPartitionSettings; - /** - * Subclasses may override - */ - protected void clearHashes() { - // nothing - } - @Override public abstract Long getId(); @@ -100,7 +93,6 @@ public abstract class BaseResourceIndexedSearchParam extends BaseResourceIndex { } public void setParamName(String theName) { - clearHashes(); myParamName = theName; } @@ -109,7 +101,6 @@ public abstract class BaseResourceIndexedSearchParam extends BaseResourceIndex { } public BaseResourceIndexedSearchParam setResource(ResourceTable theResource) { - clearHashes(); myResource = theResource; myResourceType = theResource.getResourceType(); return this; diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamCoords.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamCoords.java index b91a7145bc0..aec6f32e7b8 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamCoords.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamCoords.java @@ -28,7 +28,15 @@ import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import org.hibernate.search.annotations.Field; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; @Embeddable @Entity @@ -68,21 +76,14 @@ public class ResourceIndexedSearchParamCoords extends BaseResourceIndexedSearchP setParamName(theParamName); setLatitude(theLatitude); setLongitude(theLongitude); + calculateHashes(); } @Override - @PrePersist public void calculateHashes() { - if (myHashIdentity == null && getParamName() != null) { - String resourceType = getResourceType(); - String paramName = getParamName(); - setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); - } - } - - @Override - protected void clearHashes() { - myHashIdentity = null; + String resourceType = getResourceType(); + String paramName = getParamName(); + setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); } @Override @@ -126,7 +127,7 @@ public class ResourceIndexedSearchParamCoords extends BaseResourceIndexedSearchP @Override public void setId(Long theId) { - myId =theId; + myId = theId; } diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamDate.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamDate.java index 2119e64ad18..d998fab6ae3 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamDate.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamDate.java @@ -35,7 +35,18 @@ import org.apache.commons.lang3.builder.ToStringStyle; import org.hibernate.search.annotations.Field; import org.hl7.fhir.r4.model.DateTimeType; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; import java.util.Date; @Embeddable @@ -62,9 +73,9 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar * Field which stores an integer representation of YYYYMDD as calculated by Calendar * e.g. 2019-01-20 -> 20190120 */ - @Column(name="SP_VALUE_LOW_DATE_ORDINAL") + @Column(name = "SP_VALUE_LOW_DATE_ORDINAL") public Integer myValueLowDateOrdinal; - @Column(name="SP_VALUE_HIGH_DATE_ORDINAL") + @Column(name = "SP_VALUE_HIGH_DATE_ORDINAL") public Integer myValueHighDateOrdinal; @Transient @@ -105,6 +116,7 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar computeValueHighDateOrdinal(theHighString); computeValueLowDateOrdinal(theLowString); myOriginalValue = theOriginalValue; + calculateHashes(); } private void computeValueHighDateOrdinal(String theHigh) { @@ -112,7 +124,8 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar this.myValueHighDateOrdinal = generateOrdinalDateInteger(theHigh); } } - private int generateOrdinalDateInteger(String theDateString){ + + private int generateOrdinalDateInteger(String theDateString) { if (theDateString.contains("T")) { theDateString = theDateString.substring(0, theDateString.indexOf("T")); } @@ -146,18 +159,10 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar } @Override - @PrePersist public void calculateHashes() { - if (myHashIdentity == null && getParamName() != null) { - String resourceType = getResourceType(); - String paramName = getParamName(); - setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); - } - } - - @Override - protected void clearHashes() { - myHashIdentity = null; + String resourceType = getResourceType(); + String paramName = getParamName(); + setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); } @Override @@ -192,7 +197,7 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar @Override public void setId(Long theId) { - myId =theId; + myId = theId; } protected Long getTimeFromDate(Date date) { @@ -260,14 +265,12 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar DateRangeParam range = new DateRangeParam(dateParam); - - boolean result; if (theUseOrdinalDatesForDayComparison) { result = matchesOrdinalDateBounds(range); result = matchesDateBounds(range); } else { - result = matchesDateBounds(range); + result = matchesDateBounds(range); } return result; diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamNumber.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamNumber.java index 8e71141210c..c58817d2973 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamNumber.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamNumber.java @@ -32,7 +32,15 @@ import org.hibernate.search.annotations.Field; import org.hibernate.search.annotations.FieldBridge; import org.hibernate.search.annotations.NumericField; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; import java.math.BigDecimal; import java.util.Objects; @@ -71,6 +79,7 @@ public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchP setResourceType(theResourceType); setParamName(theParamName); setValue(theValue); + calculateHashes(); } @Override @@ -83,18 +92,14 @@ public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchP @Override - @PrePersist public void calculateHashes() { - if (myHashIdentity == null && getParamName() != null) { - String resourceType = getResourceType(); - String paramName = getParamName(); - setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); - } + String resourceType = getResourceType(); + String paramName = getParamName(); + setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); } - @Override - protected void clearHashes() { - myHashIdentity = null; + public Long getHashIdentity() { + return myHashIdentity; } @Override @@ -112,7 +117,7 @@ public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchP EqualsBuilder b = new EqualsBuilder(); b.append(getResourceType(), obj.getResourceType()); b.append(getParamName(), obj.getParamName()); - b.append(getValue(), obj.getValue()); + b.append(getHashIdentity(), obj.getHashIdentity()); b.append(isMissing(), obj.isMissing()); return b.isEquals(); } @@ -128,7 +133,7 @@ public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchP @Override public void setId(Long theId) { - myId =theId; + myId = theId; } public BigDecimal getValue() { diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamQuantity.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamQuantity.java index c1b5d2617f6..c487641d1ad 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamQuantity.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamQuantity.java @@ -33,7 +33,15 @@ import org.hibernate.search.annotations.Field; import org.hibernate.search.annotations.FieldBridge; import org.hibernate.search.annotations.NumericField; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; import java.math.BigDecimal; import java.util.Objects; @@ -101,6 +109,7 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc setSystem(theSystem); setValue(theValue); setUnits(theUnits); + calculateHashes(); } @Override @@ -117,23 +126,14 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc @Override - @PrePersist public void calculateHashes() { - if (myHashIdentity == null && getParamName() != null) { - String resourceType = getResourceType(); - String paramName = getParamName(); - String units = getUnits(); - String system = getSystem(); - setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); - setHashIdentityAndUnits(calculateHashUnits(getPartitionSettings(), getPartitionId(), resourceType, paramName, units)); - setHashIdentitySystemAndUnits(calculateHashSystemAndUnits(getPartitionSettings(), getPartitionId(), resourceType, paramName, system, units)); - } - } - - @Override - protected void clearHashes() { - myHashIdentity = null; - myHashIdentityAndUnits = null; + String resourceType = getResourceType(); + String paramName = getParamName(); + String units = getUnits(); + String system = getSystem(); + setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); + setHashIdentityAndUnits(calculateHashUnits(getPartitionSettings(), getPartitionId(), resourceType, paramName, units)); + setHashIdentitySystemAndUnits(calculateHashSystemAndUnits(getPartitionSettings(), getPartitionId(), resourceType, paramName, system, units)); } @Override @@ -151,15 +151,14 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc EqualsBuilder b = new EqualsBuilder(); b.append(getResourceType(), obj.getResourceType()); b.append(getParamName(), obj.getParamName()); - b.append(getSystem(), obj.getSystem()); - b.append(getUnits(), obj.getUnits()); - b.append(getValue(), obj.getValue()); + b.append(getHashIdentity(), obj.getHashIdentity()); + b.append(getHashIdentityAndUnits(), obj.getHashIdentityAndUnits()); + b.append(getHashIdentitySystemAndUnits(), obj.getHashIdentitySystemAndUnits()); b.append(isMissing(), obj.isMissing()); return b.isEquals(); } public Long getHashIdentity() { - calculateHashes(); return myHashIdentity; } @@ -168,7 +167,6 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc } public Long getHashIdentityAndUnits() { - calculateHashes(); return myHashIdentityAndUnits; } @@ -177,7 +175,6 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc } private Long getHashIdentitySystemAndUnits() { - calculateHashes(); return myHashIdentitySystemAndUnits; } @@ -200,7 +197,6 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc } public void setSystem(String theSystem) { - clearHashes(); mySystem = theSystem; } @@ -209,7 +205,6 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc } public void setUnits(String theUnits) { - clearHashes(); myUnits = theUnits; } @@ -218,7 +213,6 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc } public ResourceIndexedSearchParamQuantity setValue(BigDecimal theValue) { - clearHashes(); myValue = theValue; return this; } @@ -228,9 +222,9 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc HashCodeBuilder b = new HashCodeBuilder(); b.append(getResourceType()); b.append(getParamName()); - b.append(getSystem()); - b.append(getUnits()); - b.append(getValue()); + b.append(getHashIdentity()); + b.append(getHashIdentityAndUnits()); + b.append(getHashIdentitySystemAndUnits()); return b.toHashCode(); } diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamString.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamString.java index 2cf23b8abe9..b930e1a4875 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamString.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamString.java @@ -37,7 +37,19 @@ import org.hibernate.search.annotations.Fields; import org.hibernate.search.annotations.Indexed; import org.hibernate.search.annotations.Store; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.Entity; +import javax.persistence.ForeignKey; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.Transient; import static org.apache.commons.lang3.StringUtils.defaultString; import static org.apache.commons.lang3.StringUtils.left; @@ -121,6 +133,7 @@ public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchP setParamName(theParamName); setValueNormalized(theValueNormalized); setValueExact(theValueExact); + calculateHashes(); } @Override @@ -135,25 +148,14 @@ public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchP } @Override - @PrePersist - @PreUpdate public void calculateHashes() { - if ((myHashIdentity == null || myHashNormalizedPrefix == null || myHashExact == null) && getParamName() != null) { - String resourceType = getResourceType(); - String paramName = getParamName(); - String valueNormalized = getValueNormalized(); - String valueExact = getValueExact(); - setHashNormalizedPrefix(calculateHashNormalized(getPartitionSettings(), getPartitionId(), myModelConfig, resourceType, paramName, valueNormalized)); - setHashExact(calculateHashExact(getPartitionSettings(), getPartitionId(), resourceType, paramName, valueExact)); - setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); - } - } - - @Override - protected void clearHashes() { - myHashNormalizedPrefix = null; - myHashExact = null; - myHashIdentity = null; + String resourceType = getResourceType(); + String paramName = getParamName(); + String valueNormalized = getValueNormalized(); + String valueExact = getValueExact(); + setHashNormalizedPrefix(calculateHashNormalized(getPartitionSettings(), getPartitionId(), myModelConfig, resourceType, paramName, valueNormalized)); + setHashExact(calculateHashExact(getPartitionSettings(), getPartitionId(), resourceType, paramName, valueExact)); + setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); } @Override @@ -179,7 +181,6 @@ public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchP } private Long getHashIdentity() { - calculateHashes(); return myHashIdentity; } @@ -188,7 +189,6 @@ public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchP } public Long getHashExact() { - calculateHashes(); return myHashExact; } @@ -197,7 +197,6 @@ public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchP } public Long getHashNormalizedPrefix() { - calculateHashes(); return myHashNormalizedPrefix; } diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamToken.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamToken.java index ba9b49d07e6..b69edb12fa0 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamToken.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamToken.java @@ -31,7 +31,15 @@ import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import org.hibernate.search.annotations.Field; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; import static org.apache.commons.lang3.StringUtils.defaultString; import static org.apache.commons.lang3.StringUtils.trim; @@ -110,6 +118,7 @@ public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchPa setParamName(theParamName); setSystem(theSystem); setValue(theValue); + calculateHashes(); } @Override @@ -127,25 +136,15 @@ public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchPa @Override - @PrePersist public void calculateHashes() { - if (myHashSystem == null && getParamName() != null) { - String resourceType = getResourceType(); - String paramName = getParamName(); - String system = getSystem(); - String value = getValue(); - setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); - setHashSystem(calculateHashSystem(getPartitionSettings(), getPartitionId(), resourceType, paramName, system)); - setHashSystemAndValue(calculateHashSystemAndValue(getPartitionSettings(), getPartitionId(), resourceType, paramName, system, value)); - setHashValue(calculateHashValue(getPartitionSettings(), getPartitionId(), resourceType, paramName, value)); - } - } - - @Override - protected void clearHashes() { - myHashSystem = null; - myHashSystemAndValue = null; - myHashValue = null; + String resourceType = getResourceType(); + String paramName = getParamName(); + String system = getSystem(); + String value = getValue(); + setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); + setHashSystem(calculateHashSystem(getPartitionSettings(), getPartitionId(), resourceType, paramName, system)); + setHashSystemAndValue(calculateHashSystemAndValue(getPartitionSettings(), getPartitionId(), resourceType, paramName, system, value)); + setHashValue(calculateHashValue(getPartitionSettings(), getPartitionId(), resourceType, paramName, value)); } @Override @@ -161,15 +160,13 @@ public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchPa } ResourceIndexedSearchParamToken obj = (ResourceIndexedSearchParamToken) theObj; EqualsBuilder b = new EqualsBuilder(); - b.append(getResourceType(), obj.getResourceType()); - b.append(getParamName(), obj.getParamName()); - b.append(getSystem(), obj.getSystem()); - b.append(getValue(), obj.getValue()); + b.append(getHashSystem(), obj.getHashSystem()); + b.append(getHashValue(), obj.getHashValue()); + b.append(getHashSystemAndValue(), obj.getHashSystemAndValue()); return b.isEquals(); } Long getHashSystem() { - calculateHashes(); return myHashSystem; } @@ -182,17 +179,14 @@ public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchPa } Long getHashSystemAndValue() { - calculateHashes(); return myHashSystemAndValue; } private void setHashSystemAndValue(Long theHashSystemAndValue) { - calculateHashes(); myHashSystemAndValue = theHashSystemAndValue; } Long getHashValue() { - calculateHashes(); return myHashValue; } @@ -215,7 +209,6 @@ public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchPa } public void setSystem(String theSystem) { - clearHashes(); mySystem = StringUtils.defaultIfBlank(theSystem, null); } @@ -224,19 +217,17 @@ public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchPa } public ResourceIndexedSearchParamToken setValue(String theValue) { - clearHashes(); myValue = StringUtils.defaultIfBlank(theValue, null); return this; } @Override public int hashCode() { - calculateHashes(); HashCodeBuilder b = new HashCodeBuilder(); b.append(getResourceType()); - b.append(getParamName()); - b.append(getSystem()); - b.append(getValue()); + b.append(getHashValue()); + b.append(getHashSystem()); + b.append(getHashSystemAndValue()); return b.toHashCode(); } diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamUri.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamUri.java index 29fc1ff91fb..745d0ede7cb 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamUri.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamUri.java @@ -30,7 +30,15 @@ import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; import org.hibernate.search.annotations.Field; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; import static org.apache.commons.lang3.StringUtils.defaultString; @@ -87,6 +95,7 @@ public class ResourceIndexedSearchParamUri extends BaseResourceIndexedSearchPara setResourceType(theResourceType); setParamName(theParamName); setUri(theUri); + calculateHashes(); } @Override @@ -100,20 +109,12 @@ public class ResourceIndexedSearchParamUri extends BaseResourceIndexedSearchPara @Override - @PrePersist public void calculateHashes() { - if (myHashUri == null && getParamName() != null) { - String resourceType = getResourceType(); - String paramName = getParamName(); - String uri = getUri(); - setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); - setHashUri(calculateHashUri(getPartitionSettings(), getPartitionId(), resourceType, paramName, uri)); - } - } - - @Override - protected void clearHashes() { - myHashUri = null; + String resourceType = getResourceType(); + String paramName = getParamName(); + String uri = getUri(); + setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); + setHashUri(calculateHashUri(getPartitionSettings(), getPartitionId(), resourceType, paramName, uri)); } @Override @@ -138,7 +139,6 @@ public class ResourceIndexedSearchParamUri extends BaseResourceIndexedSearchPara } private Long getHashIdentity() { - calculateHashes(); return myHashIdentity; } @@ -147,7 +147,6 @@ public class ResourceIndexedSearchParamUri extends BaseResourceIndexedSearchPara } public Long getHashUri() { - calculateHashes(); return myHashUri; } @@ -182,6 +181,7 @@ public class ResourceIndexedSearchParamUri extends BaseResourceIndexedSearchPara b.append(getParamName()); b.append(getUri()); b.append(getHashUri()); + b.append(getHashIdentity()); return b.toHashCode(); } diff --git a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamQuantityTest.java b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamQuantityTest.java index 8c20f544833..1e1fda3fd2c 100644 --- a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamQuantityTest.java +++ b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamQuantityTest.java @@ -19,6 +19,7 @@ public class ResourceIndexedSearchParamQuantityTest { @Test public void testHashFunctions() { ResourceIndexedSearchParamQuantity token = createParam("NAME", "123.001", "value", "VALUE"); + token.calculateHashes(); // Make sure our hashing function gives consistent results assertEquals(834432764963581074L, token.getHashIdentity().longValue()); diff --git a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamStringTest.java b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamStringTest.java index ff07d7c6999..0db843825fb 100644 --- a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamStringTest.java +++ b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamStringTest.java @@ -13,6 +13,7 @@ public class ResourceIndexedSearchParamStringTest { public void testHashFunctions() { ResourceIndexedSearchParamString token = new ResourceIndexedSearchParamString(new PartitionSettings(), new ModelConfig(), "Patient", "NAME", "value", "VALUE"); token.setResource(new ResourceTable().setResourceType("Patient")); + token.calculateHashes(); // Make sure our hashing function gives consistent results assertEquals(6598082761639188617L, token.getHashNormalizedPrefix().longValue()); @@ -23,6 +24,7 @@ public class ResourceIndexedSearchParamStringTest { public void testHashFunctionsPrefixOnly() { ResourceIndexedSearchParamString token = new ResourceIndexedSearchParamString(new PartitionSettings(), new ModelConfig(), "Patient", "NAME", "vZZZZZZZZZZZZZZZZ", "VZZZZZZzzzZzzzZ"); token.setResource(new ResourceTable().setResourceType("Patient")); + token.calculateHashes(); // Should be the same as in testHashFunctions() assertEquals(6598082761639188617L, token.getHashNormalizedPrefix().longValue()); @@ -38,11 +40,13 @@ public class ResourceIndexedSearchParamStringTest { .setValueExact("aaa") .setValueNormalized("AAA"); val1.setPartitionSettings(new PartitionSettings()); + val1.setModelConfig(new ModelConfig()); val1.calculateHashes(); ResourceIndexedSearchParamString val2 = new ResourceIndexedSearchParamString() .setValueExact("aaa") .setValueNormalized("AAA"); val2.setPartitionSettings(new PartitionSettings()); + val2.setModelConfig(new ModelConfig()); val2.calculateHashes(); assertEquals(val1, val1); assertEquals(val1, val2); @@ -56,11 +60,13 @@ public class ResourceIndexedSearchParamStringTest { .setValueExact("aaa") .setValueNormalized("AAA"); val1.setPartitionSettings(new PartitionSettings().setIncludePartitionInSearchHashes(true)); + val1.setModelConfig(new ModelConfig()); val1.calculateHashes(); ResourceIndexedSearchParamString val2 = new ResourceIndexedSearchParamString() .setValueExact("aaa") .setValueNormalized("AAA"); val2.setPartitionSettings(new PartitionSettings().setIncludePartitionInSearchHashes(true)); + val2.setModelConfig(new ModelConfig()); val2.calculateHashes(); assertEquals(val1, val1); assertEquals(val1, val2); diff --git a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamTokenTest.java b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamTokenTest.java index 7bd2113deae..ae5e6151a1d 100644 --- a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamTokenTest.java +++ b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamTokenTest.java @@ -12,6 +12,7 @@ public class ResourceIndexedSearchParamTokenTest { public void testHashFunctions() { ResourceIndexedSearchParamToken token = new ResourceIndexedSearchParamToken(new PartitionSettings(), "Patient", "NAME", "SYSTEM", "VALUE"); token.setResource(new ResourceTable().setResourceType("Patient")); + token.calculateHashes(); // Make sure our hashing function gives consistent results assertEquals(-8558989679010582575L, token.getHashSystem().longValue()); @@ -23,6 +24,7 @@ public class ResourceIndexedSearchParamTokenTest { public void testHashFunctionsWithOverlapNames() { ResourceIndexedSearchParamToken token = new ResourceIndexedSearchParamToken(new PartitionSettings(), "Patient", "NAME", "SYSTEM", "VALUE"); token.setResource(new ResourceTable().setResourceType("Patient")); + token.calculateHashes(); // Make sure our hashing function gives consistent results assertEquals(-8558989679010582575L, token.getHashSystem().longValue()); diff --git a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamUriTest.java b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamUriTest.java index 1aadd00dfe4..8147135b367 100644 --- a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamUriTest.java +++ b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamUriTest.java @@ -12,6 +12,7 @@ public class ResourceIndexedSearchParamUriTest { public void testHashFunctions() { ResourceIndexedSearchParamUri token = new ResourceIndexedSearchParamUri(new PartitionSettings(), "Patient", "NAME", "http://example.com"); token.setResource(new ResourceTable().setResourceType("Patient")); + token.calculateHashes(); // Make sure our hashing function gives consistent results assertEquals(-6132951326739875838L, token.getHashUri().longValue()); diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/BaseSearchParamExtractor.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/BaseSearchParamExtractor.java index 355ebf37bec..1414eeb6272 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/BaseSearchParamExtractor.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/BaseSearchParamExtractor.java @@ -141,9 +141,11 @@ public abstract class BaseSearchParamExtractor implements ISearchParamExtractor /** * UNIT TEST constructor */ - BaseSearchParamExtractor(FhirContext theCtx, ISearchParamRegistry theSearchParamRegistry) { + BaseSearchParamExtractor(FhirContext theCtx, ISearchParamRegistry theSearchParamRegistry, ModelConfig theModelConfig, PartitionSettings thePartitionSettings) { myContext = theCtx; mySearchParamRegistry = theSearchParamRegistry; + myPartitionSettings = thePartitionSettings; + myModelConfig = theModelConfig; } @VisibleForTesting diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/ResourceIndexedSearchParams.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/ResourceIndexedSearchParams.java index 05df1aaef70..2f8af038d57 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/ResourceIndexedSearchParams.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/ResourceIndexedSearchParams.java @@ -130,12 +130,6 @@ public final class ResourceIndexedSearchParams { } } - public void calculateHashes(Collection theStringParams) { - for (BaseResourceIndex next : theStringParams) { - next.calculateHashes(); - } - } - public Set getPopulatedResourceLinkParameters() { return myPopulatedResourceLinkParameters; } @@ -305,6 +299,7 @@ public final class ResourceIndexedSearchParams { param.setResource(theEntity); param.setMissing(true); param.setParamName(nextParamName); + param.calculateHashes(); paramCollection.add((RT) param); } } diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorDstu2.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorDstu2.java index 8c2b46f837e..82a31d10f40 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorDstu2.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorDstu2.java @@ -21,6 +21,8 @@ package ca.uhn.fhir.jpa.searchparam.extractor; */ import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.model.config.PartitionSettings; +import ca.uhn.fhir.jpa.model.entity.ModelConfig; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; import ca.uhn.fhir.model.dstu2.composite.ContactPointDt; import ca.uhn.fhir.util.FhirTerser; @@ -40,8 +42,8 @@ public class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implemen /** * Constructor for unit tests */ - SearchParamExtractorDstu2(FhirContext theCtx, ISearchParamRegistry theSearchParamRegistry) { - super(theCtx, theSearchParamRegistry); + SearchParamExtractorDstu2(FhirContext theCtx, ISearchParamRegistry theSearchParamRegistry, ModelConfig theModelConfig, PartitionSettings thePartitionSettings) { + super(theCtx, theSearchParamRegistry, theModelConfig, thePartitionSettings); start(); } diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorDstu3.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorDstu3.java index 79a7de05c92..f2d0ff05a65 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorDstu3.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorDstu3.java @@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.searchparam.extractor; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.support.IValidationSupport; +import ca.uhn.fhir.jpa.model.config.PartitionSettings; import ca.uhn.fhir.jpa.model.entity.ModelConfig; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; import com.google.common.annotations.VisibleForTesting; @@ -49,8 +50,8 @@ public class SearchParamExtractorDstu3 extends BaseSearchParamExtractor implemen // This constructor is used by tests @VisibleForTesting - public SearchParamExtractorDstu3(ModelConfig theModelConfig, FhirContext theCtx, IValidationSupport theValidationSupport, ISearchParamRegistry theSearchParamRegistry) { - super(theCtx, theSearchParamRegistry); + public SearchParamExtractorDstu3(ModelConfig theModelConfig, FhirContext theCtx, IValidationSupport theValidationSupport, ISearchParamRegistry theSearchParamRegistry, PartitionSettings thePartitionSettings) { + super(theCtx, theSearchParamRegistry, theModelConfig, thePartitionSettings); initFhirPathEngine(theValidationSupport); start(); } diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorR4.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorR4.java index f7d216ee66a..6b501bc2d13 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorR4.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorR4.java @@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.searchparam.extractor; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.support.IValidationSupport; +import ca.uhn.fhir.jpa.model.config.PartitionSettings; import ca.uhn.fhir.jpa.model.entity.ModelConfig; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; import com.google.common.annotations.VisibleForTesting; @@ -61,8 +62,8 @@ public class SearchParamExtractorR4 extends BaseSearchParamExtractor implements // This constructor is used by tests @VisibleForTesting - public SearchParamExtractorR4(ModelConfig theModelConfig, FhirContext theCtx, IValidationSupport theValidationSupport, ISearchParamRegistry theSearchParamRegistry) { - super(theCtx, theSearchParamRegistry); + public SearchParamExtractorR4(ModelConfig theModelConfig, FhirContext theCtx, IValidationSupport theValidationSupport, ISearchParamRegistry theSearchParamRegistry, PartitionSettings thePartitionSettings) { + super(theCtx, theSearchParamRegistry,theModelConfig, thePartitionSettings); initFhirPath(theValidationSupport); start(); } diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorR5.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorR5.java index b882db0f4a5..3aa0132dfc7 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorR5.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorR5.java @@ -23,6 +23,8 @@ package ca.uhn.fhir.jpa.searchparam.extractor; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; import ca.uhn.fhir.context.support.IValidationSupport; +import ca.uhn.fhir.jpa.model.config.PartitionSettings; +import ca.uhn.fhir.jpa.model.entity.ModelConfig; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.PathEngineException; @@ -56,8 +58,8 @@ public class SearchParamExtractorR5 extends BaseSearchParamExtractor implements /** * Constructor for unit tests */ - public SearchParamExtractorR5(FhirContext theCtx, DefaultProfileValidationSupport theDefaultProfileValidationSupport, ISearchParamRegistry theSearchParamRegistry) { - super(theCtx, theSearchParamRegistry); + public SearchParamExtractorR5(FhirContext theCtx, DefaultProfileValidationSupport theDefaultProfileValidationSupport, ISearchParamRegistry theSearchParamRegistry, ModelConfig theModelConfig, PartitionSettings thePartitionSettings) { + super(theCtx, theSearchParamRegistry, theModelConfig, thePartitionSettings); initFhirPath(theDefaultProfileValidationSupport); start(); } diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/IndexStressTest.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/IndexStressTest.java index c440243e102..d59aa3f645f 100644 --- a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/IndexStressTest.java +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/IndexStressTest.java @@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.searchparam; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.context.support.IValidationSupport; +import ca.uhn.fhir.jpa.model.config.PartitionSettings; import ca.uhn.fhir.jpa.model.entity.ModelConfig; import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamString; import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorDstu3; @@ -44,7 +45,7 @@ public class IndexStressTest { when(mockValidationSupport.getFhirContext()).thenReturn(ctx); IValidationSupport validationSupport = new CachingValidationSupport(new ValidationSupportChain(new DefaultProfileValidationSupport(ctx), mockValidationSupport)); ISearchParamRegistry searchParamRegistry = mock(ISearchParamRegistry.class); - SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ctx, validationSupport, searchParamRegistry); + SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ctx, validationSupport, searchParamRegistry, new PartitionSettings()); extractor.start(); Map spMap = ctx diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorDstu3Test.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorDstu3Test.java index 6a05e7c9280..eba841d870a 100644 --- a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorDstu3Test.java +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorDstu3Test.java @@ -58,7 +58,7 @@ public class SearchParamExtractorDstu3Test { ISearchParamRegistry searchParamRegistry = new MySearchParamRegistry(); - SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry); + SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry, new PartitionSettings()); extractor.setPartitionConfigForUnitTest(new PartitionSettings()); extractor.start(); Set tokens = extractor.extractSearchParamTokens(obs); @@ -82,7 +82,7 @@ public class SearchParamExtractorDstu3Test { ISearchParamRegistry searchParamRegistry = new MySearchParamRegistry(); - SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry); + SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry, new PartitionSettings()); extractor.start(); Set params = extractor.extractSearchParamStrings(questionnaire); assertEquals(1, params.size()); @@ -100,7 +100,7 @@ public class SearchParamExtractorDstu3Test { ISearchParamRegistry searchParamRegistry = new MySearchParamRegistry(); - SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry); + SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry, new PartitionSettings()); extractor.start(); Set params = extractor.extractSearchParamNumber(enc); assertEquals(1, params.size()); @@ -118,7 +118,7 @@ public class SearchParamExtractorDstu3Test { ISearchParamRegistry searchParamRegistry = new MySearchParamRegistry(); - SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry); + SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry, new PartitionSettings()); extractor.start(); Set params = extractor.extractSearchParamNumber(enc); assertEquals(1, params.size()); @@ -130,7 +130,7 @@ public class SearchParamExtractorDstu3Test { public void testEmptyPath() { MySearchParamRegistry searchParamRegistry = new MySearchParamRegistry(); - SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry); + SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry, new PartitionSettings()); extractor.start(); searchParamRegistry.addSearchParam(new RuntimeSearchParam("foo", "foo", "", RestSearchParameterTypeEnum.STRING, Sets.newHashSet(), Sets.newHashSet(), RuntimeSearchParam.RuntimeSearchParamStatusEnum.ACTIVE)); @@ -146,7 +146,7 @@ public class SearchParamExtractorDstu3Test { public void testStringMissingResourceType() { MySearchParamRegistry searchParamRegistry = new MySearchParamRegistry(); - SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry); + SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry, new PartitionSettings()); extractor.start(); searchParamRegistry.addSearchParam(new RuntimeSearchParam("foo", "foo", "communication.language.coding.system | communication.language.coding.code", RestSearchParameterTypeEnum.STRING, Sets.newHashSet(), Sets.newHashSet(), RuntimeSearchParam.RuntimeSearchParamStatusEnum.ACTIVE)); @@ -163,7 +163,7 @@ public class SearchParamExtractorDstu3Test { public void testInvalidType() { MySearchParamRegistry searchParamRegistry = new MySearchParamRegistry(); - SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry); + SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry, new PartitionSettings()); extractor.setPartitionConfigForUnitTest(new PartitionSettings()); extractor.start(); @@ -215,7 +215,7 @@ public class SearchParamExtractorDstu3Test { ISearchParamRegistry searchParamRegistry = new MySearchParamRegistry(); - SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry); + SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry, new PartitionSettings()); extractor.start(); ISearchParamExtractor.SearchParamSet coords = extractor.extractSearchParamTokens(loc); assertEquals(1, coords.size()); diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorMegaTest.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorMegaTest.java index e29972743c1..77f6d57db05 100644 --- a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorMegaTest.java +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorMegaTest.java @@ -2,6 +2,7 @@ package ca.uhn.fhir.jpa.searchparam.extractor; import ca.uhn.fhir.context.*; import ca.uhn.fhir.jpa.model.config.PartitionSettings; +import ca.uhn.fhir.jpa.model.entity.ModelConfig; import ca.uhn.fhir.jpa.searchparam.JpaRuntimeSearchParam; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; @@ -39,19 +40,19 @@ public class SearchParamExtractorMegaTest { FhirContext ctx = FhirContext.forDstu2(); ISearchParamRegistry searchParamRegistry = new MySearchParamRegistry(ctx); - process(ctx, new SearchParamExtractorDstu2(ctx, searchParamRegistry).setPartitionConfigForUnitTest(new PartitionSettings())); + process(ctx, new SearchParamExtractorDstu2(ctx, searchParamRegistry, new ModelConfig(), new PartitionSettings()).setPartitionConfigForUnitTest(new PartitionSettings())); ctx = FhirContext.forDstu3(); searchParamRegistry = new MySearchParamRegistry(ctx); - process(ctx, new SearchParamExtractorDstu3(null, ctx, new DefaultProfileValidationSupport(ctx), searchParamRegistry).setPartitionConfigForUnitTest(new PartitionSettings())); + process(ctx, new SearchParamExtractorDstu3(new ModelConfig(), ctx, new DefaultProfileValidationSupport(ctx), searchParamRegistry, new PartitionSettings()).setPartitionConfigForUnitTest(new PartitionSettings())); ctx = FhirContext.forR4(); searchParamRegistry = new MySearchParamRegistry(ctx); - process(ctx, new SearchParamExtractorR4(null, ctx, new DefaultProfileValidationSupport(ctx), searchParamRegistry).setPartitionConfigForUnitTest(new PartitionSettings())); + process(ctx, new SearchParamExtractorR4(new ModelConfig(), ctx, new DefaultProfileValidationSupport(ctx), searchParamRegistry, new PartitionSettings()).setPartitionConfigForUnitTest(new PartitionSettings())); ctx = FhirContext.forR5(); searchParamRegistry = new MySearchParamRegistry(ctx); - process(ctx, new SearchParamExtractorR5(ctx, new DefaultProfileValidationSupport(ctx), searchParamRegistry).setPartitionConfigForUnitTest(new PartitionSettings())); + process(ctx, new SearchParamExtractorR5(ctx, new DefaultProfileValidationSupport(ctx), searchParamRegistry, new ModelConfig(), new PartitionSettings()).setPartitionConfigForUnitTest(new PartitionSettings())); } private void process(FhirContext theCtx, BaseSearchParamExtractor theExtractor) throws Exception {