Clean up hash code calculation (#1830)

* Clean up hash code calculation

* Test fixes

* Test fix

* Test fixes

* Compile fix

* Test fix
This commit is contained in:
James Agnew 2020-05-05 11:11:24 -04:00 committed by GitHub
parent 91147cf6b0
commit dada217966
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 227 additions and 193 deletions

View File

@ -61,17 +61,19 @@ public class DaoSearchParamSynchronizer {
} }
private <T extends BaseResourceIndex> void synchronize(ResourceIndexedSearchParams theParams, ResourceTable theEntity, AddRemoveCount theAddRemoveCount, Collection<T> theNewParms, Collection<T> theExistingParms) { private <T extends BaseResourceIndex> void synchronize(ResourceIndexedSearchParams theParams, ResourceTable theEntity, AddRemoveCount theAddRemoveCount, Collection<T> theNewParms, Collection<T> theExistingParms) {
for (T next : theNewParms) {
next.setPartitionId(theEntity.getPartitionId());
next.calculateHashes();
}
List<T> quantitiesToRemove = subtract(theExistingParms, theNewParms); List<T> quantitiesToRemove = subtract(theExistingParms, theNewParms);
List<T> quantitiesToAdd = subtract(theNewParms, theExistingParms); List<T> quantitiesToAdd = subtract(theNewParms, theExistingParms);
tryToReuseIndexEntities(quantitiesToRemove, quantitiesToAdd); tryToReuseIndexEntities(quantitiesToRemove, quantitiesToAdd);
for (T next : quantitiesToRemove) { for (T next : quantitiesToRemove) {
myEntityManager.remove(next); myEntityManager.remove(next);
theEntity.getParamsQuantity().remove(next); theEntity.getParamsQuantity().remove(next);
} }
for (T next : quantitiesToAdd) {
next.setPartitionId(theEntity.getPartitionId());
}
theParams.calculateHashes(theNewParms);
for (T next : quantitiesToAdd) { for (T next : quantitiesToAdd) {
myEntityManager.merge(next); myEntityManager.merge(next);
} }

View File

@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.dao.r4;
import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.model.cross.ResourcePersistentId; import ca.uhn.fhir.jpa.model.cross.ResourcePersistentId;
import ca.uhn.fhir.jpa.model.entity.ResourceHistoryTable; 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.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.jpa.util.TestUtil; 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 @Test
public void testUpdateNotModifiedDoesNotAffectDates() { public void testUpdateNotModifiedDoesNotAffectDates() {

View File

@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.dao.r4;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.context.support.DefaultProfileValidationSupport;
import ca.uhn.fhir.context.support.IValidationSupport; import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.jpa.model.config.PartitionSettings; import ca.uhn.fhir.jpa.model.config.PartitionSettings;
import ca.uhn.fhir.jpa.model.entity.BaseResourceIndexedSearchParam; 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.rest.api.RestSearchParameterTypeEnum;
import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.TestUtil;
import com.google.common.collect.Sets; 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.CodeableConcept;
import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.Consent; import org.hl7.fhir.r4.model.Consent;
@ -65,7 +65,7 @@ public class SearchParamExtractorR4Test {
Observation obs = new Observation(); Observation obs = new Observation();
obs.addCategory().addCoding().setSystem("SYSTEM").setCode("CODE"); 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()); extractor.setPartitionConfigForUnitTest(new PartitionSettings());
Set<BaseResourceIndexedSearchParam> tokens = extractor.extractSearchParamTokens(obs); Set<BaseResourceIndexedSearchParam> tokens = extractor.extractSearchParamTokens(obs);
assertEquals(1, tokens.size()); assertEquals(1, tokens.size());
@ -80,7 +80,7 @@ public class SearchParamExtractorR4Test {
SearchParameter sp = new SearchParameter(); SearchParameter sp = new SearchParameter();
sp.addUseContext().setCode(new Coding().setSystem("http://system").setCode("code")); 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()); extractor.setPartitionConfigForUnitTest(new PartitionSettings());
Set<BaseResourceIndexedSearchParam> tokens = extractor.extractSearchParamTokens(sp); Set<BaseResourceIndexedSearchParam> tokens = extractor.extractSearchParamTokens(sp);
assertEquals(1, tokens.size()); assertEquals(1, tokens.size());
@ -95,7 +95,7 @@ public class SearchParamExtractorR4Test {
Encounter enc = new Encounter(); Encounter enc = new Encounter();
enc.addLocation().setLocation(new Reference("Location/123")); 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"); RuntimeSearchParam param = mySearchParamRegistry.getActiveSearchParam("Encounter", "location");
assertNotNull(param); assertNotNull(param);
ISearchParamExtractor.SearchParamSet<PathAndRef> links = extractor.extractResourceLinks(enc); ISearchParamExtractor.SearchParamSet<PathAndRef> links = extractor.extractResourceLinks(enc);
@ -110,7 +110,7 @@ public class SearchParamExtractorR4Test {
Consent consent = new Consent(); Consent consent = new Consent();
consent.setSource(new Reference().setReference("Consent/999")); 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()); extractor.setPartitionConfigForUnitTest(new PartitionSettings());
RuntimeSearchParam param = mySearchParamRegistry.getActiveSearchParam("Consent", Consent.SP_SOURCE_REFERENCE); RuntimeSearchParam param = mySearchParamRegistry.getActiveSearchParam("Consent", Consent.SP_SOURCE_REFERENCE);
assertNotNull(param); assertNotNull(param);
@ -126,7 +126,7 @@ public class SearchParamExtractorR4Test {
Patient p = new Patient(); Patient p = new Patient();
p.addIdentifier().setSystem("sys").setValue("val"); 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()); extractor.setPartitionConfigForUnitTest(new PartitionSettings());
RuntimeSearchParam param = mySearchParamRegistry.getActiveSearchParam("Patient", Patient.SP_IDENTIFIER); RuntimeSearchParam param = mySearchParamRegistry.getActiveSearchParam("Patient", Patient.SP_IDENTIFIER);
assertNotNull(param); assertNotNull(param);
@ -149,7 +149,7 @@ public class SearchParamExtractorR4Test {
Patient patient = new Patient(); Patient patient = new Patient();
patient.addExtension("http://patext", new Reference("Organization/AAA")); 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<PathAndRef> links = extractor.extractResourceLinks(patient); ISearchParamExtractor.SearchParamSet<PathAndRef> links = extractor.extractResourceLinks(patient);
assertEquals(1, links.size()); assertEquals(1, links.size());
@ -165,7 +165,7 @@ public class SearchParamExtractorR4Test {
.setCode(new CodeableConcept().addCoding(new Coding().setSystem("http://foo").setCode("code2"))) .setCode(new CodeableConcept().addCoding(new Coding().setSystem("http://foo").setCode("code2")))
.setValue(new Quantity().setSystem("http://bar").setCode("code2").setValue(200)); .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<ResourceIndexedSearchParamQuantity> links = extractor.extractSearchParamQuantity(o1); Set<ResourceIndexedSearchParamQuantity> links = extractor.extractSearchParamQuantity(o1);
ourLog.info("Links:\n {}", links.stream().map(t -> t.toString()).collect(Collectors.joining("\n "))); ourLog.info("Links:\n {}", links.stream().map(t -> t.toString()).collect(Collectors.joining("\n ")));
assertEquals(4, links.size()); assertEquals(4, links.size());

View File

@ -85,13 +85,6 @@ public abstract class BaseResourceIndexedSearchParam extends BaseResourceIndex {
@Transient @Transient
private transient PartitionSettings myPartitionSettings; private transient PartitionSettings myPartitionSettings;
/**
* Subclasses may override
*/
protected void clearHashes() {
// nothing
}
@Override @Override
public abstract Long getId(); public abstract Long getId();
@ -100,7 +93,6 @@ public abstract class BaseResourceIndexedSearchParam extends BaseResourceIndex {
} }
public void setParamName(String theName) { public void setParamName(String theName) {
clearHashes();
myParamName = theName; myParamName = theName;
} }
@ -109,7 +101,6 @@ public abstract class BaseResourceIndexedSearchParam extends BaseResourceIndex {
} }
public BaseResourceIndexedSearchParam setResource(ResourceTable theResource) { public BaseResourceIndexedSearchParam setResource(ResourceTable theResource) {
clearHashes();
myResource = theResource; myResource = theResource;
myResourceType = theResource.getResourceType(); myResourceType = theResource.getResourceType();
return this; return this;

View File

@ -28,7 +28,15 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.search.annotations.Field; 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 @Embeddable
@Entity @Entity
@ -68,21 +76,14 @@ public class ResourceIndexedSearchParamCoords extends BaseResourceIndexedSearchP
setParamName(theParamName); setParamName(theParamName);
setLatitude(theLatitude); setLatitude(theLatitude);
setLongitude(theLongitude); setLongitude(theLongitude);
calculateHashes();
} }
@Override @Override
@PrePersist
public void calculateHashes() { public void calculateHashes() {
if (myHashIdentity == null && getParamName() != null) { String resourceType = getResourceType();
String resourceType = getResourceType(); String paramName = getParamName();
String paramName = getParamName(); setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName));
setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName));
}
}
@Override
protected void clearHashes() {
myHashIdentity = null;
} }
@Override @Override
@ -126,7 +127,7 @@ public class ResourceIndexedSearchParamCoords extends BaseResourceIndexedSearchP
@Override @Override
public void setId(Long theId) { public void setId(Long theId) {
myId =theId; myId = theId;
} }

View File

@ -35,7 +35,18 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.search.annotations.Field; import org.hibernate.search.annotations.Field;
import org.hl7.fhir.r4.model.DateTimeType; 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; import java.util.Date;
@Embeddable @Embeddable
@ -62,9 +73,9 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar
* Field which stores an integer representation of YYYYMDD as calculated by Calendar * Field which stores an integer representation of YYYYMDD as calculated by Calendar
* e.g. 2019-01-20 -> 20190120 * e.g. 2019-01-20 -> 20190120
*/ */
@Column(name="SP_VALUE_LOW_DATE_ORDINAL") @Column(name = "SP_VALUE_LOW_DATE_ORDINAL")
public Integer myValueLowDateOrdinal; public Integer myValueLowDateOrdinal;
@Column(name="SP_VALUE_HIGH_DATE_ORDINAL") @Column(name = "SP_VALUE_HIGH_DATE_ORDINAL")
public Integer myValueHighDateOrdinal; public Integer myValueHighDateOrdinal;
@Transient @Transient
@ -105,6 +116,7 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar
computeValueHighDateOrdinal(theHighString); computeValueHighDateOrdinal(theHighString);
computeValueLowDateOrdinal(theLowString); computeValueLowDateOrdinal(theLowString);
myOriginalValue = theOriginalValue; myOriginalValue = theOriginalValue;
calculateHashes();
} }
private void computeValueHighDateOrdinal(String theHigh) { private void computeValueHighDateOrdinal(String theHigh) {
@ -112,7 +124,8 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar
this.myValueHighDateOrdinal = generateOrdinalDateInteger(theHigh); this.myValueHighDateOrdinal = generateOrdinalDateInteger(theHigh);
} }
} }
private int generateOrdinalDateInteger(String theDateString){
private int generateOrdinalDateInteger(String theDateString) {
if (theDateString.contains("T")) { if (theDateString.contains("T")) {
theDateString = theDateString.substring(0, theDateString.indexOf("T")); theDateString = theDateString.substring(0, theDateString.indexOf("T"));
} }
@ -146,18 +159,10 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar
} }
@Override @Override
@PrePersist
public void calculateHashes() { public void calculateHashes() {
if (myHashIdentity == null && getParamName() != null) { String resourceType = getResourceType();
String resourceType = getResourceType(); String paramName = getParamName();
String paramName = getParamName(); setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName));
setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName));
}
}
@Override
protected void clearHashes() {
myHashIdentity = null;
} }
@Override @Override
@ -192,7 +197,7 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar
@Override @Override
public void setId(Long theId) { public void setId(Long theId) {
myId =theId; myId = theId;
} }
protected Long getTimeFromDate(Date date) { protected Long getTimeFromDate(Date date) {
@ -260,14 +265,12 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar
DateRangeParam range = new DateRangeParam(dateParam); DateRangeParam range = new DateRangeParam(dateParam);
boolean result; boolean result;
if (theUseOrdinalDatesForDayComparison) { if (theUseOrdinalDatesForDayComparison) {
result = matchesOrdinalDateBounds(range); result = matchesOrdinalDateBounds(range);
result = matchesDateBounds(range); result = matchesDateBounds(range);
} else { } else {
result = matchesDateBounds(range); result = matchesDateBounds(range);
} }
return result; return result;

View File

@ -32,7 +32,15 @@ import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.FieldBridge; import org.hibernate.search.annotations.FieldBridge;
import org.hibernate.search.annotations.NumericField; 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.math.BigDecimal;
import java.util.Objects; import java.util.Objects;
@ -71,6 +79,7 @@ public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchP
setResourceType(theResourceType); setResourceType(theResourceType);
setParamName(theParamName); setParamName(theParamName);
setValue(theValue); setValue(theValue);
calculateHashes();
} }
@Override @Override
@ -83,18 +92,14 @@ public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchP
@Override @Override
@PrePersist
public void calculateHashes() { public void calculateHashes() {
if (myHashIdentity == null && getParamName() != null) { String resourceType = getResourceType();
String resourceType = getResourceType(); String paramName = getParamName();
String paramName = getParamName(); setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName));
setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName));
}
} }
@Override public Long getHashIdentity() {
protected void clearHashes() { return myHashIdentity;
myHashIdentity = null;
} }
@Override @Override
@ -112,7 +117,7 @@ public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchP
EqualsBuilder b = new EqualsBuilder(); EqualsBuilder b = new EqualsBuilder();
b.append(getResourceType(), obj.getResourceType()); b.append(getResourceType(), obj.getResourceType());
b.append(getParamName(), obj.getParamName()); b.append(getParamName(), obj.getParamName());
b.append(getValue(), obj.getValue()); b.append(getHashIdentity(), obj.getHashIdentity());
b.append(isMissing(), obj.isMissing()); b.append(isMissing(), obj.isMissing());
return b.isEquals(); return b.isEquals();
} }
@ -128,7 +133,7 @@ public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchP
@Override @Override
public void setId(Long theId) { public void setId(Long theId) {
myId =theId; myId = theId;
} }
public BigDecimal getValue() { public BigDecimal getValue() {

View File

@ -33,7 +33,15 @@ import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.FieldBridge; import org.hibernate.search.annotations.FieldBridge;
import org.hibernate.search.annotations.NumericField; 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.math.BigDecimal;
import java.util.Objects; import java.util.Objects;
@ -101,6 +109,7 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc
setSystem(theSystem); setSystem(theSystem);
setValue(theValue); setValue(theValue);
setUnits(theUnits); setUnits(theUnits);
calculateHashes();
} }
@Override @Override
@ -117,23 +126,14 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc
@Override @Override
@PrePersist
public void calculateHashes() { public void calculateHashes() {
if (myHashIdentity == null && getParamName() != null) { String resourceType = getResourceType();
String resourceType = getResourceType(); String paramName = getParamName();
String paramName = getParamName(); String units = getUnits();
String units = getUnits(); String system = getSystem();
String system = getSystem(); setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName));
setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); setHashIdentityAndUnits(calculateHashUnits(getPartitionSettings(), getPartitionId(), resourceType, paramName, units));
setHashIdentityAndUnits(calculateHashUnits(getPartitionSettings(), getPartitionId(), resourceType, paramName, units)); setHashIdentitySystemAndUnits(calculateHashSystemAndUnits(getPartitionSettings(), getPartitionId(), resourceType, paramName, system, units));
setHashIdentitySystemAndUnits(calculateHashSystemAndUnits(getPartitionSettings(), getPartitionId(), resourceType, paramName, system, units));
}
}
@Override
protected void clearHashes() {
myHashIdentity = null;
myHashIdentityAndUnits = null;
} }
@Override @Override
@ -151,15 +151,14 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc
EqualsBuilder b = new EqualsBuilder(); EqualsBuilder b = new EqualsBuilder();
b.append(getResourceType(), obj.getResourceType()); b.append(getResourceType(), obj.getResourceType());
b.append(getParamName(), obj.getParamName()); b.append(getParamName(), obj.getParamName());
b.append(getSystem(), obj.getSystem()); b.append(getHashIdentity(), obj.getHashIdentity());
b.append(getUnits(), obj.getUnits()); b.append(getHashIdentityAndUnits(), obj.getHashIdentityAndUnits());
b.append(getValue(), obj.getValue()); b.append(getHashIdentitySystemAndUnits(), obj.getHashIdentitySystemAndUnits());
b.append(isMissing(), obj.isMissing()); b.append(isMissing(), obj.isMissing());
return b.isEquals(); return b.isEquals();
} }
public Long getHashIdentity() { public Long getHashIdentity() {
calculateHashes();
return myHashIdentity; return myHashIdentity;
} }
@ -168,7 +167,6 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc
} }
public Long getHashIdentityAndUnits() { public Long getHashIdentityAndUnits() {
calculateHashes();
return myHashIdentityAndUnits; return myHashIdentityAndUnits;
} }
@ -177,7 +175,6 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc
} }
private Long getHashIdentitySystemAndUnits() { private Long getHashIdentitySystemAndUnits() {
calculateHashes();
return myHashIdentitySystemAndUnits; return myHashIdentitySystemAndUnits;
} }
@ -200,7 +197,6 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc
} }
public void setSystem(String theSystem) { public void setSystem(String theSystem) {
clearHashes();
mySystem = theSystem; mySystem = theSystem;
} }
@ -209,7 +205,6 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc
} }
public void setUnits(String theUnits) { public void setUnits(String theUnits) {
clearHashes();
myUnits = theUnits; myUnits = theUnits;
} }
@ -218,7 +213,6 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc
} }
public ResourceIndexedSearchParamQuantity setValue(BigDecimal theValue) { public ResourceIndexedSearchParamQuantity setValue(BigDecimal theValue) {
clearHashes();
myValue = theValue; myValue = theValue;
return this; return this;
} }
@ -228,9 +222,9 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc
HashCodeBuilder b = new HashCodeBuilder(); HashCodeBuilder b = new HashCodeBuilder();
b.append(getResourceType()); b.append(getResourceType());
b.append(getParamName()); b.append(getParamName());
b.append(getSystem()); b.append(getHashIdentity());
b.append(getUnits()); b.append(getHashIdentityAndUnits());
b.append(getValue()); b.append(getHashIdentitySystemAndUnits());
return b.toHashCode(); return b.toHashCode();
} }

