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  import javax.persistence.*;
23  
24  import org.apache.commons.lang3.builder.*;
25  
26  @Entity
27  @Table(name = "HFJ_RES_TAG", uniqueConstraints= {
28  		@UniqueConstraint(name="IDX_RESTAG_TAGID", columnNames= {"RES_ID","TAG_ID"})
29  })
30  public class ResourceTag extends BaseTag {
31  
32  	private static final long serialVersionUID = 1L;
33  
34  	@SequenceGenerator(name = "SEQ_RESTAG_ID", sequenceName = "SEQ_RESTAG_ID")
35  	@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_RESTAG_ID")
36  	@Id
37  	@Column(name = "PID")
38  	private Long myId;
39  
40  	@ManyToOne(cascade = {})
41  	@JoinColumn(name = "RES_ID", referencedColumnName = "RES_ID", foreignKey=@ForeignKey(name="FK_RESTAG_RESOURCE"))
42  	private ResourceTable myResource;
43  
44  	@Column(name = "RES_TYPE", length = ResourceTable.RESTYPE_LEN, nullable = false)
45  	private String myResourceType;
46  
47  	@Column(name = "RES_ID", insertable = false, updatable = false)
48  	private Long myResourceId;
49  
50  	public Long getResourceId() {
51  		return myResourceId;
52  	}
53  
54  	public void setResourceId(Long theResourceId) {
55  		myResourceId = theResourceId;
56  	}
57  
58  	public ResourceTag() {
59  	}
60  
61  	public ResourceTag(ResourceTable theResourceTable, TagDefinition theTag) {
62  		setTag(theTag);
63  		setResource(theResourceTable);
64  		setResourceId(theResourceTable.getId());
65  		setResourceType(theResourceTable.getResourceType());
66  	}
67  
68  	public ResourceTable getResource() {
69  		return myResource;
70  	}
71  
72  	public String getResourceType() {
73  		return myResourceType;
74  	}
75  
76  	public void setResource(ResourceTable theResource) {
77  		myResource = theResource;
78  	}
79  
80  	public void setResourceType(String theResourceType) {
81  		myResourceType = theResourceType;
82  	}
83  
84  	@Override
85  	public boolean equals(Object obj) {
86  		if (this == obj) {
87  			return true;
88  		}
89  		if (obj == null) {
90  			return false;
91  		}
92  		if (!(obj instanceof ResourceTag)) {
93  			return false;
94  		}
95  		ResourceTag other = (ResourceTag) obj;
96  		EqualsBuilder b = new EqualsBuilder();
97  		b.append(getResourceId(), other.getResourceId());
98  		b.append(getTag(), other.getTag());
99  		return b.isEquals();
100 	}
101 
102 	@Override
103 	public int hashCode() {
104 		HashCodeBuilder b = new HashCodeBuilder();
105 		b.append(getResourceId());
106 		b.append(getTag());
107 		return b.toHashCode();
108 	}
109 
110 	@Override
111 	public String toString() {
112 		ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
113 		b.append("resId", getResourceId());
114 		b.append("tag", getTag().getId());
115 		return b.build();
116 	}
117 
118 }