View Javadoc
1   package ca.uhn.fhir.jpa.entity;
2   
3   /*
4    * #%L
5    * HAPI FHIR JPA Server
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import ca.uhn.fhir.model.api.IQueryParameterType;
24  import org.apache.commons.lang3.builder.EqualsBuilder;
25  import org.apache.commons.lang3.builder.HashCodeBuilder;
26  import org.apache.commons.lang3.builder.ToStringBuilder;
27  import org.apache.commons.lang3.builder.ToStringStyle;
28  import org.hibernate.search.annotations.Field;
29  
30  import javax.persistence.*;
31  
32  @Embeddable
33  @Entity
34  @Table(name = "HFJ_SPIDX_COORDS", indexes = {
35  	@Index(name = "IDX_SP_COORDS_HASH", columnList = "HASH_IDENTITY,SP_LATITUDE,SP_LONGITUDE"),
36  	@Index(name = "IDX_SP_COORDS_UPDATED", columnList = "SP_UPDATED"),
37  	@Index(name = "IDX_SP_COORDS_RESID", columnList = "RES_ID")
38  })
39  public class ResourceIndexedSearchParamCoords extends BaseResourceIndexedSearchParam {
40  
41  	public static final int MAX_LENGTH = 100;
42  
43  	private static final long serialVersionUID = 1L;
44  	@Column(name = "SP_LATITUDE")
45  	@Field
46  	public double myLatitude;
47  	@Column(name = "SP_LONGITUDE")
48  	@Field
49  	public double myLongitude;
50  	@Id
51  	@SequenceGenerator(name = "SEQ_SPIDX_COORDS", sequenceName = "SEQ_SPIDX_COORDS")
52  	@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_SPIDX_COORDS")
53  	@Column(name = "SP_ID")
54  	private Long myId;
55  	/**
56  	 * @since 3.5.0 - At some point this should be made not-null
57  	 */
58  	@Column(name = "HASH_IDENTITY", nullable = true)
59  	private Long myHashIdentity;
60  
61  	public ResourceIndexedSearchParamCoords() {
62  	}
63  
64  	public ResourceIndexedSearchParamCoords(String theName, double theLatitude, double theLongitude) {
65  		setParamName(theName);
66  		setLatitude(theLatitude);
67  		setLongitude(theLongitude);
68  	}
69  
70  	@PrePersist
71  	public void calculateHashes() {
72  		if (myHashIdentity == null) {
73  			String resourceType = getResourceType();
74  			String paramName = getParamName();
75  			setHashIdentity(calculateHashIdentity(resourceType, paramName));
76  		}
77  	}
78  
79  	@Override
80  	protected void clearHashes() {
81  		myHashIdentity = null;
82  	}
83  
84  	@Override
85  	public boolean equals(Object theObj) {
86  		if (this == theObj) {
87  			return true;
88  		}
89  		if (theObj == null) {
90  			return false;
91  		}
92  		if (!(theObj instanceof ResourceIndexedSearchParamCoords)) {
93  			return false;
94  		}
95  		ResourceIndexedSearchParamCoords obj = (ResourceIndexedSearchParamCoords) theObj;
96  		EqualsBuilder b = new EqualsBuilder();
97  		b.append(getParamName(), obj.getParamName());
98  		b.append(getResource(), obj.getResource());
99  		b.append(getLatitude(), obj.getLatitude());
100 		b.append(getLongitude(), obj.getLongitude());
101 		b.append(getHashIdentity(), obj.getHashIdentity());
102 		return b.isEquals();
103 	}
104 
105 	public Long getHashIdentity() {
106 		return myHashIdentity;
107 	}
108 
109 	public void setHashIdentity(Long theHashIdentity) {
110 		myHashIdentity = theHashIdentity;
111 	}
112 
113 	@Override
114 	protected Long getId() {
115 		return myId;
116 	}
117 
118 	public double getLatitude() {
119 		return myLatitude;
120 	}
121 
122 	public void setLatitude(double theLatitude) {
123 		myLatitude = theLatitude;
124 	}
125 
126 	public double getLongitude() {
127 		return myLongitude;
128 	}
129 
130 	public void setLongitude(double theLongitude) {
131 		myLongitude = theLongitude;
132 	}
133 
134 	@Override
135 	public int hashCode() {
136 		HashCodeBuilder b = new HashCodeBuilder();
137 		b.append(getParamName());
138 		b.append(getResource());
139 		b.append(getLatitude());
140 		b.append(getLongitude());
141 		return b.toHashCode();
142 	}
143 
144 	@Override
145 	public IQueryParameterType toQueryParameterType() {
146 		return null;
147 	}
148 
149 	@Override
150 	public String toString() {
151 		ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
152 		b.append("paramName", getParamName());
153 		b.append("resourceId", getResourcePid());
154 		b.append("lat", getLatitude());
155 		b.append("lon", getLongitude());
156 		return b.build();
157 	}
158 }