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.jpa.util.BigDecimalNumericFieldBridge;
24  import ca.uhn.fhir.model.api.IQueryParameterType;
25  import ca.uhn.fhir.rest.param.NumberParam;
26  import org.apache.commons.lang3.builder.EqualsBuilder;
27  import org.apache.commons.lang3.builder.HashCodeBuilder;
28  import org.apache.commons.lang3.builder.ToStringBuilder;
29  import org.apache.commons.lang3.builder.ToStringStyle;
30  import org.hibernate.search.annotations.Field;
31  import org.hibernate.search.annotations.FieldBridge;
32  import org.hibernate.search.annotations.NumericField;
33  
34  import javax.persistence.*;
35  import java.math.BigDecimal;
36  
37  //@formatter:off
38  @Embeddable
39  @Entity
40  @Table(name = "HFJ_SPIDX_NUMBER", indexes = {
41  	@Index(name = "IDX_SP_NUMBER", columnList = "RES_TYPE,SP_NAME,SP_VALUE"),
42  	@Index(name = "IDX_SP_NUMBER_UPDATED", columnList = "SP_UPDATED"),
43  	@Index(name = "IDX_SP_NUMBER_RESID", columnList = "RES_ID")
44  })
45  //@formatter:on
46  public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchParam {
47  
48  	private static final long serialVersionUID = 1L;
49  	@Column(name = "SP_VALUE", nullable = true)
50  	@Field
51  	@NumericField
52  	@FieldBridge(impl = BigDecimalNumericFieldBridge.class)
53  	public BigDecimal myValue;
54  	@Id
55  	@SequenceGenerator(name = "SEQ_SPIDX_NUMBER", sequenceName = "SEQ_SPIDX_NUMBER")
56  	@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_SPIDX_NUMBER")
57  	@Column(name = "SP_ID")
58  	private Long myId;
59  
60  	public ResourceIndexedSearchParamNumber() {
61  	}
62  
63  	public ResourceIndexedSearchParamNumber(String theParamName, BigDecimal theValue) {
64  		setParamName(theParamName);
65  		setValue(theValue);
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 ResourceIndexedSearchParamNumber)) {
77  			return false;
78  		}
79  		ResourceIndexedSearchParamNumber obj = (ResourceIndexedSearchParamNumber) theObj;
80  		EqualsBuilder b = new EqualsBuilder();
81  		b.append(getParamName(), obj.getParamName());
82  		b.append(getResource(), obj.getResource());
83  		b.append(getValue(), obj.getValue());
84  		b.append(isMissing(), obj.isMissing());
85  		return b.isEquals();
86  	}
87  
88  	@Override
89  	protected Long getId() {
90  		return myId;
91  	}
92  
93  	public BigDecimal getValue() {
94  		return myValue;
95  	}
96  
97  	public void setValue(BigDecimal theValue) {
98  		myValue = theValue;
99  	}
100 
101 	@Override
102 	public int hashCode() {
103 		HashCodeBuilder b = new HashCodeBuilder();
104 		b.append(getParamName());
105 		b.append(getResource());
106 		b.append(getValue());
107 		b.append(isMissing());
108 		return b.toHashCode();
109 	}
110 
111 	@Override
112 	public IQueryParameterType toQueryParameterType() {
113 		return new NumberParam(myValue.toPlainString());
114 	}
115 
116 	@Override
117 	public String toString() {
118 		ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
119 		b.append("paramName", getParamName());
120 		b.append("resourceId", getResource().getId()); // TODO: add a field so we don't need to resolve this
121 		b.append("value", getValue());
122 		return b.build();
123 	}
124 }