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 org.apache.commons.lang3.builder.EqualsBuilder; 024import org.apache.commons.lang3.builder.HashCodeBuilder; 025import org.apache.commons.lang3.builder.ToStringBuilder; 026import org.apache.commons.lang3.builder.ToStringStyle; 027 028import javax.persistence.Column; 029import javax.persistence.Entity; 030import javax.persistence.FetchType; 031import javax.persistence.ForeignKey; 032import javax.persistence.GeneratedValue; 033import javax.persistence.GenerationType; 034import javax.persistence.Id; 035import javax.persistence.JoinColumn; 036import javax.persistence.ManyToOne; 037import javax.persistence.SequenceGenerator; 038import javax.persistence.Table; 039import javax.persistence.UniqueConstraint; 040 041@Entity 042@Table(name = "HFJ_RES_TAG", uniqueConstraints = { 043 @UniqueConstraint(name = "IDX_RESTAG_TAGID", columnNames = {"RES_ID", "TAG_ID"}) 044}) 045public class ResourceTag extends BaseTag { 046 047 private static final long serialVersionUID = 1L; 048 049 @SequenceGenerator(name = "SEQ_RESTAG_ID", sequenceName = "SEQ_RESTAG_ID") 050 @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_RESTAG_ID") 051 @Id 052 @Column(name = "PID") 053 private Long myId; 054 055 @ManyToOne(cascade = {}, fetch = FetchType.LAZY) 056 @JoinColumn(name = "RES_ID", referencedColumnName = "RES_ID", foreignKey = @ForeignKey(name = "FK_RESTAG_RESOURCE")) 057 private ResourceTable myResource; 058 059 @Column(name = "RES_TYPE", length = ResourceTable.RESTYPE_LEN, nullable = false) 060 private String myResourceType; 061 062 @Column(name = "RES_ID", insertable = false, updatable = false) 063 private Long myResourceId; 064 065 /** 066 * Constructor 067 */ 068 public ResourceTag() { 069 super(); 070 } 071 072 /** 073 * Constructor 074 */ 075 public ResourceTag(ResourceTable theResourceTable, TagDefinition theTag, PartitionablePartitionId theRequestPartitionId) { 076 setTag(theTag); 077 setResource(theResourceTable); 078 setResourceId(theResourceTable.getId()); 079 setResourceType(theResourceTable.getResourceType()); 080 setPartitionId(theRequestPartitionId); 081 } 082 083 public Long getResourceId() { 084 return myResourceId; 085 } 086 087 public void setResourceId(Long theResourceId) { 088 myResourceId = theResourceId; 089 } 090 091 public ResourceTable getResource() { 092 return myResource; 093 } 094 095 public void setResource(ResourceTable theResource) { 096 myResource = theResource; 097 } 098 099 public String getResourceType() { 100 return myResourceType; 101 } 102 103 public void setResourceType(String theResourceType) { 104 myResourceType = theResourceType; 105 } 106 107 @Override 108 public boolean equals(Object obj) { 109 if (this == obj) { 110 return true; 111 } 112 if (obj == null) { 113 return false; 114 } 115 if (!(obj instanceof ResourceTag)) { 116 return false; 117 } 118 ResourceTag other = (ResourceTag) obj; 119 EqualsBuilder b = new EqualsBuilder(); 120 b.append(getResourceId(), other.getResourceId()); 121 b.append(getTag(), other.getTag()); 122 return b.isEquals(); 123 } 124 125 @Override 126 public int hashCode() { 127 HashCodeBuilder b = new HashCodeBuilder(); 128 b.append(getResourceId()); 129 b.append(getTag()); 130 return b.toHashCode(); 131 } 132 133 @Override 134 public String toString() { 135 ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); 136 if (getPartitionId() != null) { 137 b.append("partition", getPartitionId().getPartitionId()); 138 } 139 b.append("resId", getResourceId()); 140 b.append("tag", getTag().getId()); 141 return b.build(); 142 } 143 144}