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.fhir.rest.api.server.storage.IResourceVersionPersistentId; 023import ca.uhn.hapi.fhir.sql.hibernatesvc.PartitionedIdProperty; 024import jakarta.persistence.Column; 025import jakarta.persistence.Embeddable; 026import jakarta.persistence.GeneratedValue; 027import jakarta.persistence.GenerationType; 028import org.hibernate.annotations.GenericGenerator; 029 030import java.io.Serializable; 031import java.util.Objects; 032 033@Embeddable 034public class ResourceHistoryTablePk implements IResourceVersionPersistentId, Serializable { 035 036 @GenericGenerator( 037 name = "SEQ_RESOURCE_HISTORY_ID", 038 type = ca.uhn.fhir.jpa.model.dialect.HapiSequenceStyleGenerator.class) 039 @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_RESOURCE_HISTORY_ID") 040 @Column(name = "PID") 041 private Long myVersionId; 042 043 @PartitionedIdProperty 044 @Column(name = PartitionablePartitionId.PARTITION_ID) 045 private Integer myPartitionIdValue; 046 047 @Override 048 public boolean equals(Object theO) { 049 if (this == theO) { 050 return true; 051 } 052 if (!(theO instanceof ResourceHistoryTablePk)) { 053 return false; 054 } 055 ResourceHistoryTablePk that = (ResourceHistoryTablePk) theO; 056 return Objects.equals(myVersionId, that.myVersionId) 057 && Objects.equals(myPartitionIdValue, that.myPartitionIdValue); 058 } 059 060 @Override 061 public int hashCode() { 062 return Objects.hash(myVersionId, myPartitionIdValue); 063 } 064 065 public void setPartitionIdValue(Integer thePartitionIdValue) { 066 myPartitionIdValue = thePartitionIdValue; 067 } 068 069 public Long getId() { 070 return myVersionId; 071 } 072 073 public Integer getPartitionId() { 074 return myPartitionIdValue; 075 } 076 077 public IdAndPartitionId asIdAndPartitionId() { 078 return new IdAndPartitionId(getId(), getPartitionId()); 079 } 080 081 @Override 082 public String toString() { 083 return myVersionId + "/" + myPartitionIdValue; 084 } 085}