001/*-
002 * #%L
003 * HAPI FHIR JPA Model
004 * %%
005 * Copyright (C) 2014 - 2025 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.hapi.fhir.sql.hibernatesvc.PartitionedIdProperty;
023import jakarta.annotation.Nonnull;
024import jakarta.persistence.Column;
025import jakarta.persistence.Id;
026import jakarta.persistence.MappedSuperclass;
027
028import java.io.Serializable;
029import java.time.LocalDate;
030
031/**
032 * This is the base class for entities with partitioning that does NOT include Hibernate Envers logging.
033 * <p>
034 * If your entity needs Envers auditing, please have it extend {@link AuditableBasePartitionable} instead.
035 */
036@MappedSuperclass
037public abstract class BasePartitionable implements Serializable {
038
039        @SuppressWarnings("unused")
040        @Id
041        @PartitionedIdProperty
042        @Column(name = PartitionablePartitionId.PARTITION_ID)
043        Integer myPartitionIdValue;
044
045        @SuppressWarnings("unused")
046        @Column(name = PartitionablePartitionId.PARTITION_DATE, updatable = false, nullable = true)
047        private LocalDate myPartitionDateValue;
048
049        @Nonnull
050        public PartitionablePartitionId getPartitionId() {
051                return PartitionablePartitionId.with(myPartitionIdValue, myPartitionDateValue);
052        }
053
054        public void setPartitionId(PartitionablePartitionId thePartitionId) {
055                myPartitionIdValue = thePartitionId.getPartitionId();
056                myPartitionDateValue = thePartitionId.getPartitionDate();
057        }
058
059        @Override
060        public String toString() {
061                return "BasePartitionable{" + "myPartitionIdValue="
062                                + myPartitionIdValue + ", myPartitionDateValue="
063                                + myPartitionDateValue + '}';
064        }
065}