001package ca.uhn.fhir.jpa.model.entity; 002 003/*- 004 * #%L 005 * HAPI FHIR JPA Model 006 * %% 007 * Copyright (C) 2014 - 2022 Smile CDR, Inc. 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import ca.uhn.fhir.rest.api.Constants; 024import org.apache.commons.lang3.builder.ToStringBuilder; 025import org.apache.commons.lang3.builder.ToStringStyle; 026 027import javax.persistence.Column; 028import javax.persistence.Entity; 029import javax.persistence.FetchType; 030import javax.persistence.ForeignKey; 031import javax.persistence.Id; 032import javax.persistence.Index; 033import javax.persistence.JoinColumn; 034import javax.persistence.ManyToOne; 035import javax.persistence.MapsId; 036import javax.persistence.OneToOne; 037import javax.persistence.Table; 038 039@Table(name = "HFJ_RES_VER_PROV", indexes = { 040 @Index(name = "IDX_RESVERPROV_SOURCEURI", columnList = "SOURCE_URI"), 041 @Index(name = "IDX_RESVERPROV_REQUESTID", columnList = "REQUEST_ID"), 042 //@Index(name = "IDX_RESVERPROV_RESID", columnList = "RES_PID") 043}) 044@Entity 045public class ResourceHistoryProvenanceEntity extends BasePartitionable { 046 047 public static final int SOURCE_URI_LENGTH = 100; 048 049 @Id 050 @Column(name = "RES_VER_PID") 051 private Long myId; 052 @OneToOne(fetch = FetchType.LAZY) 053 @JoinColumn(name = "RES_VER_PID", referencedColumnName = "PID", foreignKey = @ForeignKey(name = "FK_RESVERPROV_RESVER_PID"), nullable = false, insertable = false, updatable = false) 054 @MapsId 055 private ResourceHistoryTable myResourceHistoryTable; 056 @ManyToOne(fetch = FetchType.LAZY) 057 @JoinColumn(name = "RES_PID", referencedColumnName = "RES_ID", foreignKey = @ForeignKey(name = "FK_RESVERPROV_RES_PID"), nullable = false) 058 private ResourceTable myResourceTable; 059 @Column(name = "SOURCE_URI", length = SOURCE_URI_LENGTH, nullable = true) 060 private String mySourceUri; 061 @Column(name = "REQUEST_ID", length = Constants.REQUEST_ID_LENGTH, nullable = true) 062 private String myRequestId; 063 064 /** 065 * Constructor 066 */ 067 public ResourceHistoryProvenanceEntity() { 068 super(); 069 } 070 071 @Override 072 public String toString() { 073 ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); 074 b.append("resourceId", myResourceTable.getId()); 075 b.append("sourceUri", mySourceUri); 076 b.append("requestId", myRequestId); 077 return b.toString(); 078 } 079 080 public void setResourceTable(ResourceTable theResourceTable) { 081 myResourceTable = theResourceTable; 082 } 083 084 public void setResourceHistoryTable(ResourceHistoryTable theResourceHistoryTable) { 085 myResourceHistoryTable = theResourceHistoryTable; 086 } 087 088 public String getSourceUri() { 089 return mySourceUri; 090 } 091 092 public void setSourceUri(String theSourceUri) { 093 mySourceUri = theSourceUri; 094 } 095 096 public String getRequestId() { 097 return myRequestId; 098 } 099 100 public void setRequestId(String theRequestId) { 101 myRequestId = theRequestId; 102 } 103 104 public Long getId() { 105 return myId; 106 } 107 108 109}