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 java.io.Serializable;
24  import java.util.Collection;
25  
26  import javax.persistence.*;
27  
28  import org.apache.commons.lang3.builder.EqualsBuilder;
29  import org.apache.commons.lang3.builder.HashCodeBuilder;
30  import org.apache.commons.lang3.builder.ToStringBuilder;
31  import org.apache.commons.lang3.builder.ToStringStyle;
32  
33  import ca.uhn.fhir.model.api.Tag;
34  
35  //@formatter:on
36  @Entity
37  @Table(name = "HFJ_TAG_DEF", uniqueConstraints = {
38  		@UniqueConstraint(name = "IDX_TAGDEF_TYPESYSCODE", columnNames = { "TAG_TYPE", "TAG_SYSTEM", "TAG_CODE" })
39  })
40  //@formatter:off
41  public class TagDefinition implements Serializable {
42  
43  	private static final long serialVersionUID = 1L;
44  
45  	@Column(name = "TAG_CODE", length = 200)
46  	private String myCode;
47  
48  	@Column(name = "TAG_DISPLAY", length = 200)
49  	private String myDisplay;
50  
51  	@Id
52  	@GeneratedValue(strategy = GenerationType.AUTO, generator="SEQ_TAGDEF_ID")
53  	@SequenceGenerator(name = "SEQ_TAGDEF_ID", sequenceName = "SEQ_TAGDEF_ID")
54  	@Column(name = "TAG_ID")
55  	private Long myId;
56  
57  	@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "myTag")
58  	private Collection<ResourceTag> myResources;
59  
60  	@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "myTag")
61  	private Collection<ResourceHistoryTag> myResourceVersions;
62  
63  	@Column(name = "TAG_SYSTEM", length = 200)
64  	private String mySystem;
65  
66  	@Column(name="TAG_TYPE", nullable=false)
67  	@Enumerated(EnumType.ORDINAL)
68  	private TagTypeEnum myTagType;
69  
70  	@Transient
71  	private transient Integer myHashCode;
72  
73  	public TagDefinition() {
74  	}
75  
76  	public TagDefinition(TagTypeEnum theTagType, String theSystem, String theCode, String theDisplay) {
77  		setTagType(theTagType);
78  		setCode(theCode);
79  		setSystem(theSystem);
80  		setDisplay(theDisplay);
81  	}
82  
83  	public String getCode() {
84  		return myCode;
85  	}
86  
87  	public String getDisplay() {
88  		return myDisplay;
89  	}
90  
91  	public Long getId() {
92  		return myId;
93  	}
94  
95  	public String getSystem() {
96  		return mySystem;
97  	}
98  
99  	public TagTypeEnum getTagType() {
100 		return myTagType;
101 	}
102 
103 	public void setCode(String theCode) {
104 		myCode = theCode;
105 		myHashCode = null;
106 	}
107 
108 	public void setDisplay(String theDisplay) {
109 		myDisplay = theDisplay;
110 	}
111 
112 	public void setSystem(String theSystem) {
113 		mySystem = theSystem;
114 		myHashCode = null;
115 	}
116 
117 	public void setTagType(TagTypeEnum theTagType) {
118 		myTagType = theTagType;
119 		myHashCode = null;
120 	}
121 
122 	public Tag toTag() {
123 		return new Tag(getSystem(), getCode(), getDisplay());
124 	}
125 
126 	@Override
127 	public boolean equals(Object obj) {
128 		if (this == obj) {
129 			return true;
130 		}
131 		if (obj == null) {
132 			return false;
133 		}
134 		if (!(obj instanceof TagDefinition)) {
135 			return false;
136 		}
137 		TagDefinition other = (TagDefinition) obj;
138 		EqualsBuilder b = new EqualsBuilder();
139 		
140 		if (myId != null && other.myId != null) {
141 			b.append(myId, other.myId);
142 		} else {
143 			b.append(myTagType, other.myTagType);
144 			b.append(mySystem, other.mySystem);
145 			b.append(myCode, other.myCode);
146 		}
147 		
148 		return b.isEquals();
149 	}
150 	
151 	@Override
152 	public int hashCode() {
153 		if (myHashCode == null) {
154 			HashCodeBuilder b = new HashCodeBuilder();
155 			b.append(myTagType);
156 			b.append(mySystem);
157 			b.append(myCode);
158 			myHashCode = b.toHashCode();
159 		}
160 		return myHashCode;
161 	}
162 
163 	@Override
164 	public String toString() {
165 		ToStringBuilder retVal = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
166 		retVal.append("id", myId);
167 		retVal.append("system", mySystem);
168 		retVal.append("code", myCode);
169 		retVal.append("display", myDisplay);
170 		return retVal.build();
171 	}
172 	
173 	
174 	
175 }