Skip to content

Commit

Permalink
Issue #2155 - Update after review comments to generate hash faster
Browse files Browse the repository at this point in the history
Signed-off-by: Troy Biesterfeld <tbieste@us.ibm.com>
  • Loading branch information
tbieste committed Jun 30, 2021
1 parent 13d2e20 commit b8eb124
Show file tree
Hide file tree
Showing 15 changed files with 828 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.List;

import com.ibm.fhir.persistence.exception.FHIRPersistenceException;
import com.ibm.fhir.persistence.jdbc.util.ParameterHashUtil;

/**
* This class defines the Data Transfer Object representing a composite parameter.
Expand All @@ -26,19 +25,6 @@ public CompositeParmVal() {
component = new ArrayList<>(2);
}

/**
* We know our type, so we can call the correct method on the visitor
*/
@Override
public void accept(ExtractedParameterValueVisitor visitor) throws FHIRPersistenceException {
visitor.visit(this);
}

@Override
public String getHash(ParameterHashUtil parameterHashUtil) {
return parameterHashUtil.getNameValueHash(getHashHeader(), parameterHashUtil.getParametersHash(component));
}

/**
* @return get the list of components in this composite parameter
*/
Expand All @@ -61,4 +47,42 @@ public void addComponent(ExtractedParameterValue... component) {
this.component.add(value);
}
}

/**
* We know our type, so we can call the correct method on the visitor
*/
@Override
public void accept(ExtractedParameterValueVisitor visitor) throws FHIRPersistenceException {
visitor.visit(this);
}

