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.context.FhirVersionEnum;
24  import ca.uhn.fhir.model.primitive.IdDt;
25  import ca.uhn.fhir.model.primitive.InstantDt;
26  import org.hibernate.annotations.OptimisticLock;
27  
28  import javax.persistence.*;
29  import java.util.Collection;
30  import java.util.Date;
31  
32  @MappedSuperclass
33  public abstract class BaseHasResource implements IBaseResourceEntity {
34  
35  	@Column(name = "RES_DELETED_AT", nullable = true)
36  	@Temporal(TemporalType.TIMESTAMP)
37  	private Date myDeleted;
38  
39  	// TODO: move to resource history table
40  	@Column(name = "RES_VERSION", nullable = true, length = 7)
41  	@Enumerated(EnumType.STRING)
42  	@OptimisticLock(excluded = true)
43  	private FhirVersionEnum myFhirVersion;
44  
45  	@OneToOne(optional = true, fetch = FetchType.LAZY, cascade = {}, orphanRemoval = false)
46  	@JoinColumn(name = "FORCED_ID_PID")
47  	@OptimisticLock(excluded = true)
48  	private ForcedId myForcedId;
49  
50  	@Column(name = "HAS_TAGS", nullable = false)
51  	@OptimisticLock(excluded = true)
52  	private boolean myHasTags;
53  
54  	@Temporal(TemporalType.TIMESTAMP)
55  	@Column(name = "RES_PUBLISHED", nullable = false)
56  	@OptimisticLock(excluded = true)
57  	private Date myPublished;
58  
59  	@Temporal(TemporalType.TIMESTAMP)
60  	@Column(name = "RES_UPDATED", nullable = false)
61  	@OptimisticLock(excluded = true)
62  	private Date myUpdated;
63  
64  	public abstract BaseTag addTag(TagDefinition theDef);
65  
66  	@Override
67  	public Date getDeleted() {
68  		return myDeleted;
69  	}
70  
71  	public void setDeleted(Date theDate) {
72  		myDeleted = theDate;
73  	}
74  
75  
76  	@Override
77  	public FhirVersionEnum getFhirVersion() {
78  		return myFhirVersion;
79  	}
80  
81  	public void setFhirVersion(FhirVersionEnum theFhirVersion) {
82  		myFhirVersion = theFhirVersion;
83  	}
84  
85  	public ForcedId getForcedId() {
86  		return myForcedId;
87  	}
88  
89  	public void setForcedId(ForcedId theForcedId) {
90  		myForcedId = theForcedId;
91  	}
92  
93  	@Override
94  	public abstract Long getId();
95  
96  	@Override
97  	public abstract IdDt getIdDt();
98  
99  	@Override
100 	public InstantDt getPublished() {
101 		if (myPublished != null) {
102 			return new InstantDt(myPublished);
103 		} else {
104 			return null;
105 		}
106 	}
107 
108 	public void setPublished(Date thePublished) {
109 		myPublished = thePublished;
110 	}
111 
112 	@Override
113 	public abstract Long getResourceId();
114 
115 	@Override
116 	public abstract String getResourceType();
117 
118 	public abstract Collection<? extends BaseTag> getTags();
119 
120 	@Override
121 	public InstantDt getUpdated() {
122 		return new InstantDt(myUpdated);
123 	}
124 
125 	public void setUpdated(Date theUpdated) {
126 		myUpdated = theUpdated;
127 	}
128 
129 	@Override
130 	public Date getUpdatedDate() {
131 		return myUpdated;
132 	}
133 
134 	@Override
135 	public abstract long getVersion();
136 
137 	@Override
138 	public boolean isHasTags() {
139 		return myHasTags;
140 	}
141 
142 	public void setHasTags(boolean theHasTags) {
143 		myHasTags = theHasTags;
144 	}
145 
146 	public void setPublished(InstantDt thePublished) {
147 		myPublished = thePublished.getValue();
148 	}
149 
150 	public void setUpdated(InstantDt theUpdated) {
151 		myUpdated = theUpdated.getValue();
152 	}
153 
154 }