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 jakarta.persistence.Column;
023import jakarta.persistence.Entity;
024import jakarta.persistence.Id;
025import jakarta.persistence.Lob;
026import jakarta.persistence.Table;
027import jakarta.persistence.Temporal;
028import jakarta.persistence.TemporalType;
029import org.hibernate.Length;
030
031import java.sql.Blob;
032import java.util.Date;
033
034import static java.util.Objects.nonNull;
035
036@Entity
037@Table(name = "HFJ_BINARY_STORAGE")
038public class BinaryStorageEntity {
039
040        @Id
041        @Column(name = "CONTENT_ID", length = 200, nullable = false)
042        // N.B GGG: Note that the `content id` is the same as the `externalized binary id`.
043        private String myContentId;
044
045        @Column(name = "RESOURCE_ID", length = 100, nullable = false)
046        private String myResourceId;
047
048        @Column(name = "CONTENT_SIZE", nullable = true)
049        private long mySize;
050
051        @Column(name = "CONTENT_TYPE", nullable = false, length = 100)
052        private String myContentType;
053
054        @Deprecated(since = "7.2.0")
055        @Lob // TODO: VC column added in 7.2.0 - Remove non-VC column later
056        @Column(name = "BLOB_DATA", nullable = true, insertable = true, updatable = false)
057        private Blob myBlob;
058
059        @Column(name = "STORAGE_CONTENT_BIN", nullable = true, length = Length.LONG32)
060        private byte[] myStorageContentBin;
061
062        @Temporal(TemporalType.TIMESTAMP)
063        @Column(name = "PUBLISHED_DATE", nullable = false)
064        private Date myPublished;
065
066        @Column(name = "CONTENT_HASH", length = 128, nullable = true)
067        private String myHash;
068
069        public Date getPublished() {
070                return new Date(myPublished.getTime());
071        }
072
073        public void setPublished(Date thePublishedDate) {
074                myPublished = thePublishedDate;
075        }
076
077        public String getHash() {
078                return myHash;
079        }
080
081        public void setContentId(String theContentId) {
082                myContentId = theContentId;
083        }
084
085        public void setResourceId(String theResourceId) {
086                myResourceId = theResourceId;
087        }
088
089        public long getSize() {
090                return mySize;
091        }
092
093        public String getContentType() {
094                return myContentType;
095        }
096
097        public void setContentType(String theContentType) {
098                myContentType = theContentType;
099        }
100
101        public Blob getBlob() {
102                return myBlob;
103        }
104
105        public void setBlob(Blob theBlob) {
106                myBlob = theBlob;
107        }
108
109        public String getContentId() {
110                return myContentId;
111        }
112
113        public void setSize(long theSize) {
114                mySize = theSize;
115        }
116
117        public void setHash(String theHash) {
118                myHash = theHash;
119        }
120
121        public byte[] getStorageContentBin() {
122                return myStorageContentBin;
123        }
124
125        public BinaryStorageEntity setStorageContentBin(byte[] theStorageContentBin) {
126                myStorageContentBin = theStorageContentBin;
127                return this;
128        }
129
130        public boolean hasStorageContent() {
131                return nonNull(myStorageContentBin);
132        }
133
134        public boolean hasBlob() {
135                return nonNull(myBlob);
136        }
137}