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 javax.persistence.Column; 024import javax.persistence.MappedSuperclass; 025 026import org.apache.commons.lang3.builder.HashCodeBuilder; 027import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField; 028 029import ca.uhn.fhir.interceptor.model.RequestPartitionId; 030import ca.uhn.fhir.jpa.model.config.PartitionSettings; 031 032@MappedSuperclass 033public abstract class ResourceIndexedSearchParamBaseQuantity extends BaseResourceIndexedSearchParam { 034 035 private static final int MAX_LENGTH = 200; 036 037 private static final long serialVersionUID = 1L; 038 039 @Column(name = "SP_SYSTEM", nullable = true, length = MAX_LENGTH) 040 @FullTextField 041 public String mySystem; 042 043 @Column(name = "SP_UNITS", nullable = true, length = MAX_LENGTH) 044 @FullTextField 045 public String myUnits; 046 047 /** 048 * @since 3.5.0 - At some point this should be made not-null 049 */ 050 @Column(name = "HASH_IDENTITY_AND_UNITS", nullable = true) 051 private Long myHashIdentityAndUnits; 052 /** 053 * @since 3.5.0 - At some point this should be made not-null 054 */ 055 @Column(name = "HASH_IDENTITY_SYS_UNITS", nullable = true) 056 private Long myHashIdentitySystemAndUnits; 057 /** 058 * @since 3.5.0 - At some point this should be made not-null 059 */ 060 @Column(name = "HASH_IDENTITY", nullable = true) 061 private Long myHashIdentity; 062 063 /** 064 * Constructor 065 */ 066 public ResourceIndexedSearchParamBaseQuantity() { 067 super(); 068 } 069 070 @Override 071 public void clearHashes() { 072 myHashIdentity = null; 073 myHashIdentityAndUnits = null; 074 myHashIdentitySystemAndUnits = null; 075 } 076 077 @Override 078 public void calculateHashes() { 079 if (myHashIdentity != null || myHashIdentityAndUnits != null || myHashIdentitySystemAndUnits != null) { 080 return; 081 } 082 083 String resourceType = getResourceType(); 084 String paramName = getParamName(); 085 String units = getUnits(); 086 String system = getSystem(); 087 setHashIdentity(calculateHashIdentity(getPartitionSettings(), getPartitionId(), resourceType, paramName)); 088 setHashIdentityAndUnits(calculateHashUnits(getPartitionSettings(), getPartitionId(), resourceType, paramName, units)); 089 setHashIdentitySystemAndUnits(calculateHashSystemAndUnits(getPartitionSettings(), getPartitionId(), resourceType, paramName, system, units)); 090 } 091 092 public Long getHashIdentity() { 093 return myHashIdentity; 094 } 095 096 public void setHashIdentity(Long theHashIdentity) { 097 myHashIdentity = theHashIdentity; 098 } 099 100 public Long getHashIdentityAndUnits() { 101 return myHashIdentityAndUnits; 102 } 103 104 public void setHashIdentityAndUnits(Long theHashIdentityAndUnits) { 105 myHashIdentityAndUnits = theHashIdentityAndUnits; 106 } 107 108 public Long getHashIdentitySystemAndUnits() { 109 return myHashIdentitySystemAndUnits; 110 } 111 112 public void setHashIdentitySystemAndUnits(Long theHashIdentitySystemAndUnits) { 113 myHashIdentitySystemAndUnits = theHashIdentitySystemAndUnits; 114 } 115 116 public String getSystem() { 117 return mySystem; 118 } 119 120 public void setSystem(String theSystem) { 121 mySystem = theSystem; 122 } 123 124 public String getUnits() { 125 return myUnits; 126 } 127 128 public void setUnits(String theUnits) { 129 myUnits = theUnits; 130 } 131 132 @Override 133 public int hashCode() { 134 HashCodeBuilder b = new HashCodeBuilder(); 135 b.append(getResourceType()); 136 b.append(getParamName()); 137 b.append(getHashIdentity()); 138 b.append(getHashIdentityAndUnits()); 139 b.append(getHashIdentitySystemAndUnits()); 140 return b.toHashCode(); 141 } 142 143 144 public static long calculateHashSystemAndUnits(PartitionSettings thePartitionSettings, PartitionablePartitionId theRequestPartitionId, String theResourceType, String theParamName, String theSystem, String theUnits) { 145 RequestPartitionId requestPartitionId = PartitionablePartitionId.toRequestPartitionId(theRequestPartitionId); 146 return calculateHashSystemAndUnits(thePartitionSettings, requestPartitionId, theResourceType, theParamName, theSystem, theUnits); 147 } 148 149 public static long calculateHashSystemAndUnits(PartitionSettings thePartitionSettings, RequestPartitionId theRequestPartitionId, String theResourceType, String theParamName, String theSystem, String theUnits) { 150 return hash(thePartitionSettings, theRequestPartitionId, theResourceType, theParamName, theSystem, theUnits); 151 } 152 153 public static long calculateHashUnits(PartitionSettings thePartitionSettings, PartitionablePartitionId theRequestPartitionId, String theResourceType, String theParamName, String theUnits) { 154 RequestPartitionId requestPartitionId = PartitionablePartitionId.toRequestPartitionId(theRequestPartitionId); 155 return calculateHashUnits(thePartitionSettings, requestPartitionId, theResourceType, theParamName, theUnits); 156 } 157 158 public static long calculateHashUnits(PartitionSettings thePartitionSettings, RequestPartitionId theRequestPartitionId, String theResourceType, String theParamName, String theUnits) { 159 return hash(thePartitionSettings, theRequestPartitionId, theResourceType, theParamName, theUnits); 160 } 161}