First attempt to introduce hibernate envers and use it for MdmLink.

This commit is contained in:
Luke deGruchy 2023-02-21 17:09:13 -05:00
parent 607f27b686
commit 51077e212f
11 changed files with 46 additions and 0 deletions

View File

@ -340,6 +340,12 @@
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-backend-elasticsearch-aws</artifactId>
</dependency>
<!--
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
</dependency>
-->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-phonetic</artifactId>

View File

@ -27,6 +27,7 @@ import ca.uhn.fhir.mdm.api.IMdmLink;
import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum;
import ca.uhn.fhir.mdm.api.MdmMatchResultEnum;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.envers.Audited;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -57,6 +58,7 @@ import java.util.Date;
}, indexes = {
@Index(name = "IDX_EMPI_MATCH_TGT_VER", columnList = "MATCH_RESULT, TARGET_PID, VERSION")
})
@Audited
public class MdmLink extends BasePartitionable implements IMdmLink<JpaPid> {
public static final int VERSION_LENGTH = 16;
private static final int MATCH_RESULT_LENGTH = 16;

View File

@ -99,6 +99,11 @@
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-backend-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<!-- <groupId>org.hibernate.orm</groupId>-->
<artifactId>hibernate-envers</artifactId>
</dependency>
<!-- Spring -->
<dependency>

View File

@ -26,15 +26,19 @@ import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.envers.Audited;
import org.hl7.fhir.instance.model.api.IIdType;
import javax.persistence.*;
import static org.hibernate.envers.RelationTargetAuditMode.NOT_AUDITED;
@Entity()
@Table(name = "HFJ_IDX_CMP_STRING_UNIQ", indexes = {
@Index(name = ResourceIndexedComboStringUnique.IDX_IDXCMPSTRUNIQ_STRING, columnList = "IDX_STRING", unique = true),
@Index(name = ResourceIndexedComboStringUnique.IDX_IDXCMPSTRUNIQ_RESOURCE, columnList = "RES_ID", unique = false)
})
@Audited(targetAuditMode = NOT_AUDITED)
public class ResourceIndexedComboStringUnique extends BasePartitionable implements Comparable<ResourceIndexedComboStringUnique>, IResourceIndexComboSearchParameter {
public static final int MAX_STRING_LENGTH = 500;

View File

@ -27,6 +27,7 @@ import org.apache.commons.lang3.builder.CompareToBuilder;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.envers.Audited;
import org.hl7.fhir.instance.model.api.IIdType;
import javax.persistence.Column;
@ -43,12 +44,14 @@ import javax.persistence.Table;
import javax.persistence.Transient;
import static ca.uhn.fhir.jpa.model.entity.BaseResourceIndexedSearchParam.hash;
import static org.hibernate.envers.RelationTargetAuditMode.NOT_AUDITED;
@Entity
@Table(name = "HFJ_IDX_CMB_TOK_NU", indexes = {
@Index(name = "IDX_IDXCMBTOKNU_STR", columnList = "IDX_STRING", unique = false),
@Index(name = "IDX_IDXCMBTOKNU_RES", columnList = "RES_ID", unique = false)
})
@Audited(targetAuditMode = NOT_AUDITED)
public class ResourceIndexedComboTokenNonUnique extends BaseResourceIndex implements Comparable<ResourceIndexedComboTokenNonUnique>, IResourceIndexComboSearchParameter {
@SequenceGenerator(name = "SEQ_IDXCMBTOKNU_ID", sequenceName = "SEQ_IDXCMBTOKNU_ID")

View File

@ -26,6 +26,7 @@ import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.envers.Audited;
import javax.persistence.Column;
import javax.persistence.Embeddable;
@ -41,6 +42,8 @@ import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import static org.hibernate.envers.RelationTargetAuditMode.NOT_AUDITED;
@Embeddable
@Entity
@Table(name = "HFJ_SPIDX_COORDS", indexes = {
@ -48,6 +51,7 @@ import javax.persistence.Table;
@Index(name = "IDX_SP_COORDS_UPDATED", columnList = "SP_UPDATED"),
@Index(name = "IDX_SP_COORDS_RESID", columnList = "RES_ID")
})
@Audited(targetAuditMode = NOT_AUDITED)
public class ResourceIndexedSearchParamCoords extends BaseResourceIndexedSearchParam {
public static final int MAX_LENGTH = 100;

View File

@ -46,6 +46,7 @@ import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.envers.Audited;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField;
import org.hl7.fhir.r4.model.DateTimeType;
@ -57,6 +58,8 @@ import ca.uhn.fhir.rest.param.DateParam;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.util.DateUtils;
import static org.hibernate.envers.RelationTargetAuditMode.NOT_AUDITED;
@Embeddable
@Entity
@Table(name = "HFJ_SPIDX_DATE", indexes = {
@ -67,6 +70,7 @@ import ca.uhn.fhir.util.DateUtils;
@Index(name = "IDX_SP_DATE_ORD_HASH_HIGH_V2", columnList = "HASH_IDENTITY,SP_VALUE_HIGH_DATE_ORDINAL,RES_ID,PARTITION_ID"),
@Index(name = "IDX_SP_DATE_RESID_V2", columnList = "RES_ID,HASH_IDENTITY,SP_VALUE_LOW,SP_VALUE_HIGH,SP_VALUE_LOW_DATE_ORDINAL,SP_VALUE_HIGH_DATE_ORDINAL,PARTITION_ID"),
})
@Audited(targetAuditMode = NOT_AUDITED)
public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchParam {
private static final long serialVersionUID = 1L;

View File

@ -27,6 +27,7 @@ import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.envers.Audited;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.ScaledNumberField;
import javax.persistence.Column;
@ -45,6 +46,8 @@ import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Objects;
import static org.hibernate.envers.RelationTargetAuditMode.NOT_AUDITED;
@Embeddable
@Entity
@Table(name = "HFJ_SPIDX_NUMBER", indexes = {
@ -52,6 +55,7 @@ import java.util.Objects;
@Index(name = "IDX_SP_NUMBER_HASH_VAL_V2", columnList = "HASH_IDENTITY,SP_VALUE,RES_ID,PARTITION_ID"),
@Index(name = "IDX_SP_NUMBER_RESID_V2", columnList = "RES_ID, HASH_IDENTITY, SP_VALUE, PARTITION_ID")
})
@Audited(targetAuditMode = NOT_AUDITED)
public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchParam {
private static final long serialVersionUID = 1L;

View File

@ -26,6 +26,7 @@ import ca.uhn.fhir.rest.param.QuantityParam;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.envers.Audited;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.ScaledNumberField;
import javax.persistence.Column;
@ -46,6 +47,7 @@ import java.util.Objects;
import static org.apache.commons.lang3.StringUtils.defaultString;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.hibernate.envers.RelationTargetAuditMode.NOT_AUDITED;
//@formatter:off
@Embeddable
@ -57,6 +59,7 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
@Index(name = "IDX_SP_QUANTITY_HASH_SYSUN_V2", columnList = "HASH_IDENTITY_SYS_UNITS,SP_VALUE,RES_ID,PARTITION_ID"),
@Index(name = "IDX_SP_QUANTITY_RESID_V2", columnList = "RES_ID,HASH_IDENTITY,HASH_IDENTITY_SYS_UNITS,HASH_IDENTITY_AND_UNITS,SP_VALUE,PARTITION_ID")
})
@Audited(targetAuditMode = NOT_AUDITED)
public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearchParamQuantity {
private static final long serialVersionUID = 1L;

View File

@ -37,6 +37,7 @@ import org.hibernate.Session;
import org.hibernate.annotations.GenerationTime;
import org.hibernate.annotations.GeneratorType;
import org.hibernate.annotations.OptimisticLock;
import org.hibernate.envers.Audited;
import org.hibernate.search.engine.backend.types.Projectable;
import org.hibernate.search.engine.backend.types.Searchable;
import org.hibernate.search.mapper.pojo.bridge.mapping.annotation.PropertyBinderRef;
@ -76,6 +77,8 @@ import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import static org.hibernate.envers.RelationTargetAuditMode.NOT_AUDITED;
@Indexed(routingBinder= @RoutingBinderRef(type = ResourceTableRoutingBinder.class))
@Entity
@Table(name = "HFJ_RESOURCE", uniqueConstraints = {}, indexes = {
@ -84,6 +87,7 @@ import java.util.stream.Collectors;
@Index(name = "IDX_RES_TYPE_DEL_UPDATED", columnList = "RES_TYPE,RES_DELETED_AT,RES_UPDATED,PARTITION_ID,RES_ID"),
})
@NamedEntityGraph(name = "Resource.noJoins")
@Audited(targetAuditMode = NOT_AUDITED)
public class ResourceTable extends BaseHasResource implements Serializable, IBasePersistedResource, IResourceLookup {
public static final int RESTYPE_LEN = 40;
private static final int MAX_LANGUAGE_LENGTH = 20;

View File

@ -1759,6 +1759,13 @@
</exclusions>
</dependency>
<dependency>
<!-- <groupId>org.hibernate.orm</groupId>-->
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
<version>${hibernate_version}</version>
<!-- <version>${hibernate_search_version}</version>-->
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate_validator_version}</version>