-
Notifications
You must be signed in to change notification settings - Fork 188
/
ContainerTableUpdateContext.java
76 lines (65 loc) · 2.48 KB
/
ContainerTableUpdateContext.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
/*
* 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.update;
import com.querydsl.core.types.Path;
import com.querydsl.sql.dml.SQLUpdateClause;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.repo.sqale.qmodel.SqaleTableMapping;
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;
/**
* Update context for multi-value containers stored in separate table.
* This can be owned by the root object or another container.
*
* @param <S> schema type of the container stored in the owned table
* @param <Q> type of entity path for the owned (child) table
* @param <R> row type related to the {@link Q}
* @param <OR> owner row type
*/
public class ContainerTableUpdateContext<S extends Containerable, Q extends QContainer<R, OR>, R extends MContainer, OR>
extends SqaleUpdateContext<S, Q, R> {
private final Q path;
private final SQLUpdateClause update;
private final QContainerMapping<S, Q, R, OR> mapping;
/**
* Creates the context for container component of the path, skeleton/fake row of the container
* with pre-filled CID and FK referencing the owner row must be provided.
*/
public ContainerTableUpdateContext(
SqaleUpdateContext<?, ?, OR> parentContext,
QContainerMapping<S, Q, R, OR> mapping,
R row) {
super(parentContext, row);
this.mapping = mapping;
path = mapping.defaultAlias();
// we create the update, but only use it if set methods are used
update = jdbcSession.newUpdate(path)
.where(path.isOwnedBy(parentContext.row())
.and(path.cid.eq(row.cid)));
}
public Q path() {
return path;
}
@Override
public SqaleTableMapping<S, Q, R> mapping() {
return mapping;
}
public SQLUpdateClause update() {
return update;
}
public <P extends Path<T>, T> void set(P path, T value) {
update.set(path, value);
}
/** Executes updates if applicable, nothing is done if set methods were not used. */
@Override
protected void finishExecutionOwn() {
if (!update.isEmpty()) {
update.execute();
}
}
}