-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
39 changed files
with
438 additions
and
182 deletions.
There are no files selected for viewing
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
80 changes: 80 additions & 0 deletions
80
...sqale/src/main/java/com/evolveum/midpoint/repo/sqale/filtering/ExistsFilterProcessor.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,80 @@ | ||
/* | ||
* 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.filtering; | ||
|
||
import com.querydsl.core.types.Predicate; | ||
|
||
import com.evolveum.midpoint.prism.path.ItemPath; | ||
import com.evolveum.midpoint.prism.query.ExistsFilter; | ||
import com.evolveum.midpoint.prism.query.ObjectFilter; | ||
import com.evolveum.midpoint.repo.sqale.SqaleQueryContext; | ||
import com.evolveum.midpoint.repo.sqale.mapping.CountMappingResolver; | ||
import com.evolveum.midpoint.repo.sqlbase.RepositoryException; | ||
import com.evolveum.midpoint.repo.sqlbase.filtering.FilterProcessor; | ||
import com.evolveum.midpoint.repo.sqlbase.mapping.ItemRelationResolver; | ||
import com.evolveum.midpoint.repo.sqlbase.mapping.QueryModelMapping; | ||
import com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase; | ||
|
||
/** | ||
* Filter processor that resolves {@link ExistsFilter}. | ||
* | ||
* @param <Q> query type of the original context | ||
* @param <R> row type related to {@link Q} | ||
*/ | ||
public class ExistsFilterProcessor<Q extends FlexibleRelationalPathBase<R>, R> | ||
implements FilterProcessor<ExistsFilter> { | ||
|
||
private final SqaleQueryContext<?, Q, R> context; | ||
private final QueryModelMapping<?, Q, R> mapping; | ||
|
||
public ExistsFilterProcessor(SqaleQueryContext<?, Q, R> context) { | ||
this.context = context; | ||
this.mapping = context.mapping(); | ||
} | ||
|
||
private ExistsFilterProcessor( | ||
SqaleQueryContext<?, Q, R> context, QueryModelMapping<?, Q, R> mapping) { | ||
this.context = context; | ||
this.mapping = mapping; | ||
} | ||
|
||
@Override | ||
public Predicate process(ExistsFilter filter) throws RepositoryException { | ||
return process(filter.getFullPath(), filter); | ||
} | ||
|
||
private <TQ extends FlexibleRelationalPathBase<TR>, TR> Predicate process( | ||
ItemPath path, ExistsFilter filter) throws RepositoryException { | ||
if (path.isEmpty()) { | ||
ObjectFilter innerFilter = filter.getFilter(); | ||
|
||
// empty filter means EXISTS, NOT can be added before the filter | ||
return innerFilter != null | ||
? context.process(innerFilter) | ||
: null; | ||
} | ||
|
||
ItemRelationResolver<Q, R, TQ, TR> resolver = mapping.relationResolver(path.firstName()); | ||
// Instead of cleaner but arguably confusing solution that would follow the code lower | ||
// we resolve this corner case here and now. | ||
if (resolver instanceof CountMappingResolver<?, ?, ?>) { | ||
return ((CountMappingResolver<?, Q, R>) resolver).createExistsPredicate(context); | ||
} | ||
|
||
ItemRelationResolver.ResolutionResult<TQ, TR> resolution = resolver.resolve(context); | ||
//noinspection unchecked | ||
SqaleQueryContext<?, TQ, TR> subcontext = (SqaleQueryContext<?, TQ, TR>) resolution.context; | ||
ExistsFilterProcessor<TQ, TR> nestedProcessor = | ||
new ExistsFilterProcessor<>(subcontext, resolution.mapping); | ||
Predicate predicate = nestedProcessor.process(path.rest(), filter); | ||
if (resolution.subquery) { | ||
return subcontext.sqlQuery().where(predicate).exists(); | ||
} else { | ||
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
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
56 changes: 56 additions & 0 deletions
56
...po-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/mapping/CountMappingResolver.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,56 @@ | ||
/* | ||
* 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.mapping; | ||
|
||
import java.util.function.Function; | ||
|
||
import com.querydsl.core.types.Predicate; | ||
import com.querydsl.core.types.dsl.NumberPath; | ||
|
||
import com.evolveum.midpoint.prism.Containerable; | ||
import com.evolveum.midpoint.prism.path.ItemPath; | ||
import com.evolveum.midpoint.repo.sqale.SqaleQueryContext; | ||
import com.evolveum.midpoint.repo.sqale.update.NestedContainerUpdateContext; | ||
import com.evolveum.midpoint.repo.sqale.update.SqaleUpdateContext; | ||
import com.evolveum.midpoint.repo.sqlbase.SqlQueryContext; | ||
import com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase; | ||
|
||
/** | ||
* Resolver that maps the container item to the count column. | ||
* | ||
* @param <S> schema type for the nested container | ||
* @param <Q> query type of entity where the mapping is nested and declared | ||
* @param <R> row type of {@link Q} | ||
*/ | ||
public class CountMappingResolver<S extends Containerable, Q extends FlexibleRelationalPathBase<R>, R> | ||
implements SqaleItemRelationResolver<Q, R, Q, R> { | ||
|
||
private final Function<Q, NumberPath<Integer>> rootToCount; | ||
|
||
public CountMappingResolver(Function<Q, NumberPath<Integer>> rootToCount) { | ||
this.rootToCount = rootToCount; | ||
} | ||
|
||
/** Should not be called, the count must be treated before this happens. */ | ||
@Override | ||
public ResolutionResult<Q, R> resolve(SqlQueryContext<?, Q, R> context) { | ||
throw new UnsupportedOperationException("resolution not supported for count mapping"); | ||
} | ||
|
||
@Override | ||
public NestedContainerUpdateContext<S, Q, R> resolve( | ||
SqaleUpdateContext<?, Q, R> context, ItemPath ignored) { | ||
throw new UnsupportedOperationException("TODO"); | ||
// TODO test for ShadowType.pendingOperation modification is needed | ||
// return new NestedContainerUpdateContext<>(context, mapping); | ||
} | ||
|
||
/** This creates the predicate representing the EXISTS filter. */ | ||
public Predicate createExistsPredicate(SqaleQueryContext<?, Q, R> context) { | ||
return rootToCount.apply(context.path()).gt(0); | ||
} | ||
} |
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.