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 org.apache.commons.lang3.Validate;
24  import org.apache.commons.lang3.builder.*;
25  
26  import javax.persistence.*;
27  
28  @Entity()
29  @Table(name = "HFJ_IDX_CMP_STRING_UNIQ", indexes = {
30  	@Index(name = ResourceIndexedCompositeStringUnique.IDX_IDXCMPSTRUNIQ_STRING, columnList = "IDX_STRING", unique = true),
31  	@Index(name = ResourceIndexedCompositeStringUnique.IDX_IDXCMPSTRUNIQ_RESOURCE, columnList = "RES_ID", unique = false)
32  })
33  public class ResourceIndexedCompositeStringUnique implements Comparable<ResourceIndexedCompositeStringUnique> {
34  
35  	public static final int MAX_STRING_LENGTH = 200;
36  	public static final String IDX_IDXCMPSTRUNIQ_STRING = "IDX_IDXCMPSTRUNIQ_STRING";
37  	public static final String IDX_IDXCMPSTRUNIQ_RESOURCE = "IDX_IDXCMPSTRUNIQ_RESOURCE";
38  
39  	@SequenceGenerator(name = "SEQ_IDXCMPSTRUNIQ_ID", sequenceName = "SEQ_IDXCMPSTRUNIQ_ID")
40  	@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_IDXCMPSTRUNIQ_ID")
41  	@Id
42  	@Column(name = "PID")
43  	private Long myId;
44  	@ManyToOne
45  	@JoinColumn(name = "RES_ID", referencedColumnName = "RES_ID", foreignKey = @ForeignKey(name = "FK_IDXCMPSTRUNIQ_RES_ID"))
46  	private ResourceTable myResource;
47  	@Column(name = "RES_ID", insertable = false, updatable = false)
48  	private Long myResourceId;
49  	@Column(name = "IDX_STRING", nullable = false, length = MAX_STRING_LENGTH)
50  	private String myIndexString;
51  
52  	/**
53  	 * Constructor
54  	 */
55  	public ResourceIndexedCompositeStringUnique() {
56  		super();
57  	}
58  
59  	/**
60  	 * Constructor
61  	 */
62  	public ResourceIndexedCompositeStringUnique(ResourceTable theResource, String theIndexString) {
63  		setResource(theResource);
64  		setIndexString(theIndexString);
65  	}
66  
67  	@Override
68  	public int compareTo(ResourceIndexedCompositeStringUnique theO) {
69  		CompareToBuilder b = new CompareToBuilder();
70  		b.append(myIndexString, theO.getIndexString());
71  		return b.toComparison();
72  	}
73  
74  	@Override
75  	public boolean equals(Object theO) {
76  		if (this == theO) return true;
77  
78  		if (!(theO instanceof ResourceIndexedCompositeStringUnique)) {
79  			return false;
80  		}
81  
82  		ResourceIndexedCompositeStringUnique that = (ResourceIndexedCompositeStringUnique) theO;
83  
84  		return new EqualsBuilder()
85  			.append(myIndexString, that.myIndexString)
86  			.isEquals();
87  	}
88  
89  	public String getIndexString() {
90  		return myIndexString;
91  	}
92  
93  	public void setIndexString(String theIndexString) {
94  		myIndexString = theIndexString;
95  	}
96  
97  	public ResourceTable getResource() {
98  		return myResource;
99  	}
100 
101 	public void setResource(ResourceTable theResource) {
102 		Validate.notNull(theResource);
103 		myResource = theResource;
104 	}
105 
106 	@Override
107 	public int hashCode() {
108 		return new HashCodeBuilder(17, 37)
109 			.append(myIndexString)
110 			.toHashCode();
111 	}
112 
113 	@Override
114 	public String toString() {
115 		return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
116 			.append("id", myId)
117 			.append("resourceId", myResourceId)
118 			.append("indexString", myIndexString)
119 			.toString();
120 	}
121 }