View File

@ -37,7 +37,19 @@ import org.hibernate.search.annotations.Fields;
import org.hibernate.search.annotations.Indexed; import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store; 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.defaultString;
import static org.apache.commons.lang3.StringUtils.left; import static org.apache.commons.lang3.StringUtils.left;
@ -121,6 +133,7 @@ public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchP
setParamName(theParamName); setParamName(theParamName);
setValueNormalized(theValueNormalized); setValueNormalized(theValueNormalized);
setValueExact(theValueExact); setValueExact(theValueExact);
calculateHashes();
} }
@Override @Override
@ -135,25 +148,14 @@ public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchP
} }
@Override @Override
@PrePersist
@PreUpdate
public void calculateHashes() { public void calculateHashes() {
if ((myHashIdentity == null || myHashNormalizedPrefix == null || myHashExact == null) && getParamName() != null) { String resourceType = getResourceType();
String resourceType = getResourceType(); String paramName = getParamName();
String paramName = getParamName(); String valueNormalized = getValueNormalized();
String valueNormalized = getValueNormalized(); String valueExact = getValueExact();
String valueExact = getValueExact(); setHashNormalizedPrefix(calculateHashNormalized(getPartitionSettings(), getPartitionId(), myModelConfig, resourceType, paramName, valueNormalized));
setHashNormalizedPrefix(calculateHashNormalized(getPartitionSettings(), getPartitionId(), myModelConfig, resourceType, paramName, valueNormalized)); setHashExact(calculateHashExact(getPartitionSettings(), getPartitionId(), resourceType, paramName, valueExact));
setHashExact(calculateHashExact(getPartitionSettings(), getPartitionId(), resourceType, paramName, valueExact)); setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName));
setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName));
}
}
@Override
protected void clearHashes() {
myHashNormalizedPrefix = null;
myHashExact = null;
myHashIdentity = null;
} }
@Override @Override
@ -179,7 +181,6 @@ public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchP
} }
private Long getHashIdentity() { private Long getHashIdentity() {
calculateHashes();
return myHashIdentity; return myHashIdentity;
} }
@ -188,7 +189,6 @@ public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchP
} }
public Long getHashExact() { public Long getHashExact() {
calculateHashes();
return myHashExact; return myHashExact;
} }
@ -197,7 +197,6 @@ public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchP
} }
public Long getHashNormalizedPrefix() { public Long getHashNormalizedPrefix() {
calculateHashes();
return myHashNormalizedPrefix; return myHashNormalizedPrefix;
} }

