-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
ResourceSearchUrlEntity.java
122 lines (104 loc) 路 3.53 KB
/
ResourceSearchUrlEntity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*-
* #%L
* HAPI FHIR JPA Model
* %%
* Copyright (C) 2014 - 2024 Smile CDR, Inc.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package ca.uhn.fhir.jpa.model.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.Id;
import jakarta.persistence.Index;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import java.util.Date;
/**
* This entity is used to enforce uniqueness on a given search URL being
* used as a conditional operation URL, e.g. a conditional create or a
* conditional update. When we perform a conditional operation that is
* creating a new resource, we store an entity with the conditional URL
* in this table. The URL is the PK of the table, so the database
* ensures that two concurrent threads don't accidentally create two
* resources with the same conditional URL.
*/
@Entity
@Table(
name = "HFJ_RES_SEARCH_URL",
indexes = {
@Index(name = "IDX_RESSEARCHURL_RES", columnList = "RES_ID"),
@Index(name = "IDX_RESSEARCHURL_TIME", columnList = "CREATED_TIME")
})
public class ResourceSearchUrlEntity {
public static final String RES_SEARCH_URL_COLUMN_NAME = "RES_SEARCH_URL";
public static final int RES_SEARCH_URL_LENGTH = 768;
@Id
@Column(name = RES_SEARCH_URL_COLUMN_NAME, length = RES_SEARCH_URL_LENGTH, nullable = false)
private String mySearchUrl;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(
name = "RES_ID",
nullable = false,
updatable = false,
foreignKey = @ForeignKey(name = "FK_RES_SEARCH_URL_RESOURCE"))
private ResourceTable myResourceTable;
@Column(name = "RES_ID", updatable = false, nullable = false, insertable = false)
private Long myResourcePid;
@Column(name = "CREATED_TIME", nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date myCreatedTime;
public static ResourceSearchUrlEntity from(String theUrl, ResourceTable theResourceTable) {
return new ResourceSearchUrlEntity()
.setResourceTable(theResourceTable)
.setSearchUrl(theUrl)
.setCreatedTime(new Date());
}
public Long getResourcePid() {
if (myResourcePid != null) {
return myResourcePid;
}
return myResourceTable.getResourceId();
}
public ResourceSearchUrlEntity setResourcePid(Long theResourcePid) {
myResourcePid = theResourcePid;
return this;
}
public ResourceTable getResourceTable() {
return myResourceTable;
}
public ResourceSearchUrlEntity setResourceTable(ResourceTable myResourceTable) {
this.myResourceTable = myResourceTable;
return this;
}
public Date getCreatedTime() {
return myCreatedTime;
}
public ResourceSearchUrlEntity setCreatedTime(Date theCreatedTime) {
myCreatedTime = theCreatedTime;
return this;
}
public String getSearchUrl() {
return mySearchUrl;
}
public ResourceSearchUrlEntity setSearchUrl(String theSearchUrl) {
mySearchUrl = theSearchUrl;
return this;
}
}