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", columnList = "RES_TYPE,SP_NAME,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  
45  	@Id
46  	@SequenceGenerator(name = "SEQ_SPIDX_COORDS", sequenceName = "SEQ_SPIDX_COORDS")
47  	@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_SPIDX_COORDS")
48  	@Column(name = "SP_ID")
49  	private Long myId;
50  
51  	@Column(name = "SP_LATITUDE")
52  	@Field
53  	public double myLatitude;
54  
55  	@Column(name = "SP_LONGITUDE")
56  	@Field
57  	public double myLongitude;
58  
59  	public ResourceIndexedSearchParamCoords() {
60  	}
61  
62  	public ResourceIndexedSearchParamCoords(String theName, double theLatitude, double theLongitude) {
63  		setParamName(theName);
64  		setLatitude(theLatitude);
65  		setLongitude(theLongitude);
66  	}
67  
68  	@Override
69  	public boolean equals(Object theObj) {
70  		if (this == theObj) {
71  			return true;
72  		}
73  		if (theObj == null) {
74  			return false;
75  		}
76  		if (!(theObj instanceof ResourceIndexedSearchParamCoords)) {
77  			return false;
78  		}
79  		ResourceIndexedSearchParamCoords obj = (ResourceIndexedSearchParamCoords) theObj;
80  		EqualsBuilder b = new EqualsBuilder();
81  		b.append(getParamName(), obj.getParamName());
82  		b.append(getResource(), obj.getResource());
83  		b.append(getLatitude(), obj.getLatitude());
84  		b.append(getLongitude(), obj.getLongitude());
85  		return b.isEquals();
86  	}
87  
88  	@Override
89  	protected Long getId() {
90  		return myId;
91  	}
92  
93  	@Override
94  	public IQueryParameterType toQueryParameterType() {
95  		return null;
96  	}
97  
98  	public double getLatitude() {
99  		return myLatitude;
100 	}
101 
102 	public double getLongitude() {
103 		return myLongitude;
104 	}
105 
106 	@Override
107 	public int hashCode() {
108 		HashCodeBuilder b = new HashCodeBuilder();
109 		b.append(getParamName());
110 		b.append(getResource());
111 		b.append(getLatitude());
112 		b.append(getLongitude());
113 		return b.toHashCode();
114 	}
115 
116 	public void setLatitude(double theLatitude) {
117 		myLatitude = theLatitude;
118 	}
119 
120 	public void setLongitude(double theLongitude) {
121 		myLongitude = theLongitude;
122 	}
123 
124 	@Override
125 	public String toString() {
126 		ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
127 		b.append("paramName", getParamName());
128 		b.append("resourceId", getResourcePid());
129 		b.append("lat", getLatitude());
130 		b.append("lon", getLongitude());
131 		return b.build();
132 	}
133 }