Add update time to search parameters

This commit is contained in:
James 2017-03-12 12:13:31 -04:00
parent 120227da2f
commit 0e3cc29c50
10 changed files with 68 additions and 20 deletions

View File

@ -252,7 +252,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
}
@SuppressWarnings("unchecked")
protected void extractResourceLinks(ResourceTable theEntity, IBaseResource theResource, Set<ResourceLink> theLinks) {
protected void extractResourceLinks(ResourceTable theEntity, IBaseResource theResource, Set<ResourceLink> theLinks, Date theUpdateTime) {
/*
* For now we don't try to load any of the links in a bundle if it's the actual bundle we're storing..
@ -329,7 +329,8 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
String msg = getContext().getLocalizer().getMessage(BaseHapiFhirDao.class, "externalReferenceNotAllowed", nextId.getValue());
throw new InvalidRequestException(msg);
} else {
if (theLinks.add(new ResourceLink(nextPathAndRef.getPath(), theEntity, nextId))) {
ResourceLink resourceLink = new ResourceLink(nextPathAndRef.getPath(), theEntity, nextId, theUpdateTime);
if (theLinks.add(resourceLink)) {
ourLog.info("Indexing remote resource reference URL: {}", nextId);
}
continue;
@ -377,7 +378,8 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
continue;
}
theLinks.add(new ResourceLink(nextPathAndRef.getPath(), theEntity, target));
ResourceLink resourceLink = new ResourceLink(nextPathAndRef.getPath(), theEntity, target, theUpdateTime);
theLinks.add(resourceLink);
}
}
@ -390,11 +392,6 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
return mySearchParamExtractor.extractSearchParamCoords(theEntity, theResource);
}
// @Override
// public void setResourceDaos(List<IFhirResourceDao<?>> theResourceDaos) {
// myResourceDaos = theResourceDaos;
// }
protected Set<ResourceIndexedSearchParamDate> extractSearchParamDates(ResourceTable theEntity, IBaseResource theResource) {
return mySearchParamExtractor.extractSearchParamDates(theEntity, theResource);
}
@ -1229,6 +1226,13 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
uriParams = extractSearchParamUri(theEntity, theResource);
coordsParams = extractSearchParamCoords(theEntity, theResource);
setUpdatedTime(stringParams, theUpdateTime);
setUpdatedTime(numberParams, theUpdateTime);
setUpdatedTime(quantityParams, theUpdateTime);
setUpdatedTime(dateParams, theUpdateTime);
setUpdatedTime(uriParams, theUpdateTime);
setUpdatedTime(coordsParams, theUpdateTime);
// ourLog.info("Indexing resource: {}", entity.getId());
ourLog.trace("Storing date indexes: {}", dateParams);
@ -1292,7 +1296,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
}
links = new HashSet<ResourceLink>();
extractResourceLinks(theEntity, theResource, links);
extractResourceLinks(theEntity, theResource, links, theUpdateTime);
/*
* If the existing resource already has links and those match links we still want, use them instead of removing them and re adding them
@ -1451,6 +1455,12 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
return theEntity;
}
private void setUpdatedTime(Collection<? extends BaseResourceIndexedSearchParam> theParams, Date theUpdateTime) {
for (BaseResourceIndexedSearchParam nextSearchParam : theParams) {
nextSearchParam.setUpdated(theUpdateTime);
}
}
protected ResourceTable updateEntity(IBaseResource theResource, ResourceTable entity, Date theDeletedTimestampOrNull, Date theUpdateTime) {
return updateEntity(theResource, entity, theDeletedTimestampOrNull, true, true, theUpdateTime);
}

View File

@ -21,14 +21,14 @@ package ca.uhn.fhir.jpa.entity;
*/
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.search.annotations.ContainedIn;
import org.hibernate.search.annotations.Field;
@ -56,6 +56,11 @@ public abstract class BaseResourceIndexedSearchParam implements Serializable {
@Column(name = "RES_TYPE", nullable = false)
private String myResourceType;
@Field()
@Column(name = "SP_UPDATED", nullable = true) // TODO: make this false after HAPI 2.3
@Temporal(TemporalType.TIMESTAMP)
private Date myUpdated;
protected abstract Long getId();
public String getParamName() {
@ -74,6 +79,10 @@ public abstract class BaseResourceIndexedSearchParam implements Serializable {
return myResourceType;
}
public Date getUpdated() {
return myUpdated;
}
public void setParamName(String theName) {
myParamName = theName;
}
@ -83,4 +92,8 @@ public abstract class BaseResourceIndexedSearchParam implements Serializable {
myResourceType = theResource.getResourceType();
}
public void setUpdated(Date theUpdated) {
myUpdated = theUpdated;
}
}

View File

@ -41,6 +41,7 @@ import org.hibernate.search.annotations.Field;
@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")
})
//@formatter:on

View File

@ -47,6 +47,7 @@ import ca.uhn.fhir.model.primitive.InstantDt;
@Entity
@Table(name = "HFJ_SPIDX_DATE", indexes= {
@Index(name = "IDX_SP_DATE", columnList = "RES_TYPE,SP_NAME,SP_VALUE_LOW,SP_VALUE_HIGH"),
@Index(name = "IDX_SP_DATE_UPDATED", columnList = "SP_UPDATED"),
@Index(name = "IDX_SP_DATE_RESID", columnList = "RES_ID")
})
//@formatter:on

View File

@ -47,6 +47,7 @@ import ca.uhn.fhir.jpa.util.BigDecimalNumericFieldBridge;
@Entity
@Table(name = "HFJ_SPIDX_NUMBER", indexes= {
@Index(name = "IDX_SP_NUMBER", columnList = "RES_TYPE,SP_NAME,SP_VALUE"),
@Index(name = "IDX_SP_NUMBER_UPDATED", columnList = "SP_UPDATED"),
@Index(name = "IDX_SP_NUMBER_RESID", columnList = "RES_ID")
})
//@formatter:on

View File

@ -47,6 +47,7 @@ import ca.uhn.fhir.jpa.util.BigDecimalNumericFieldBridge;
@Entity
@Table(name = "HFJ_SPIDX_QUANTITY", indexes = {
@Index(name = "IDX_SP_QUANTITY", columnList = "RES_TYPE,SP_NAME,SP_SYSTEM,SP_UNITS,SP_VALUE"),
@Index(name = "IDX_SP_QUANTITY_UPDATED", columnList = "SP_UPDATED"),
@Index(name = "IDX_SP_QUANTITY_RESID", columnList = "RES_ID")
})
//@formatter:on

View File

@ -50,6 +50,7 @@ import org.hibernate.search.annotations.Store;
@Entity
@Table(name = "HFJ_SPIDX_STRING", indexes = {
@Index(name = "IDX_SP_STRING", columnList = "RES_TYPE,SP_NAME,SP_VALUE_NORMALIZED"),
@Index(name = "IDX_SP_STRING_UPDATED", columnList = "SP_UPDATED"),
@Index(name = "IDX_SP_STRING_RESID", columnList = "RES_ID")
})
@Indexed()

View File

@ -43,6 +43,7 @@ import org.hibernate.search.annotations.Field;
@Table(name = "HFJ_SPIDX_TOKEN", indexes = {
@Index(name = "IDX_SP_TOKEN", columnList = "RES_TYPE,SP_NAME,SP_SYSTEM,SP_VALUE"),
@Index(name = "IDX_SP_TOKEN_UNQUAL", columnList = "RES_TYPE,SP_NAME,SP_VALUE"),
@Index(name = "IDX_SP_TOKEN_UPDATED", columnList = "SP_UPDATED"),
@Index(name = "IDX_SP_TOKEN_RESID", columnList = "RES_ID")
})
//@formatter:on

View File

@ -42,6 +42,7 @@ import org.hibernate.search.annotations.Field;
@Table(name = "HFJ_SPIDX_URI", indexes = {
@Index(name = "IDX_SP_URI", columnList = "RES_TYPE,SP_NAME,SP_URI"),
@Index(name = "IDX_SP_URI_RESTYPE_NAME", columnList = "RES_TYPE,SP_NAME"),
@Index(name = "IDX_SP_URI_UPDATED", columnList = "SP_UPDATED"),
@Index(name = "IDX_SP_URI_COORDS", columnList = "RES_ID")
})
//@formatter:on

View File

@ -21,6 +21,7 @@ package ca.uhn.fhir.jpa.entity;
*/
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -32,6 +33,8 @@ import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.EqualsBuilder;
@ -88,22 +91,29 @@ public class ResourceLink implements Serializable {
@Field()
private String myTargetResourceUrl;
@Field()
@Column(name = "SP_UPDATED", nullable = true) // TODO: make this false after HAPI 2.3
@Temporal(TemporalType.TIMESTAMP)
private Date myUpdated;
public ResourceLink() {
super();
}
public ResourceLink(String theSourcePath, ResourceTable theSourceResource, ResourceTable theTargetResource) {
super();
setSourcePath(theSourcePath);
setSourceResource(theSourceResource);
setTargetResource(theTargetResource);
}
public ResourceLink(String theSourcePath, ResourceTable theSourceResource, IIdType theTargetResourceUrl) {
public ResourceLink(String theSourcePath, ResourceTable theSourceResource, IIdType theTargetResourceUrl, Date theUpdated) {
super();
setSourcePath(theSourcePath);
setSourceResource(theSourceResource);
setTargetResourceUrl(theTargetResourceUrl);
setUpdated(theUpdated);
}
public ResourceLink(String theSourcePath, ResourceTable theSourceResource, ResourceTable theTargetResource, Date theUpdated) {
super();
setSourcePath(theSourcePath);
setSourceResource(theSourceResource);
setTargetResource(theTargetResource);
setUpdated(theUpdated);
}
@Override
@ -150,6 +160,10 @@ public class ResourceLink implements Serializable {
return myTargetResourceUrl;
}
public Date getUpdated() {
return myUpdated;
}
@Override
public int hashCode() {
HashCodeBuilder b = new HashCodeBuilder();
@ -186,6 +200,10 @@ public class ResourceLink implements Serializable {
myTargetResourceUrl = theTargetResourceUrl.getValue();
}
public void setUpdated(Date theUpdated) {
myUpdated = theUpdated;
}
@Override
public String toString() {
StringBuilder b = new StringBuilder();