-
Notifications
You must be signed in to change notification settings - Fork 188
/
QAssignmentReferenceMapping.java
93 lines (79 loc) · 3.77 KB
/
QAssignmentReferenceMapping.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
/*
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.repo.sqale.qmodel.assignment;
import java.util.Objects;
import java.util.function.BiFunction;
import com.querydsl.core.types.Predicate;
import org.jetbrains.annotations.NotNull;
import com.evolveum.midpoint.repo.sqale.SqaleRepoContext;
import com.evolveum.midpoint.repo.sqale.qmodel.object.MObject;
import com.evolveum.midpoint.repo.sqale.qmodel.ref.QReferenceMapping;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
/**
* Mapping between {@link QAssignmentReference} and {@link ObjectReferenceType}.
* The mapping is the same for all subtypes, see various static `get*()` methods below.
* Both mapping instances are initialized (`init*()` methods) in {@link QAssignmentMapping}.
* Init methods can be called multiple times, only one instance for each sub-tables is created.
*
* @param <AOR> type of the row (M-bean) of the assignment owner
*/
public class QAssignmentReferenceMapping<AOR extends MObject>
extends QReferenceMapping<QAssignmentReference, MAssignmentReference, QAssignment<AOR>, MAssignment> {
private static QAssignmentReferenceMapping<?> instanceAssignmentCreateApprover;
private static QAssignmentReferenceMapping<?> instanceAssignmentModifyApprover;
public static <OR extends MObject> QAssignmentReferenceMapping<OR>
initForAssignmentCreateApprover(@NotNull SqaleRepoContext repositoryContext) {
if (instanceAssignmentCreateApprover == null) {
instanceAssignmentCreateApprover = new QAssignmentReferenceMapping<>(
"m_assignment_ref_create_approver", "arefca", repositoryContext);
}
return getForAssignmentCreateApprover();
}
public static <OR extends MObject> QAssignmentReferenceMapping<OR>
getForAssignmentCreateApprover() {
//noinspection unchecked
return (QAssignmentReferenceMapping<OR>)
Objects.requireNonNull(instanceAssignmentCreateApprover);
}
public static <OR extends MObject> QAssignmentReferenceMapping<OR>
initForAssignmentModifyApprover(@NotNull SqaleRepoContext repositoryContext) {
if (instanceAssignmentModifyApprover == null) {
instanceAssignmentModifyApprover = new QAssignmentReferenceMapping<>(
"m_assignment_ref_modify_approver", "arefma", repositoryContext);
}
return getForAssignmentModifyApprover();
}
public static <OR extends MObject> QAssignmentReferenceMapping<OR>
getForAssignmentModifyApprover() {
//noinspection unchecked
return (QAssignmentReferenceMapping<OR>)
Objects.requireNonNull(instanceAssignmentModifyApprover);
}
private QAssignmentReferenceMapping(
String tableName,
String defaultAliasName,
@NotNull SqaleRepoContext repositoryContext) {
super(tableName, defaultAliasName, QAssignmentReference.class, repositoryContext);
// assignmentCid probably can't be mapped directly
}
@Override
protected QAssignmentReference newAliasInstance(String alias) {
return new QAssignmentReference(alias, tableName());
}
@Override
public MAssignmentReference newRowObject(MAssignment ownerRow) {
MAssignmentReference row = new MAssignmentReference();
row.ownerOid = ownerRow.ownerOid;
row.ownerType = ownerRow.ownerType;
row.assignmentCid = ownerRow.cid;
return row;
}
@Override
public BiFunction<QAssignment<AOR>, QAssignmentReference, Predicate> joinOnPredicate() {
return (a, r) -> a.ownerOid.eq(r.ownerOid).and(a.cid.eq(r.assignmentCid));
}
}