Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repo-sqale: MObjectType introduced as PG enum + few columns migrated
- Loading branch information
Showing
16 changed files
with
335 additions
and
209 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
.../repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/RefItemIntFilterProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.function.Function; | ||
|
||
import com.querydsl.core.types.EntityPath; | ||
import com.querydsl.core.types.ExpressionUtils; | ||
import com.querydsl.core.types.Predicate; | ||
import com.querydsl.core.types.dsl.NumberPath; | ||
|
||
import com.evolveum.midpoint.prism.PrismConstants; | ||
import com.evolveum.midpoint.prism.PrismReferenceValue; | ||
import com.evolveum.midpoint.prism.query.RefFilter; | ||
import com.evolveum.midpoint.repo.sqale.qmodel.common.QUri; | ||
import com.evolveum.midpoint.repo.sqlbase.SqlQueryContext; | ||
import com.evolveum.midpoint.repo.sqlbase.mapping.item.ItemFilterProcessor; | ||
import com.evolveum.midpoint.repo.sqlbase.mapping.item.ItemSqlMapper; | ||
import com.evolveum.midpoint.repo.sqlbase.querydsl.UuidPath; | ||
|
||
/** | ||
* Filter processor for reference item paths embedded in table as three columns. | ||
* TODO: This version supports integer target type path while migrating to enum version. | ||
* OID is represented by UUID column, type by ID (see {@link MObjectType} and relation | ||
* by Integer (foreign key) to {@link QUri}. | ||
*/ | ||
@Deprecated | ||
public class RefItemIntFilterProcessor extends ItemFilterProcessor<RefFilter> { | ||
|
||
/** | ||
* Returns the mapper function creating the ref-filter processor from query context. | ||
*/ | ||
public static ItemSqlMapper mapper( | ||
Function<EntityPath<?>, UuidPath> rootToOidPath, | ||
Function<EntityPath<?>, NumberPath<Integer>> rootToTypePath, | ||
Function<EntityPath<?>, NumberPath<Integer>> rootToRelationIdPath) { | ||
return new ItemSqlMapper(ctx -> new RefItemIntFilterProcessor( | ||
ctx, rootToOidPath, rootToTypePath, rootToRelationIdPath)); | ||
} | ||
|
||
// only oidPath is strictly not-null, but then the filter better not ask for type or relation | ||
private final UuidPath oidPath; | ||
private final NumberPath<Integer> typePath; | ||
private final NumberPath<Integer> relationIdPath; | ||
|
||
private RefItemIntFilterProcessor( | ||
SqlQueryContext<?, ?, ?> context, | ||
Function<EntityPath<?>, UuidPath> rootToOidPath, | ||
Function<EntityPath<?>, NumberPath<Integer>> rootToTypePath, | ||
Function<EntityPath<?>, NumberPath<Integer>> rootToRelationIdPath) { | ||
this(context, | ||
rootToOidPath.apply(context.path()), | ||
rootToTypePath != null ? rootToTypePath.apply(context.path()) : null, | ||
rootToRelationIdPath != null ? rootToRelationIdPath.apply(context.path()) : null); | ||
} | ||
|
||
// exposed mainly for RefTableItemFilterProcessor | ||
RefItemIntFilterProcessor(SqlQueryContext<?, ?, ?> context, | ||
UuidPath oidPath, NumberPath<Integer> typePath, NumberPath<Integer> relationIdPath) { | ||
super(context); | ||
this.oidPath = oidPath; | ||
this.typePath = typePath; | ||
this.relationIdPath = relationIdPath; | ||
} | ||
|
||
@Override | ||
public Predicate process(RefFilter filter) { | ||
List<PrismReferenceValue> values = filter.getValues(); | ||
if (values == null || values.isEmpty()) { | ||
return oidPath.isNull(); | ||
} | ||
if (values.size() == 1) { | ||
return processSingleValue(filter, values.get(0)); | ||
} | ||
|
||
Predicate predicate = null; | ||
for (PrismReferenceValue ref : values) { | ||
predicate = ExpressionUtils.or(predicate, processSingleValue(filter, ref)); | ||
} | ||
return predicate; | ||
} | ||
|
||
private Predicate processSingleValue(RefFilter filter, PrismReferenceValue ref) { | ||
Predicate predicate = null; | ||
if (ref.getOid() != null) { | ||
predicate = predicateWithNotTreated(oidPath, | ||
oidPath.eq(UUID.fromString(ref.getOid()))); | ||
} else if (!filter.isOidNullAsAny()) { | ||
predicate = oidPath.isNull(); | ||
} | ||
if (ref.getRelation() == null) { | ||
Integer defaultRelationId = ((SqaleRepoContext) context.sqlRepoContext()) | ||
.searchCachedUriId(context.prismContext().getDefaultRelation()); | ||
predicate = ExpressionUtils.and(predicate, | ||
predicateWithNotTreated(relationIdPath, relationIdPath.eq(defaultRelationId))); | ||
} else if (ref.getRelation().equals(PrismConstants.Q_ANY)) { | ||
// no additional predicate needed | ||
} else { | ||
Integer relationId = ((SqaleRepoContext) context.sqlRepoContext()) | ||
.searchCachedUriId(ref.getRelation()); | ||
predicate = ExpressionUtils.and(predicate, | ||
predicateWithNotTreated(relationIdPath, relationIdPath.eq(relationId))); | ||
} | ||
if (ref.getTargetType() != null) { | ||
int typeCode = MObjectType.fromTypeQName(ref.getTargetType()).code(); | ||
predicate = ExpressionUtils.and(predicate, | ||
predicateWithNotTreated(typePath, typePath.eq(typeCode))); | ||
} else if (!filter.isTargetTypeNullAsAny()) { | ||
predicate = ExpressionUtils.and(predicate, typePath.isNull()); | ||
} | ||
return predicate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.