-
Notifications
You must be signed in to change notification settings - Fork 188
/
TableContainerDeltaProcessor.java
69 lines (60 loc) · 2.54 KB
/
TableContainerDeltaProcessor.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
/*
* 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 org.jetbrains.annotations.NotNull;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.repo.sqale.SqaleUpdateContext;
import com.evolveum.midpoint.repo.sqale.delta.ItemDeltaValueProcessor;
import com.evolveum.midpoint.repo.sqale.qmodel.common.MContainer;
import com.evolveum.midpoint.repo.sqale.qmodel.common.QContainer;
import com.evolveum.midpoint.repo.sqale.qmodel.common.QContainerMapping;
import com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase;
/**
* Delta processor for multi-value containers stored in separate tables.
*
* @param <T> schema type for container
* @param <Q> query type for container table
* @param <R> row type for container table, related to {@link Q}
* @param <OQ> query type of the table owning this container
* @param <OR> row type of the table owning this container, related to {@link OQ}
*/
public class TableContainerDeltaProcessor<
T extends Containerable, Q extends QContainer<R, OR>, R extends MContainer,
OQ extends FlexibleRelationalPathBase<OR>, OR>
extends ItemDeltaValueProcessor<T> {
private final SqaleUpdateContext<?, OQ, OR> context;
private final QContainerMapping<T, Q, R, OR> containerTableMapping;
public TableContainerDeltaProcessor(
@NotNull SqaleUpdateContext<?, OQ, OR> context,
@NotNull QContainerMapping<T, Q, R, OR> containerTableMapping) {
super(context);
this.context = context;
this.containerTableMapping = containerTableMapping;
}
@Override
public void addValues(Collection<T> values) {
values.forEach(ref -> context.insertOwnedRow(containerTableMapping, ref));
}
@Override
public void deleteValues(Collection<T> values) {
Q c = containerTableMapping.defaultAlias();
for (T container : values) {
context.jdbcSession().newDelete(c)
.where(c.isOwnedBy(context.row())
.and(c.cid.eq(container.asPrismContainerValue().getId())))
.execute();
}
}
@Override
public void delete() {
QContainer<R, OR> c = containerTableMapping.defaultAlias();
context.jdbcSession().newDelete(c)
.where(c.isOwnedBy(context.row()))
.execute();
}
}