View File

@ -31,7 +31,15 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.search.annotations.Field; 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.defaultString;
import static org.apache.commons.lang3.StringUtils.trim; import static org.apache.commons.lang3.StringUtils.trim;
@ -110,6 +118,7 @@ public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchPa
setParamName(theParamName); setParamName(theParamName);
setSystem(theSystem); setSystem(theSystem);
setValue(theValue); setValue(theValue);
calculateHashes();
} }
@Override @Override
@ -127,25 +136,15 @@ public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchPa
@Override @Override
@PrePersist
public void calculateHashes() { public void calculateHashes() {
if (myHashSystem == null && getParamName() != null) { String resourceType = getResourceType();
String resourceType = getResourceType(); String paramName = getParamName();
String paramName = getParamName(); String system = getSystem();
String system = getSystem(); String value = getValue();
String value = getValue(); setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName));
setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); setHashSystem(calculateHashSystem(getPartitionSettings(), getPartitionId(), resourceType, paramName, system));
setHashSystem(calculateHashSystem(getPartitionSettings(), getPartitionId(), resourceType, paramName, system)); setHashSystemAndValue(calculateHashSystemAndValue(getPartitionSettings(), getPartitionId(), resourceType, paramName, system, value));
setHashSystemAndValue(calculateHashSystemAndValue(getPartitionSettings(), getPartitionId(), resourceType, paramName, system, value)); setHashValue(calculateHashValue(getPartitionSettings(), getPartitionId(), resourceType, paramName, value));
setHashValue(calculateHashValue(getPartitionSettings(), getPartitionId(), resourceType, paramName, value));
}
}
@Override
protected void clearHashes() {
myHashSystem = null;
myHashSystemAndValue = null;
myHashValue = null;
} }
@Override @Override
@ -161,15 +160,13 @@ public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchPa
} }
ResourceIndexedSearchParamToken obj = (ResourceIndexedSearchParamToken) theObj; ResourceIndexedSearchParamToken obj = (ResourceIndexedSearchParamToken) theObj;
EqualsBuilder b = new EqualsBuilder(); EqualsBuilder b = new EqualsBuilder();
b.append(getResourceType(), obj.getResourceType()); b.append(getHashSystem(), obj.getHashSystem());
b.append(getParamName(), obj.getParamName()); b.append(getHashValue(), obj.getHashValue());
b.append(getSystem(), obj.getSystem()); b.append(getHashSystemAndValue(), obj.getHashSystemAndValue());
b.append(getValue(), obj.getValue());
return b.isEquals(); return b.isEquals();
} }
Long getHashSystem() { Long getHashSystem() {
calculateHashes();
return myHashSystem; return myHashSystem;
} }
@ -182,17 +179,14 @@ public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchPa
} }
Long getHashSystemAndValue() { Long getHashSystemAndValue() {
calculateHashes();
return myHashSystemAndValue; return myHashSystemAndValue;
} }
private void setHashSystemAndValue(Long theHashSystemAndValue) { private void setHashSystemAndValue(Long theHashSystemAndValue) {
calculateHashes();
myHashSystemAndValue = theHashSystemAndValue; myHashSystemAndValue = theHashSystemAndValue;
} }
Long getHashValue() { Long getHashValue() {
calculateHashes();
return myHashValue; return myHashValue;
} }
@ -215,7 +209,6 @@ public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchPa
} }
public void setSystem(String theSystem) { public void setSystem(String theSystem) {
clearHashes();
mySystem = StringUtils.defaultIfBlank(theSystem, null); mySystem = StringUtils.defaultIfBlank(theSystem, null);
} }
@ -224,19 +217,17 @@ public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchPa
} }
public ResourceIndexedSearchParamToken setValue(String theValue) { public ResourceIndexedSearchParamToken setValue(String theValue) {
clearHashes();
myValue = StringUtils.defaultIfBlank(theValue, null); myValue = StringUtils.defaultIfBlank(theValue, null);
return this; return this;
} }
@Override @Override
public int hashCode() { public int hashCode() {
calculateHashes();
HashCodeBuilder b = new HashCodeBuilder(); HashCodeBuilder b = new HashCodeBuilder();
b.append(getResourceType()); b.append(getResourceType());
b.append(getParamName()); b.append(getHashValue());
b.append(getSystem()); b.append(getHashSystem());
b.append(getValue()); b.append(getHashSystemAndValue());
return b.toHashCode(); return b.toHashCode();
} }

