001package ca.uhn.fhir.jpa.model.entity;
002
003/*
004 * #%L
005 * HAPI FHIR JPA Model
006 * %%
007 * Copyright (C) 2014 - 2022 Smile CDR, Inc.
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 * http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import org.apache.commons.lang3.builder.EqualsBuilder;
024import org.apache.commons.lang3.builder.HashCodeBuilder;
025import org.apache.commons.lang3.builder.ToStringBuilder;
026import org.apache.commons.lang3.builder.ToStringStyle;
027
028import javax.persistence.Column;
029import javax.persistence.Entity;
030import javax.persistence.EnumType;
031import javax.persistence.Enumerated;
032import javax.persistence.FetchType;
033import javax.persistence.GeneratedValue;
034import javax.persistence.GenerationType;
035import javax.persistence.Id;
036import javax.persistence.OneToMany;
037import javax.persistence.SequenceGenerator;
038import javax.persistence.Table;
039import javax.persistence.Transient;
040import javax.persistence.UniqueConstraint;
041import java.io.Serializable;
042import java.util.Collection;
043
044@Entity
045@Table(name = "HFJ_TAG_DEF", uniqueConstraints = {
046        @UniqueConstraint(name = "IDX_TAGDEF_TYPESYSCODE", columnNames = {"TAG_TYPE", "TAG_SYSTEM", "TAG_CODE"})
047})
048public class TagDefinition implements Serializable {
049
050        private static final long serialVersionUID = 1L;
051        @Column(name = "TAG_CODE", length = 200)
052        private String myCode;
053        @Column(name = "TAG_DISPLAY", length = 200)
054        private String myDisplay;
055        @Id
056        @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_TAGDEF_ID")
057        @SequenceGenerator(name = "SEQ_TAGDEF_ID", sequenceName = "SEQ_TAGDEF_ID")
058        @Column(name = "TAG_ID")
059        private Long myId;
060        @OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "myTag")
061        private Collection<ResourceTag> myResources;
062        @OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "myTag")
063        private Collection<ResourceHistoryTag> myResourceVersions;
064        @Column(name = "TAG_SYSTEM", length = 200)
065        private String mySystem;
066        @Column(name = "TAG_TYPE", nullable = false)
067        @Enumerated(EnumType.ORDINAL)
068        private TagTypeEnum myTagType;
069        @Transient
070        private transient Integer myHashCode;
071
072        /**
073         * Constructor
074         */
075        public TagDefinition() {
076                super();
077        }
078
079        public TagDefinition(TagTypeEnum theTagType, String theSystem, String theCode, String theDisplay) {
080                setTagType(theTagType);
081                setCode(theCode);
082                setSystem(theSystem);
083                setDisplay(theDisplay);
084        }
085
086        public String getCode() {
087                return myCode;
088        }
089
090        public void setCode(String theCode) {
091                myCode = theCode;
092                myHashCode = null;
093        }
094
095        public String getDisplay() {
096                return myDisplay;
097        }
098
099        public void setDisplay(String theDisplay) {
100                myDisplay = theDisplay;
101        }
102
103        public Long getId() {
104                return myId;
105        }
106
107        public void setId(Long theId) {
108                myId = theId;
109        }
110
111        public String getSystem() {
112                return mySystem;
113        }
114
115        public void setSystem(String theSystem) {
116                mySystem = theSystem;
117                myHashCode = null;
118        }
119
120        public TagTypeEnum getTagType() {
121                return myTagType;
122        }
123
124        public void setTagType(TagTypeEnum theTagType) {
125                myTagType = theTagType;
126                myHashCode = null;
127        }
128
129        @Override
130        public boolean equals(Object obj) {
131                if (this == obj) {
132                        return true;
133                }
134                if (!(obj instanceof TagDefinition)) {
135                        return false;
136                }
137                TagDefinition other = (TagDefinition) obj;
138
139                EqualsBuilder b = new EqualsBuilder();
140
141                if (myId != null && other.myId != null) {
142                        b.append(myId, other.myId);
143                } else {
144                        b.append(myTagType, other.myTagType);
145                        b.append(mySystem, other.mySystem);
146                        b.append(myCode, other.myCode);
147                }
148
149                return b.isEquals();
150        }
151
152        @Override
153        public int hashCode() {
154                if (myHashCode == null) {
155                        HashCodeBuilder b = new HashCodeBuilder();
156                        b.append(myTagType);
157                        b.append(mySystem);
158                        b.append(myCode);
159                        myHashCode = b.toHashCode();
160                }
161                return myHashCode;
162        }
163
164        @Override
165        public String toString() {
166                ToStringBuilder retVal = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
167                retVal.append("id", myId);
168                retVal.append("system", mySystem);
169                retVal.append("code", myCode);
170                retVal.append("display", myDisplay);
171                return retVal.build();
172        }
173}