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