View File

@ -30,7 +30,15 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.search.annotations.Field; 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.defaultString;
@ -87,6 +95,7 @@ public class ResourceIndexedSearchParamUri extends BaseResourceIndexedSearchPara
setResourceType(theResourceType); setResourceType(theResourceType);
setParamName(theParamName); setParamName(theParamName);
setUri(theUri); setUri(theUri);
calculateHashes();
} }
@Override @Override
@ -100,20 +109,12 @@ public class ResourceIndexedSearchParamUri extends BaseResourceIndexedSearchPara
@Override @Override
@PrePersist
public void calculateHashes() { public void calculateHashes() {
if (myHashUri == null && getParamName() != null) { String resourceType = getResourceType();
String resourceType = getResourceType(); String paramName = getParamName();
String paramName = getParamName(); String uri = getUri();
String uri = getUri(); setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName));
setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); setHashUri(calculateHashUri(getPartitionSettings(), getPartitionId(), resourceType, paramName, uri));
setHashUri(calculateHashUri(getPartitionSettings(), getPartitionId(), resourceType, paramName, uri));
}
}
@Override
protected void clearHashes() {
myHashUri = null;
} }
@Override @Override
@ -138,7 +139,6 @@ public class ResourceIndexedSearchParamUri extends BaseResourceIndexedSearchPara
} }
private Long getHashIdentity() { private Long getHashIdentity() {
calculateHashes();
return myHashIdentity; return myHashIdentity;
} }
@ -147,7 +147,6 @@ public class ResourceIndexedSearchParamUri extends BaseResourceIndexedSearchPara
} }
public Long getHashUri() { public Long getHashUri() {
calculateHashes();
return myHashUri; return myHashUri;
} }
@ -182,6 +181,7 @@ public class ResourceIndexedSearchParamUri extends BaseResourceIndexedSearchPara
b.append(getParamName()); b.append(getParamName());
b.append(getUri()); b.append(getUri());
b.append(getHashUri()); b.append(getHashUri());
b.append(getHashIdentity());
return b.toHashCode(); return b.toHashCode();
} }