@Override
protected int compareToInner(ExtractedParameterValue o) {
CompositeParmVal other = (CompositeParmVal) o;
int retVal;

List<ExtractedParameterValue> thisComponent = this.getComponent();
List<ExtractedParameterValue> otherComponent = other.getComponent();
if (thisComponent != null || otherComponent != null) {
if (thisComponent == null) {
return -1;
} else if (otherComponent == null) {
return 1;
}
Integer thisSize = thisComponent.size();
Integer otherSize = otherComponent.size();
for (int i=0; i<thisSize && i<otherSize; i++) {
retVal = thisComponent.get(i).compareTo(otherComponent.get(i));
if (retVal != 0) {
return retVal;
}
}
retVal = thisSize.compareTo(otherSize);
if (retVal != 0) {
return retVal;
}
}

return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
package com.ibm.fhir.persistence.jdbc.dto;

import java.sql.Timestamp;
import java.util.Objects;

import com.ibm.fhir.persistence.exception.FHIRPersistenceException;
import com.ibm.fhir.persistence.jdbc.util.ParameterHashUtil;

/**
* This class defines the Data Transfer Object representing a row in the X_DATE_VALUES tables.
Expand Down Expand Up @@ -58,11 +56,39 @@ public void accept(ExtractedParameterValueVisitor visitor) throws FHIRPersistenc
}

@Override
public String getHash(ParameterHashUtil parameterHashUtil) {
StringBuilder sb = new StringBuilder();
sb.append(Objects.toString(valueDateStart, ""));
sb.append("|").append(Objects.toString(valueDateEnd, ""));
return parameterHashUtil.getNameValueHash(getHashHeader(), sb.toString());
protected int compareToInner(ExtractedParameterValue o) {
DateParmVal other = (DateParmVal) o;
int retVal;

Timestamp thisValueDateStart = this.getValueDateStart();
Timestamp otherValueDateStart = other.getValueDateStart();
if (thisValueDateStart != null || otherValueDateStart != null) {
if (thisValueDateStart == null) {
return -1;
} else if (otherValueDateStart == null) {
return 1;
}
retVal = thisValueDateStart.compareTo(otherValueDateStart);
if (retVal != 0) {
return retVal;
}
}

Timestamp thisValueDateEnd = this.getValueDateEnd();
Timestamp otherValueDateEnd = other.getValueDateEnd();
if (thisValueDateEnd != null || otherValueDateEnd != null) {
if (thisValueDateEnd == null) {
return -1;
} else if (otherValueDateEnd == null) {
return 1;
}
retVal = thisValueDateEnd.compareTo(otherValueDateEnd);
if (retVal != 0) {
return retVal;
}
}

return 0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@

package com.ibm.fhir.persistence.jdbc.dto;

import java.util.Objects;

import com.ibm.fhir.persistence.exception.FHIRPersistenceException;
import com.ibm.fhir.persistence.jdbc.util.ParameterHashUtil;
import com.ibm.fhir.schema.control.FhirSchemaVersion;

/**
* A search parameter value extracted from a resource and ready to store / index for search
*/
public abstract class ExtractedParameterValue {
public abstract class ExtractedParameterValue implements Comparable<ExtractedParameterValue> {

// The name (code) of this parameter
private String name;
Expand All @@ -26,9 +22,6 @@ public abstract class ExtractedParameterValue {
// The resource type associated with this parameter
private String resourceType;

// The base resource name
private String base;

// URL and version of search parameter
private String url;
private String version;
Expand Down Expand Up @@ -60,20 +53,6 @@ public void setResourceType(String resourceType) {
*/
public abstract void accept(ExtractedParameterValueVisitor visitor) throws FHIRPersistenceException;

/**
* @return the base
*/
public String getBase() {
return this.base;
}

/**
* @param base the base to set
*/
public void setBase(String base) {
this.base = base;
}

/**
* @return the wholeSystem
*/
Expand Down Expand Up @@ -130,24 +109,70 @@ public void setVersion(String version) {
this.version = version;
}

/**
* Gets the hash header.
* @return the hash header
*/
protected String getHashHeader() {
StringBuilder sb = new StringBuilder();
sb.append(Objects.toString(FhirSchemaVersion.getLatestParameterStorageUpdate(), ""));
sb.append("|").append(Objects.toString(name, ""));
sb.append("|").append(Objects.toString(url, ""));
sb.append("|").append(Objects.toString(version, ""));
return sb.toString();
@Override
public int compareTo(ExtractedParameterValue o) {
int retVal;
String thisClass = this.getClass().getName();
String otherClass = o.getClass().getName();
if (thisClass != null || otherClass != null) {
if (thisClass == null) {
return -1;
} else if (otherClass == null) {
return 1;
}
retVal = thisClass.compareTo(otherClass);
if (retVal != 0) {
return retVal;
}
}
String thisName = this.getName();
String otherName = o.getName();
if (thisName != null || otherName != null) {
if (thisName == null) {
return -1;
} else if (otherName == null) {
return 1;
}
retVal = thisName.compareTo(otherName);
if (retVal != 0) {
return retVal;
}
}
String thisUrl = this.getUrl();
String otherUrl = o.getUrl();
if (thisUrl != null || otherUrl != null) {
if (thisUrl == null) {
return -1;
} else if (otherUrl == null) {
return 1;
}
retVal = thisUrl.compareTo(otherUrl);
if (retVal != 0) {
return retVal;
}
}
String thisVersion = this.getVersion();
String otherVersion = o.getVersion();
if (thisVersion != null || otherVersion != null) {
if (thisVersion == null) {
return -1;
} else if (otherVersion == null) {
return 1;
}
retVal = thisVersion.compareTo(otherVersion);
if (retVal != 0) {
return retVal;
}
}
return compareToInner(o);
}

/**
* Gets the hash representation of the parameter.
* This should be generated from the search parameter (schemaVersion, code, url, version) and the extracted value.
* @param the parameter hash utility to use for generating hashes
* @return the hash
* Additional extracted parameter value comparisions when the same class.
* @param o an extracted parameter value to compare to
* @return a negative integer, zero, or a positive integer as this extracted parameter value
* is less than, equal to, or greater than the specified extracted parameter value.
*/
public abstract String getHash(ParameterHashUtil parameterHashUtil);
protected abstract int compareToInner(ExtractedParameterValue o);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@

package com.ibm.fhir.persistence.jdbc.dto;

import java.util.Objects;

import com.ibm.fhir.persistence.exception.FHIRPersistenceException;
import com.ibm.fhir.persistence.jdbc.util.ParameterHashUtil;

/**
* This class defines the Data Transfer Object representing a row in the X_LATLNG_VALUES tables.
*/
public class LocationParmVal extends ExtractedParameterValue {

private Double valueLongitude;
private Double valueLatitude;
private Double valueLongitude;

/**
* Public constructor
Expand All @@ -26,14 +23,6 @@ public LocationParmVal() {
super();
}

public Double getValueLongitude() {
return valueLongitude;
}

public void setValueLongitude(Double valueLongitude) {
this.valueLongitude = valueLongitude;
}

public Double getValueLatitude() {
return valueLatitude;
}
Expand All @@ -42,6 +31,14 @@ public void setValueLatitude(Double valueLatitude) {
this.valueLatitude = valueLatitude;
}

public Double getValueLongitude() {
return valueLongitude;
}

public void setValueLongitude(Double valueLongitude) {
this.valueLongitude = valueLongitude;
}

/**
* We know our type, so we can call the correct method on the visitor
*/
Expand All @@ -51,10 +48,38 @@ public void accept(ExtractedParameterValueVisitor visitor) throws FHIRPersistenc
}

@Override
public String getHash(ParameterHashUtil parameterHashUtil) {
StringBuilder sb = new StringBuilder();
sb.append(Objects.toString(valueLongitude, ""));
sb.append("|").append(Objects.toString(valueLatitude, ""));
return parameterHashUtil.getNameValueHash(getHashHeader(), sb.toString());
protected int compareToInner(ExtractedParameterValue o) {
LocationParmVal other = (LocationParmVal) o;
int retVal;

Double thisValueLatitude = this.getValueLatitude();
Double otherValueLatitude = other.getValueLatitude();
if (thisValueLatitude != null || otherValueLatitude != null) {
if (thisValueLatitude == null) {
return -1;
} else if (otherValueLatitude == null) {
return 1;
}
retVal = thisValueLatitude.compareTo(otherValueLatitude);
if (retVal != 0) {
return retVal;
}
}

Double thisValueLongitude = this.getValueLongitude();
Double otherValueLongitude = other.getValueLongitude();
if (thisValueLongitude != null || otherValueLongitude != null) {
if (thisValueLongitude == null) {
return -1;
} else if (otherValueLongitude == null) {
return 1;
}
retVal = thisValueLongitude.compareTo(otherValueLongitude);
if (retVal != 0) {
return retVal;
}
}

return 0;
}
}
Loading

0 comments on commit b8eb124

Please sign in to comment.