From 24ad8870cf4ce643e5532f7c9accb81e90df2c39 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Sat, 16 Jun 2018 18:23:05 -0400 Subject: [PATCH] Add to indexes --- .../BaseResourceIndexedSearchParam.java | 37 +++++----- .../ResourceIndexedSearchParamCoords.java | 68 ++++++++++++------- .../ResourceIndexedSearchParamDate.java | 43 +++++++++--- .../ResourceIndexedSearchParamNumber.java | 29 ++++++-- .../ResourceIndexedSearchParamQuantity.java | 1 + .../ResourceIndexedSearchParamString.java | 10 +-- .../ResourceIndexedSearchParamToken.java | 4 -- .../entity/ResourceIndexedSearchParamUri.java | 4 +- 8 files changed, 130 insertions(+), 66 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/BaseResourceIndexedSearchParam.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/BaseResourceIndexedSearchParam.java index 3062ca3a21a..6ac896c89a7 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/BaseResourceIndexedSearchParam.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/BaseResourceIndexedSearchParam.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.entity; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -36,13 +36,15 @@ import java.util.Date; @MappedSuperclass public abstract class BaseResourceIndexedSearchParam implements Serializable { - /** Don't change this without careful consideration. You will break existing hashes! */ - private static final HashFunction HASH_FUNCTION = Hashing.murmur3_128(0); - /** Don't make this public 'cause nobody better be able to modify it! */ - private static final byte[] DELIMITER_BYTES = "|".getBytes(Charsets.UTF_8); - static final int MAX_SP_NAME = 100; - + /** + * Don't change this without careful consideration. You will break existing hashes! + */ + private static final HashFunction HASH_FUNCTION = Hashing.murmur3_128(0); + /** + * Don't make this public 'cause nobody better be able to modify it! + */ + private static final byte[] DELIMITER_BYTES = "|".getBytes(Charsets.UTF_8); private static final long serialVersionUID = 1L; // TODO: make this nullable=false and a primitive (written may 2017) @@ -71,6 +73,13 @@ public abstract class BaseResourceIndexedSearchParam implements Serializable { @Temporal(TemporalType.TIMESTAMP) private Date myUpdated; + /** + * Subclasses may override + */ + protected void clearHashes() { + // nothing + } + protected abstract Long getId(); public String getParamName() { @@ -82,13 +91,6 @@ public abstract class BaseResourceIndexedSearchParam implements Serializable { myParamName = theName; } - /** - * Subclasses may override - */ - protected void clearHashes() { - // nothing - } - public ResourceTable getResource() { return myResource; } @@ -127,6 +129,10 @@ public abstract class BaseResourceIndexedSearchParam implements Serializable { public abstract IQueryParameterType toQueryParameterType(); + public static long calculateHashIdentity(String theResourceType, String theParamName) { + return hash(theResourceType, theParamName); + } + /** * Applies a fast and consistent hashing algorithm to a set of strings */ @@ -148,5 +154,4 @@ public abstract class BaseResourceIndexedSearchParam implements Serializable { return hashCode.asLong(); } - } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamCoords.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamCoords.java index 4661405a2bc..107662ddfd3 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamCoords.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamCoords.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.entity; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -31,30 +31,32 @@ import javax.persistence.*; @Embeddable @Entity -@Table(name = "HFJ_SPIDX_COORDS", indexes = { - @Index(name = "IDX_SP_COORDS", columnList = "RES_TYPE,SP_NAME,SP_LATITUDE,SP_LONGITUDE"), - @Index(name = "IDX_SP_COORDS_UPDATED", columnList = "SP_UPDATED"), - @Index(name = "IDX_SP_COORDS_RESID", columnList = "RES_ID") +@Table(name = "HFJ_SPIDX_COORDS", indexes = { + @Index(name = "IDX_SP_COORDS", columnList = "RES_TYPE,SP_NAME,SP_LATITUDE,SP_LONGITUDE"), + @Index(name = "IDX_SP_COORDS_UPDATED", columnList = "SP_UPDATED"), + @Index(name = "IDX_SP_COORDS_RESID", columnList = "RES_ID") }) public class ResourceIndexedSearchParamCoords extends BaseResourceIndexedSearchParam { public static final int MAX_LENGTH = 100; private static final long serialVersionUID = 1L; - + @Column(name = "SP_LATITUDE") + @Field + public double myLatitude; + @Column(name = "SP_LONGITUDE") + @Field + public double myLongitude; @Id @SequenceGenerator(name = "SEQ_SPIDX_COORDS", sequenceName = "SEQ_SPIDX_COORDS") @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_SPIDX_COORDS") @Column(name = "SP_ID") private Long myId; - - @Column(name = "SP_LATITUDE") - @Field - public double myLatitude; - - @Column(name = "SP_LONGITUDE") - @Field - public double myLongitude; + /** + * @since 3.5.0 - At some point this should be made not-null + */ + @Column(name = "HASH_IDENTITY", nullable = true) + private Long myHashIdentity; public ResourceIndexedSearchParamCoords() { } @@ -65,6 +67,20 @@ public class ResourceIndexedSearchParamCoords extends BaseResourceIndexedSearchP setLongitude(theLongitude); } + @PrePersist + public void calculateHashes() { + if (myHashIdentity == null) { + String resourceType = getResourceType(); + String paramName = getParamName(); + setHashIdentity(calculateHashIdentity(resourceType, paramName)); + } + } + + @Override + protected void clearHashes() { + myHashIdentity = null; + } + @Override public boolean equals(Object theObj) { if (this == theObj) { @@ -90,19 +106,22 @@ public class ResourceIndexedSearchParamCoords extends BaseResourceIndexedSearchP return myId; } - @Override - public IQueryParameterType toQueryParameterType() { - return null; - } - public double getLatitude() { return myLatitude; } + public void setLatitude(double theLatitude) { + myLatitude = theLatitude; + } + public double getLongitude() { return myLongitude; } + public void setLongitude(double theLongitude) { + myLongitude = theLongitude; + } + @Override public int hashCode() { HashCodeBuilder b = new HashCodeBuilder(); @@ -113,12 +132,13 @@ public class ResourceIndexedSearchParamCoords extends BaseResourceIndexedSearchP return b.toHashCode(); } - public void setLatitude(double theLatitude) { - myLatitude = theLatitude; + public void setHashIdentity(Long theHashIdentity) { + myHashIdentity = theHashIdentity; } - public void setLongitude(double theLongitude) { - myLongitude = theLongitude; + @Override + public IQueryParameterType toQueryParameterType() { + return null; } @Override diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamDate.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamDate.java index 858a20de253..8765a8a5d79 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamDate.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamDate.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.entity; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -44,10 +44,6 @@ import java.util.Date; public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchParam { private static final long serialVersionUID = 1L; - - @Transient - private transient String myOriginalValue; - @Column(name = "SP_VALUE_HIGH", nullable = true) @Temporal(TemporalType.TIMESTAMP) @Field @@ -56,11 +52,18 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar @Temporal(TemporalType.TIMESTAMP) @Field public Date myValueLow; + @Transient + private transient String myOriginalValue; @Id @SequenceGenerator(name = "SEQ_SPIDX_DATE", sequenceName = "SEQ_SPIDX_DATE") @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_SPIDX_DATE") @Column(name = "SP_ID") private Long myId; + /** + * @since 3.5.0 - At some point this should be made not-null + */ + @Column(name = "HASH_IDENTITY", nullable = true) + private Long myHashIdentity; /** * Constructor @@ -79,6 +82,20 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar myOriginalValue = theOriginalValue; } + @PrePersist + public void calculateHashes() { + if (myHashIdentity == null) { + String resourceType = getResourceType(); + String paramName = getParamName(); + setHashIdentity(calculateHashIdentity(resourceType, paramName)); + } + } + + @Override + protected void clearHashes() { + myHashIdentity = null; + } + @Override public boolean equals(Object theObj) { if (this == theObj) { @@ -100,6 +117,11 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar return b.isEquals(); } + @Override + protected Long getId() { + return myId; + } + protected Long getTimeFromDate(Date date) { if (date != null) { return date.getTime(); @@ -107,11 +129,6 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar return null; } - @Override - protected Long getId() { - return myId; - } - public Date getValueHigh() { return myValueHigh; } @@ -138,6 +155,10 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar return b.toHashCode(); } + public void setHashIdentity(Long theHashIdentity) { + myHashIdentity = theHashIdentity; + } + @Override public IQueryParameterType toQueryParameterType() { DateTimeType value = new DateTimeType(myOriginalValue); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamNumber.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamNumber.java index 0232ff25ad9..029386f6ed1 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamNumber.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamNumber.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.entity; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -34,7 +34,6 @@ import org.hibernate.search.annotations.NumericField; import javax.persistence.*; import java.math.BigDecimal; -//@formatter:off @Embeddable @Entity @Table(name = "HFJ_SPIDX_NUMBER", indexes = { @@ -42,7 +41,6 @@ import java.math.BigDecimal; @Index(name = "IDX_SP_NUMBER_UPDATED", columnList = "SP_UPDATED"), @Index(name = "IDX_SP_NUMBER_RESID", columnList = "RES_ID") }) -//@formatter:on public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchParam { private static final long serialVersionUID = 1L; @@ -56,6 +54,11 @@ public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchP @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_SPIDX_NUMBER") @Column(name = "SP_ID") private Long myId; + /** + * @since 3.5.0 - At some point this should be made not-null + */ + @Column(name = "HASH_IDENTITY", nullable = true) + private Long myHashIdentity; public ResourceIndexedSearchParamNumber() { } @@ -65,6 +68,20 @@ public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchP setValue(theValue); } + @PrePersist + public void calculateHashes() { + if (myHashIdentity == null) { + String resourceType = getResourceType(); + String paramName = getParamName(); + setHashIdentity(calculateHashIdentity(resourceType, paramName)); + } + } + + @Override + protected void clearHashes() { + myHashIdentity = null; + } + @Override public boolean equals(Object theObj) { if (this == theObj) { @@ -108,6 +125,10 @@ public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchP return b.toHashCode(); } + public void setHashIdentity(Long theHashIdentity) { + myHashIdentity = theHashIdentity; + } + @Override public IQueryParameterType toQueryParameterType() { return new NumberParam(myValue.toPlainString()); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamQuantity.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamQuantity.java index ac7a90f25e0..4c1deaf807d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamQuantity.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamQuantity.java @@ -79,6 +79,7 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc // nothing } + public ResourceIndexedSearchParamQuantity(String theParamName, BigDecimal theValue, String theSystem, String theUnits) { setParamName(theParamName); setSystem(theSystem); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamString.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamString.java index 2123dac9370..cee187bd5c9 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamString.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamString.java @@ -192,11 +192,6 @@ public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchP return myHashExact; } - public BaseResourceIndexedSearchParam setDaoConfig(DaoConfig theDaoConfig) { - myDaoConfig = theDaoConfig; - return this; - } - public void setHashExact(Long theHashExact) { myHashExact = theHashExact; } @@ -247,6 +242,11 @@ public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchP return b.toHashCode(); } + public BaseResourceIndexedSearchParam setDaoConfig(DaoConfig theDaoConfig) { + myDaoConfig = theDaoConfig; + return this; + } + @Override public IQueryParameterType toQueryParameterType() { return new StringParam(getValueExact()); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamToken.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamToken.java index e82d91d3784..66f89e9eb9b 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamToken.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamToken.java @@ -238,10 +238,6 @@ public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchPa return hash(theResourceType, theParamName, trim(theSystem)); } - public static long calculateHashIdentity(String theResourceType, String theParamName) { - return hash(theResourceType, theParamName); - } - public static long calculateHashSystemAndValue(String theResourceType, String theParamName, String theSystem, String theValue) { return hash(theResourceType, theParamName, defaultString(trim(theSystem)), trim(theValue)); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamUri.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamUri.java index 27b52efeac9..72fd8bcbf6d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamUri.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/ResourceIndexedSearchParamUri.java @@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.entity; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.