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.hibernate.annotations.ColumnDefault;
24  
25  import javax.persistence.*;
26  
27  @Entity()
28  @Table(name = "HFJ_FORCED_ID", uniqueConstraints = {
29  	@UniqueConstraint(name = "IDX_FORCEDID_RESID", columnNames = {"RESOURCE_PID"}),
30  	@UniqueConstraint(name = "IDX_FORCEDID_TYPE_FID", columnNames = {"RESOURCE_TYPE", "FORCED_ID"})
31  }, indexes = {
32  	/*
33  	 * NB: We previously had indexes named
34  	 * - IDX_FORCEDID_TYPE_FORCEDID
35  	 * - IDX_FORCEDID_TYPE_RESID
36  	 * so don't reuse these names
37  	 */
38  })
39  public class ForcedId {
40  
41  	public static final int MAX_FORCED_ID_LENGTH = 100;
42  
43  	@Column(name = "FORCED_ID", nullable = false, length = MAX_FORCED_ID_LENGTH, updatable = false)
44  	private String myForcedId;
45  
46  	@SequenceGenerator(name = "SEQ_FORCEDID_ID", sequenceName = "SEQ_FORCEDID_ID")
47  	@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_FORCEDID_ID")
48  	@Id
49  	@Column(name = "PID")
50  	private Long myId;
51  
52  	@JoinColumn(name = "RESOURCE_PID", nullable = false, updatable = false, foreignKey = @ForeignKey(name = "FK_FORCEDID_RESOURCE"))
53  	@OneToOne()
54  	private ResourceTable myResource;
55  
56  	@Column(name = "RESOURCE_PID", nullable = false, updatable = false, insertable = false)
57  	private Long myResourcePid;
58  
59  	// This is updatable=true because it was added in 1.6 and needs to be set.. At some
60  	// point we should remove the default and make it not updatable
61  	@ColumnDefault("''")
62  	@Column(name = "RESOURCE_TYPE", nullable = true, length = 100, updatable = true)
63  	private String myResourceType;
64  
65  	/**
66  	 * Constructor
67  	 */
68  	public ForcedId() {
69  		super();
70  	}
71  
72  	public String getForcedId() {
73  		return myForcedId;
74  	}
75  
76  	public void setForcedId(String theForcedId) {
77  		myForcedId = theForcedId;
78  	}
79  
80  	public ResourceTable getResource() {
81  		return myResource;
82  	}
83  
84  	public void setResource(ResourceTable theResource) {
85  		myResource = theResource;
86  	}
87  
88  	public Long getResourcePid() {
89  		if (myResourcePid == null) {
90  			return myResource.getId();
91  		}
92  		return myResourcePid;
93  	}
94  
95  	public void setResourcePid(ResourceTable theResourcePid) {
96  		myResource = theResourcePid;
97  	}
98  
99  	public String getResourceType() {
100 		return myResourceType;
101 	}
102 
103 	public void setResourceType(String theResourceType) {
104 		myResourceType = theResourceType;
105 	}
106 
107 	public void setResourcePid(Long theResourcePid) {
108 		myResourcePid = theResourcePid;
109 	}
110 
111 }