-
Notifications
You must be signed in to change notification settings - Fork 188
/
RAExtReference.java
230 lines (188 loc) · 6.91 KB
/
RAExtReference.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
* Copyright (c) 2010-2013 Evolveum
*
* 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://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.
*/
package com.evolveum.midpoint.repo.sql.data.common.any;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.repo.sql.data.common.id.RAExtReferenceId;
import com.evolveum.midpoint.repo.sql.data.common.other.RObjectType;
import com.evolveum.midpoint.repo.sql.data.common.type.RAssignmentExtensionType;
import com.evolveum.midpoint.repo.sql.util.ClassMapper;
import com.evolveum.midpoint.repo.sql.util.RUtil;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Index;
import javax.persistence.*;
/**
* @author lazyman
*/
@Entity
@IdClass(RAExtReferenceId.class)
@Table(name = "m_assignment_ext_reference")
@org.hibernate.annotations.Table(appliesTo = "m_assignment_ext_reference",
indexes = {@Index(name = "iAExtensionReference", columnNames = {"extensionType", "targetoid", "eName", "eType"})})
public class RAExtReference implements RAExtValue {
//owner entity
private RAssignmentExtension anyContainer;
private String ownerOid;
private Short ownerId;
private RAssignmentExtensionType extensionType;
private boolean dynamic;
private String name;
private String type;
private RValueType valueType;
//this is target oid
private String value;
//this is type attribute
private RObjectType targetType;
private String relation;
public RAExtReference() {
}
@ForeignKey(name = "fk_assignment_ext_reference")
@MapsId("owner")
@ManyToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumns({
@PrimaryKeyJoinColumn(name = "anyContainer_owner_owner_oid", referencedColumnName = "ownerOid"),
@PrimaryKeyJoinColumn(name = "anyContainer_owner_id", referencedColumnName = "owner_type")
})
public RAssignmentExtension getAnyContainer() {
return anyContainer;
}
@Id
@Column(name = "anyContainer_owner_owner_oid", length = RUtil.COLUMN_LENGTH_OID)
public String getOwnerOid() {
if (ownerOid == null && anyContainer != null) {
ownerOid = anyContainer.getOwnerOid();
}
return ownerOid;
}
@Id
@Column(name = "anyContainer_owner_id")
public Short getOwnerId() {
if (ownerId == null && anyContainer != null) {
ownerId = anyContainer.getOwnerId();
}
return ownerId;
}
@Id
@Enumerated(EnumType.ORDINAL)
public RAssignmentExtensionType getExtensionType() {
// return extensionType;
return RAssignmentExtensionType.EXTENSION;
}
@Id
@Column(name = "eName", length = RUtil.COLUMN_LENGTH_QNAME)
public String getName() {
return name;
}
@Id
@Column(name = "eType", length = RUtil.COLUMN_LENGTH_QNAME)
public String getType() {
return type;
}
@Enumerated(EnumType.ORDINAL)
public RValueType getValueType() {
return valueType;
}
/**
* @return true if this property has dynamic definition
*/
@Column(name = "dynamicDef")
public boolean isDynamic() {
return dynamic;
}
@Column(name = "targetoid", length = RUtil.COLUMN_LENGTH_OID)
public String getValue() {
return value;
}
@Enumerated(EnumType.ORDINAL)
public RObjectType getTargetType() {
return targetType;
}
@Column(name = "relation", length = RUtil.COLUMN_LENGTH_QNAME)
public String getRelation() {
return relation;
}
public void setValue(String value) {
this.value = value;
}
public void setValueType(RValueType valueType) {
this.valueType = valueType;
}
public void setName(String name) {
this.name = name;
}
public void setType(String type) {
this.type = type;
}
public void setDynamic(boolean dynamic) {
this.dynamic = dynamic;
}
public void setAnyContainer(RAssignmentExtension anyContainer) {
this.anyContainer = anyContainer;
}
public void setOwnerOid(String ownerOid) {
this.ownerOid = ownerOid;
}
public void setTargetType(RObjectType targetType) {
this.targetType = targetType;
}
public void setRelation(String relation) {
this.relation = relation;
}
public void setOwnerId(Short ownerId) {
this.ownerId = ownerId;
}
public void setExtensionType(RAssignmentExtensionType extensionType) {
this.extensionType = extensionType;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RAExtReference that = (RAExtReference) o;
if (dynamic != that.dynamic) return false;
if (name != null ? !name.equals(that.name) : that.name != null) return false;
if (relation != null ? !relation.equals(that.relation) : that.relation != null) return false;
if (targetType != that.targetType) return false;
if (type != null ? !type.equals(that.type) : that.type != null) return false;
if (value != null ? !value.equals(that.value) : that.value != null) return false;
if (valueType != that.valueType) return false;
return true;
}
@Override
public int hashCode() {
int result = (dynamic ? 1 : 0);
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (type != null ? type.hashCode() : 0);
result = 31 * result + (valueType != null ? valueType.hashCode() : 0);
result = 31 * result + (value != null ? value.hashCode() : 0);
result = 31 * result + (targetType != null ? targetType.hashCode() : 0);
result = 31 * result + (relation != null ? relation.hashCode() : 0);
return result;
}
public static PrismReferenceValue createReference(RAExtReference repo) {
PrismReferenceValue value = new PrismReferenceValue();
value.setOid(repo.getValue());
value.setRelation(RUtil.stringToQName(repo.getRelation()));
value.setTargetType(ClassMapper.getQNameForHQLType(repo.getTargetType()));
return value;
}
public static RAExtReference createReference(PrismReferenceValue jaxb) {
RAExtReference repo = new RAExtReference();
repo.setValue(jaxb.getOid());
repo.setRelation(RUtil.qnameToString(jaxb.getRelation()));
repo.setTargetType(ClassMapper.getHQLTypeForQName(jaxb.getTargetType()));
return repo;
}
}