View File

@ -19,6 +19,7 @@ public class ResourceIndexedSearchParamQuantityTest {
@Test @Test
public void testHashFunctions() { public void testHashFunctions() {
ResourceIndexedSearchParamQuantity token = createParam("NAME", "123.001", "value", "VALUE"); ResourceIndexedSearchParamQuantity token = createParam("NAME", "123.001", "value", "VALUE");
token.calculateHashes();
// Make sure our hashing function gives consistent results // Make sure our hashing function gives consistent results
assertEquals(834432764963581074L, token.getHashIdentity().longValue()); assertEquals(834432764963581074L, token.getHashIdentity().longValue());

View File

@ -13,6 +13,7 @@ public class ResourceIndexedSearchParamStringTest {
public void testHashFunctions() { public void testHashFunctions() {
ResourceIndexedSearchParamString token = new ResourceIndexedSearchParamString(new PartitionSettings(), new ModelConfig(), "Patient", "NAME", "value", "VALUE"); ResourceIndexedSearchParamString token = new ResourceIndexedSearchParamString(new PartitionSettings(), new ModelConfig(), "Patient", "NAME", "value", "VALUE");
token.setResource(new ResourceTable().setResourceType("Patient")); token.setResource(new ResourceTable().setResourceType("Patient"));
token.calculateHashes();
// Make sure our hashing function gives consistent results // Make sure our hashing function gives consistent results
assertEquals(6598082761639188617L, token.getHashNormalizedPrefix().longValue()); assertEquals(6598082761639188617L, token.getHashNormalizedPrefix().longValue());
@ -23,6 +24,7 @@ public class ResourceIndexedSearchParamStringTest {
public void testHashFunctionsPrefixOnly() { public void testHashFunctionsPrefixOnly() {
ResourceIndexedSearchParamString token = new ResourceIndexedSearchParamString(new PartitionSettings(), new ModelConfig(), "Patient", "NAME", "vZZZZZZZZZZZZZZZZ", "VZZZZZZzzzZzzzZ"); ResourceIndexedSearchParamString token = new ResourceIndexedSearchParamString(new PartitionSettings(), new ModelConfig(), "Patient", "NAME", "vZZZZZZZZZZZZZZZZ", "VZZZZZZzzzZzzzZ");
token.setResource(new ResourceTable().setResourceType("Patient")); token.setResource(new ResourceTable().setResourceType("Patient"));
token.calculateHashes();
// Should be the same as in testHashFunctions() // Should be the same as in testHashFunctions()
assertEquals(6598082761639188617L, token.getHashNormalizedPrefix().longValue()); assertEquals(6598082761639188617L, token.getHashNormalizedPrefix().longValue());
@ -38,11 +40,13 @@ public class ResourceIndexedSearchParamStringTest {
.setValueExact("aaa") .setValueExact("aaa")
.setValueNormalized("AAA"); .setValueNormalized("AAA");
val1.setPartitionSettings(new PartitionSettings()); val1.setPartitionSettings(new PartitionSettings());
val1.setModelConfig(new ModelConfig());
val1.calculateHashes(); val1.calculateHashes();
ResourceIndexedSearchParamString val2 = new ResourceIndexedSearchParamString() ResourceIndexedSearchParamString val2 = new ResourceIndexedSearchParamString()
.setValueExact("aaa") .setValueExact("aaa")
.setValueNormalized("AAA"); .setValueNormalized("AAA");
val2.setPartitionSettings(new PartitionSettings()); val2.setPartitionSettings(new PartitionSettings());
val2.setModelConfig(new ModelConfig());
val2.calculateHashes(); val2.calculateHashes();
assertEquals(val1, val1); assertEquals(val1, val1);
assertEquals(val1, val2); assertEquals(val1, val2);
@ -56,11 +60,13 @@ public class ResourceIndexedSearchParamStringTest {
.setValueExact("aaa") .setValueExact("aaa")
.setValueNormalized("AAA"); .setValueNormalized("AAA");
val1.setPartitionSettings(new PartitionSettings().setIncludePartitionInSearchHashes(true)); val1.setPartitionSettings(new PartitionSettings().setIncludePartitionInSearchHashes(true));
val1.setModelConfig(new ModelConfig());
val1.calculateHashes(); val1.calculateHashes();
ResourceIndexedSearchParamString val2 = new ResourceIndexedSearchParamString() ResourceIndexedSearchParamString val2 = new ResourceIndexedSearchParamString()
.setValueExact("aaa") .setValueExact("aaa")
.setValueNormalized("AAA"); .setValueNormalized("AAA");
val2.setPartitionSettings(new PartitionSettings().setIncludePartitionInSearchHashes(true)); val2.setPartitionSettings(new PartitionSettings().setIncludePartitionInSearchHashes(true));
val2.setModelConfig(new ModelConfig());
val2.calculateHashes(); val2.calculateHashes();
assertEquals(val1, val1); assertEquals(val1, val1);
assertEquals(val1, val2); assertEquals(val1, val2);

View File

@ -12,6 +12,7 @@ public class ResourceIndexedSearchParamTokenTest {
public void testHashFunctions() { public void testHashFunctions() {
ResourceIndexedSearchParamToken token = new ResourceIndexedSearchParamToken(new PartitionSettings(), "Patient", "NAME", "SYSTEM", "VALUE"); ResourceIndexedSearchParamToken token = new ResourceIndexedSearchParamToken(new PartitionSettings(), "Patient", "NAME", "SYSTEM", "VALUE");
token.setResource(new ResourceTable().setResourceType("Patient")); token.setResource(new ResourceTable().setResourceType("Patient"));
token.calculateHashes();
// Make sure our hashing function gives consistent results // Make sure our hashing function gives consistent results
assertEquals(-8558989679010582575L, token.getHashSystem().longValue()); assertEquals(-8558989679010582575L, token.getHashSystem().longValue());
@ -23,6 +24,7 @@ public class ResourceIndexedSearchParamTokenTest {
public void testHashFunctionsWithOverlapNames() { public void testHashFunctionsWithOverlapNames() {
ResourceIndexedSearchParamToken token = new ResourceIndexedSearchParamToken(new PartitionSettings(), "Patient", "NAME", "SYSTEM", "VALUE"); ResourceIndexedSearchParamToken token = new ResourceIndexedSearchParamToken(new PartitionSettings(), "Patient", "NAME", "SYSTEM", "VALUE");
token.setResource(new ResourceTable().setResourceType("Patient")); token.setResource(new ResourceTable().setResourceType("Patient"));
token.calculateHashes();
// Make sure our hashing function gives consistent results // Make sure our hashing function gives consistent results
assertEquals(-8558989679010582575L, token.getHashSystem().longValue()); assertEquals(-8558989679010582575L, token.getHashSystem().longValue());

View File

@ -12,6 +12,7 @@ public class ResourceIndexedSearchParamUriTest {
public void testHashFunctions() { public void testHashFunctions() {
ResourceIndexedSearchParamUri token = new ResourceIndexedSearchParamUri(new PartitionSettings(), "Patient", "NAME", "http://example.com"); ResourceIndexedSearchParamUri token = new ResourceIndexedSearchParamUri(new PartitionSettings(), "Patient", "NAME", "http://example.com");
token.setResource(new ResourceTable().setResourceType("Patient")); token.setResource(new ResourceTable().setResourceType("Patient"));
token.calculateHashes();
// Make sure our hashing function gives consistent results // Make sure our hashing function gives consistent results
assertEquals(-6132951326739875838L, token.getHashUri().longValue()); assertEquals(-6132951326739875838L, token.getHashUri().longValue());

View File

@ -141,9 +141,11 @@ public abstract class BaseSearchParamExtractor implements ISearchParamExtractor
/** /**
* UNIT TEST constructor * UNIT TEST constructor
*/ */
BaseSearchParamExtractor(FhirContext theCtx, ISearchParamRegistry theSearchParamRegistry) { BaseSearchParamExtractor(FhirContext theCtx, ISearchParamRegistry theSearchParamRegistry, ModelConfig theModelConfig, PartitionSettings thePartitionSettings) {
myContext = theCtx; myContext = theCtx;
mySearchParamRegistry = theSearchParamRegistry; mySearchParamRegistry = theSearchParamRegistry;
myPartitionSettings = thePartitionSettings;
myModelConfig = theModelConfig;
} }
@VisibleForTesting @VisibleForTesting

View File

@ -130,12 +130,6 @@ public final class ResourceIndexedSearchParams {
} }
} }
public void calculateHashes(Collection<? extends BaseResourceIndex> theStringParams) {
for (BaseResourceIndex next : theStringParams) {
next.calculateHashes();
}
}
public Set<String> getPopulatedResourceLinkParameters() { public Set<String> getPopulatedResourceLinkParameters() {
return myPopulatedResourceLinkParameters; return myPopulatedResourceLinkParameters;
} }
@ -305,6 +299,7 @@ public final class ResourceIndexedSearchParams {
param.setResource(theEntity); param.setResource(theEntity);
param.setMissing(true); param.setMissing(true);
param.setParamName(nextParamName); param.setParamName(nextParamName);
param.calculateHashes();
paramCollection.add((RT) param); paramCollection.add((RT) param);
} }
} }

View File

@ -21,6 +21,8 @@ package ca.uhn.fhir.jpa.searchparam.extractor;
*/ */
import ca.uhn.fhir.context.FhirContext; 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.jpa.searchparam.registry.ISearchParamRegistry;
import ca.uhn.fhir.model.dstu2.composite.ContactPointDt; import ca.uhn.fhir.model.dstu2.composite.ContactPointDt;
import ca.uhn.fhir.util.FhirTerser; import ca.uhn.fhir.util.FhirTerser;
@ -40,8 +42,8 @@ public class SearchParamExtractorDstu2 extends BaseSearchParamExtractor implemen
/** /**
* Constructor for unit tests * Constructor for unit tests
*/ */
SearchParamExtractorDstu2(FhirContext theCtx, ISearchParamRegistry theSearchParamRegistry) { SearchParamExtractorDstu2(FhirContext theCtx, ISearchParamRegistry theSearchParamRegistry, ModelConfig theModelConfig, PartitionSettings thePartitionSettings) {
super(theCtx, theSearchParamRegistry); super(theCtx, theSearchParamRegistry, theModelConfig, thePartitionSettings);
start(); start();
} }

View File

@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.searchparam.extractor;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.support.IValidationSupport; 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.ModelConfig;
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
@ -49,8 +50,8 @@ public class SearchParamExtractorDstu3 extends BaseSearchParamExtractor implemen
// This constructor is used by tests // This constructor is used by tests
@VisibleForTesting @VisibleForTesting
public SearchParamExtractorDstu3(ModelConfig theModelConfig, FhirContext theCtx, IValidationSupport theValidationSupport, ISearchParamRegistry theSearchParamRegistry) { public SearchParamExtractorDstu3(ModelConfig theModelConfig, FhirContext theCtx, IValidationSupport theValidationSupport, ISearchParamRegistry theSearchParamRegistry, PartitionSettings thePartitionSettings) {
super(theCtx, theSearchParamRegistry); super(theCtx, theSearchParamRegistry, theModelConfig, thePartitionSettings);
initFhirPathEngine(theValidationSupport); initFhirPathEngine(theValidationSupport);
start(); start();
} }

View File

@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.searchparam.extractor;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.support.IValidationSupport; 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.ModelConfig;
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
@ -61,8 +62,8 @@ public class SearchParamExtractorR4 extends BaseSearchParamExtractor implements
// This constructor is used by tests // This constructor is used by tests
@VisibleForTesting @VisibleForTesting
public SearchParamExtractorR4(ModelConfig theModelConfig, FhirContext theCtx, IValidationSupport theValidationSupport, ISearchParamRegistry theSearchParamRegistry) { public SearchParamExtractorR4(ModelConfig theModelConfig, FhirContext theCtx, IValidationSupport theValidationSupport, ISearchParamRegistry theSearchParamRegistry, PartitionSettings thePartitionSettings) {
super(theCtx, theSearchParamRegistry); super(theCtx, theSearchParamRegistry,theModelConfig, thePartitionSettings);
initFhirPath(theValidationSupport); initFhirPath(theValidationSupport);
start(); start();
} }

View File

@ -23,6 +23,8 @@ package ca.uhn.fhir.jpa.searchparam.extractor;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; import ca.uhn.fhir.context.support.DefaultProfileValidationSupport;
import ca.uhn.fhir.context.support.IValidationSupport; 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 ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.PathEngineException; import org.hl7.fhir.exceptions.PathEngineException;
@ -56,8 +58,8 @@ public class SearchParamExtractorR5 extends BaseSearchParamExtractor implements
/** /**
* Constructor for unit tests * Constructor for unit tests
*/ */
public SearchParamExtractorR5(FhirContext theCtx, DefaultProfileValidationSupport theDefaultProfileValidationSupport, ISearchParamRegistry theSearchParamRegistry) { public SearchParamExtractorR5(FhirContext theCtx, DefaultProfileValidationSupport theDefaultProfileValidationSupport, ISearchParamRegistry theSearchParamRegistry, ModelConfig theModelConfig, PartitionSettings thePartitionSettings) {
super(theCtx, theSearchParamRegistry); super(theCtx, theSearchParamRegistry, theModelConfig, thePartitionSettings);
initFhirPath(theDefaultProfileValidationSupport); initFhirPath(theDefaultProfileValidationSupport);
start(); start();
} }

View File

@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.searchparam;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.context.support.IValidationSupport; 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.ModelConfig;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamString; import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamString;
import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorDstu3; import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorDstu3;
@ -44,7 +45,7 @@ public class IndexStressTest {
when(mockValidationSupport.getFhirContext()).thenReturn(ctx); when(mockValidationSupport.getFhirContext()).thenReturn(ctx);
IValidationSupport validationSupport = new CachingValidationSupport(new ValidationSupportChain(new DefaultProfileValidationSupport(ctx), mockValidationSupport)); IValidationSupport validationSupport = new CachingValidationSupport(new ValidationSupportChain(new DefaultProfileValidationSupport(ctx), mockValidationSupport));
ISearchParamRegistry searchParamRegistry = mock(ISearchParamRegistry.class); 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(); extractor.start();
Map<String, RuntimeSearchParam> spMap = ctx Map<String, RuntimeSearchParam> spMap = ctx

View File

@ -58,7 +58,7 @@ public class SearchParamExtractorDstu3Test {
ISearchParamRegistry searchParamRegistry = new MySearchParamRegistry(); 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.setPartitionConfigForUnitTest(new PartitionSettings());
extractor.start(); extractor.start();
Set<BaseResourceIndexedSearchParam> tokens = extractor.extractSearchParamTokens(obs); Set<BaseResourceIndexedSearchParam> tokens = extractor.extractSearchParamTokens(obs);
@ -82,7 +82,7 @@ public class SearchParamExtractorDstu3Test {
ISearchParamRegistry searchParamRegistry = new MySearchParamRegistry(); 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(); extractor.start();
Set<ResourceIndexedSearchParamString> params = extractor.extractSearchParamStrings(questionnaire); Set<ResourceIndexedSearchParamString> params = extractor.extractSearchParamStrings(questionnaire);
assertEquals(1, params.size()); assertEquals(1, params.size());
@ -100,7 +100,7 @@ public class SearchParamExtractorDstu3Test {
ISearchParamRegistry searchParamRegistry = new MySearchParamRegistry(); 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(); extractor.start();
Set<ResourceIndexedSearchParamNumber> params = extractor.extractSearchParamNumber(enc); Set<ResourceIndexedSearchParamNumber> params = extractor.extractSearchParamNumber(enc);
assertEquals(1, params.size()); assertEquals(1, params.size());
@ -118,7 +118,7 @@ public class SearchParamExtractorDstu3Test {
ISearchParamRegistry searchParamRegistry = new MySearchParamRegistry(); 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(); extractor.start();
Set<ResourceIndexedSearchParamNumber> params = extractor.extractSearchParamNumber(enc); Set<ResourceIndexedSearchParamNumber> params = extractor.extractSearchParamNumber(enc);
assertEquals(1, params.size()); assertEquals(1, params.size());
@ -130,7 +130,7 @@ public class SearchParamExtractorDstu3Test {
public void testEmptyPath() { public void testEmptyPath() {
MySearchParamRegistry searchParamRegistry = new MySearchParamRegistry(); 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(); extractor.start();
searchParamRegistry.addSearchParam(new RuntimeSearchParam("foo", "foo", "", RestSearchParameterTypeEnum.STRING, Sets.newHashSet(), Sets.newHashSet(), RuntimeSearchParam.RuntimeSearchParamStatusEnum.ACTIVE)); 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() { public void testStringMissingResourceType() {
MySearchParamRegistry searchParamRegistry = new MySearchParamRegistry(); 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(); 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)); 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() { public void testInvalidType() {
MySearchParamRegistry searchParamRegistry = new MySearchParamRegistry(); 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.setPartitionConfigForUnitTest(new PartitionSettings());
extractor.start(); extractor.start();
@ -215,7 +215,7 @@ public class SearchParamExtractorDstu3Test {
ISearchParamRegistry searchParamRegistry = new MySearchParamRegistry(); 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(); extractor.start();
ISearchParamExtractor.SearchParamSet<BaseResourceIndexedSearchParam> coords = extractor.extractSearchParamTokens(loc); ISearchParamExtractor.SearchParamSet<BaseResourceIndexedSearchParam> coords = extractor.extractSearchParamTokens(loc);
assertEquals(1, coords.size()); assertEquals(1, coords.size());

View File

@ -2,6 +2,7 @@ package ca.uhn.fhir.jpa.searchparam.extractor;
import ca.uhn.fhir.context.*; import ca.uhn.fhir.context.*;
import ca.uhn.fhir.jpa.model.config.PartitionSettings; 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.JpaRuntimeSearchParam;
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; import ca.uhn.fhir.context.support.DefaultProfileValidationSupport;
@ -39,19 +40,19 @@ public class SearchParamExtractorMegaTest {
FhirContext ctx = FhirContext.forDstu2(); FhirContext ctx = FhirContext.forDstu2();
ISearchParamRegistry searchParamRegistry = new MySearchParamRegistry(ctx); 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(); ctx = FhirContext.forDstu3();
searchParamRegistry = new MySearchParamRegistry(ctx); 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(); ctx = FhirContext.forR4();
searchParamRegistry = new MySearchParamRegistry(ctx); 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(); ctx = FhirContext.forR5();
searchParamRegistry = new MySearchParamRegistry(ctx); 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 { private void process(FhirContext theCtx, BaseSearchParamExtractor theExtractor) throws Exception {