-
Notifications
You must be signed in to change notification settings - Fork 188
/
ReferenceSqlTransformer.java
46 lines (38 loc) · 1.77 KB
/
ReferenceSqlTransformer.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
/*
* 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.ref;
import java.util.UUID;
import com.evolveum.midpoint.prism.Referencable;
import com.evolveum.midpoint.repo.sqale.qmodel.SqaleTransformerBase;
import com.evolveum.midpoint.repo.sqlbase.JdbcSession;
import com.evolveum.midpoint.repo.sqlbase.SqlTransformerSupport;
public class ReferenceSqlTransformer<Q extends QReference<R>, R extends MReference, OR>
extends SqaleTransformerBase<Referencable, Q, R> {
private final QReferenceMapping<Q, R, ?, OR> mapping;
public ReferenceSqlTransformer(
SqlTransformerSupport transformerSupport, QReferenceMapping<Q, R, ?, OR> mapping) {
super(transformerSupport);
this.mapping = mapping;
}
@Override
protected QReferenceMapping<Q, R, ?, OR> mapping() {
return mapping;
}
/**
* There is no need to override this, only reference creation is different and that is covered
* by {@link QReferenceMapping#newRowObject(Object)} including setting FK columns.
* All the other columns are based on a single schema type, so there is no variation.
*/
public void insert(Referencable schemaObject, OR ownerRow, JdbcSession jdbcSession) {
R row = mapping.newRowObject(ownerRow);
// row.referenceType is DB generated, must be kept NULL, but it will match referenceType
row.relationId = processCacheableRelation(schemaObject.getRelation());
row.targetOid = UUID.fromString(schemaObject.getOid());
row.targetType = schemaTypeToObjectType(schemaObject.getType());
insert(row, jdbcSession);
}
}