-
Notifications
You must be signed in to change notification settings - Fork 188
/
RefTableItemDeltaProcessor.java
63 lines (55 loc) · 2.31 KB
/
RefTableItemDeltaProcessor.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
/*
* 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.delta.item;
import java.util.Collection;
import java.util.UUID;
import com.evolveum.midpoint.prism.Referencable;
import com.evolveum.midpoint.repo.sqale.SqaleUpdateContext;
import com.evolveum.midpoint.repo.sqale.delta.ItemDeltaValueProcessor;
import com.evolveum.midpoint.repo.sqale.qmodel.ref.QReference;
import com.evolveum.midpoint.repo.sqale.qmodel.ref.QReferenceMapping;
import com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase;
/**
* @param <Q> type of entity path for the reference table
* @param <OQ> query type of the reference owner
* @param <OR> row type of the reference owner (related to {@link OQ})
*/
public class RefTableItemDeltaProcessor<Q extends QReference<?, OR>, OQ extends FlexibleRelationalPathBase<OR>, OR>
extends ItemDeltaValueProcessor<Referencable> {
private final SqaleUpdateContext<?, OQ, OR> context;
private final QReferenceMapping<Q, ?, OQ, OR> refTableMapping;
public RefTableItemDeltaProcessor(
SqaleUpdateContext<?, OQ, OR> context,
QReferenceMapping<Q, ?, OQ, OR> refTableMapping) {
super(context);
this.context = context;
this.refTableMapping = refTableMapping;
}
@Override
public void addValues(Collection<Referencable> values) {
values.forEach(ref -> context.insertOwnedRow(refTableMapping, ref));
}
@Override
public void deleteValues(Collection<Referencable> values) {
Q r = refTableMapping.defaultAlias();
for (Referencable ref : values) {
Integer relId = context.transformerSupport().searchCachedRelationId(ref.getRelation());
context.jdbcSession().newDelete(r)
.where(r.isOwnedBy(context.row())
.and(r.targetOid.eq(UUID.fromString(ref.getOid())))
.and(r.relationId.eq(relId)))
.execute();
}
}
@Override
public void delete() {
Q r = refTableMapping.defaultAlias();
context.jdbcSession().newDelete(r)
.where(r.isOwnedBy(context.row()))
.execute();
}
}