Add to indexes

This commit is contained in:
jamesagnew 2018-06-16 18:23:05 -04:00
parent dd9031de32
commit 24ad8870cf
8 changed files with 130 additions and 66 deletions

View File

@ -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();
}
}

View File

@ -41,20 +41,22 @@ public class ResourceIndexedSearchParamCoords extends BaseResourceIndexedSearchP
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

View File

@ -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);

View File

@ -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());

View File

@ -79,6 +79,7 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc
// nothing
}
public ResourceIndexedSearchParamQuantity(String theParamName, BigDecimal theValue, String theSystem, String theUnits) {
setParamName(theParamName);
setSystem(theSystem);

View File

@ -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());

View File

@ -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));
}