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