-
Notifications
You must be signed in to change notification settings - Fork 188
/
RContainerReference.java
144 lines (117 loc) · 4.31 KB
/
RContainerReference.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
/*
* Copyright (c) 2010-2015 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.container;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.repo.sql.data.common.ObjectReference;
import com.evolveum.midpoint.repo.sql.data.common.RObject;
import com.evolveum.midpoint.repo.sql.data.common.RObjectReference;
import com.evolveum.midpoint.repo.sql.data.common.other.RCReferenceOwner;
import com.evolveum.midpoint.repo.sql.query2.definition.NotQueryable;
import com.evolveum.midpoint.repo.sql.util.ClassMapper;
import com.evolveum.midpoint.repo.sql.util.EntityState;
import com.evolveum.midpoint.repo.sql.util.RUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import org.apache.commons.lang.Validate;
import javax.persistence.Transient;
/**
* @author lazyman
* @author mederly
*
* This is a reference that is contained in (any) container. Its owner is identified by OID, container value ID,
* and owner type.
*
* It is created as a superclass for both RAssignmentReference and RCertCaseReference (now non-existent) because they share
* almost all the code.
*
*/
public abstract class RContainerReference extends RReference implements ObjectReference, EntityState {
public static final String REFERENCE_TYPE = "reference_type";
public static final String F_OWNER = "owner";
private Boolean trans;
private RCReferenceOwner referenceType;
//owner
private String ownerOid;
private Integer ownerId;
public RContainerReference() {
}
@NotQueryable
public abstract Container getOwner();
@NotQueryable
protected String getOwnerOid() {
if (ownerOid == null && getOwner() != null) {
ownerOid = getOwner().getOwnerOid();
}
return ownerOid;
}
@NotQueryable
protected Integer getOwnerId() {
if (ownerId == null && getOwner() != null) {
ownerId = getOwner().getId();
}
return ownerId;
}
public RObject getTarget() { // for HQL use only
return null;
}
protected RCReferenceOwner getReferenceType() {
return referenceType;
}
public void setReferenceType(RCReferenceOwner referenceType) { this.referenceType = referenceType; }
public void setOwnerOid(String ownerOid) {
this.ownerOid = ownerOid;
}
public void setOwnerId(Integer ownerId) {
this.ownerId = ownerId;
}
@Transient
public Boolean isTransient() {
return trans;
}
@Override
public void setTransient(Boolean trans) {
this.trans = trans;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof RContainerReference))
return false;
if (!super.equals(o))
return false;
RContainerReference that = (RContainerReference) o;
return referenceType == that.referenceType;
}
@Override
public int hashCode() {
return super.hashCode();
}
public static void copyToJAXB(RContainerReference repo, ObjectReferenceType jaxb, PrismContext prismContext) {
Validate.notNull(repo, "Repo object must not be null.");
Validate.notNull(jaxb, "JAXB object must not be null.");
jaxb.setType(ClassMapper.getQNameForHQLType(repo.getType()));
jaxb.setOid(repo.getTargetOid());
jaxb.setRelation(RUtil.stringToQName(repo.getRelation()));
}
public static void copyFromJAXB(ObjectReferenceType jaxb, RContainerReference repo) {
RObjectReference.copyFromJAXB(jaxb, repo);
}
public ObjectReferenceType toJAXB(PrismContext prismContext) {
ObjectReferenceType ref = new ObjectReferenceType();
copyToJAXB(this, ref, prismContext);
return ref;
}
}