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  	@Override
71  	@PrePersist
72  	public void calculateHashes() {
73  		if (myHashIdentity == null) {
74  			String resourceType = getResourceType();
75  			String paramName = getParamName();
76  			setHashIdentity(calculateHashIdentity(resourceType, paramName));
77  		}
78  	}
79  
80  	@Override
81  	protected void clearHashes() {
82  		myHashIdentity = null;
83  	}
84  
85  	@Override
86  	public boolean equals(Object theObj) {
87  		if (this == theObj) {
88  			return true;
89  		}
90  		if (theObj == null) {
91  			return false;
92  		}
93  		if (!(theObj instanceof ResourceIndexedSearchParamCoords)) {
94  			return false;
95  		}
96  		ResourceIndexedSearchParamCoords obj = (ResourceIndexedSearchParamCoords) theObj;
97  		EqualsBuilder b = new EqualsBuilder();
98  		b.append(getParamName(), obj.getParamName());
99  		b.append(getResource(), obj.getResource());
100 		b.append(getLatitude(), obj.getLatitude());
101 		b.append(getLongitude(), obj.getLongitude());
102 		b.append(getHashIdentity(), obj.getHashIdentity());
103 		return b.isEquals();
104 	}
105 
106 	public Long getHashIdentity() {
107 		return myHashIdentity;
108 	}
109 
110 	public void setHashIdentity(Long theHashIdentity) {
111 		myHashIdentity = theHashIdentity;
112 	}
113 
114 	@Override
115 	protected Long getId() {
116 		return myId;
117 	}
118 
119 	public double getLatitude() {
120 		return myLatitude;
121 	}
122 
123 	public void setLatitude(double theLatitude) {
124 		myLatitude = theLatitude;
125 	}
126 
127 	public double getLongitude() {
128 		return myLongitude;
129 	}
130 
131 	public void setLongitude(double theLongitude) {
132 		myLongitude = theLongitude;
133 	}
134 
135 	@Override
136 	public int hashCode() {
137 		HashCodeBuilder b = new HashCodeBuilder();
138 		b.append(getParamName());
139 		b.append(getResource());
140 		b.append(getLatitude());
141 		b.append(getLongitude());
142 		return b.toHashCode();
143 	}
144 
145 	@Override
146 	public IQueryParameterType toQueryParameterType() {
147 		return null;
148 	}
149 
150 	@Override
151 	public String toString() {
152 		ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
153 		b.append("paramName", getParamName());
154 		b.append("resourceId", getResourcePid());
155 		b.append("lat", getLatitude());
156 		b.append("lon", getLongitude());
157 		return b.build();
158 	}
159 }