Skip to content

Commit

Permalink
repo-sqale: CountMappingResolver simplified to ItemRelationResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Jul 8, 2021
1 parent 86d4483 commit f3d13b5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ private <TQ extends FlexibleRelationalPathBase<TR>, TR> Predicate process(
}

ItemRelationResolver<Q, R, TQ, TR> resolver = mapping.relationResolver(path);
// 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);
// Instead of cleaner solution that would follow the code lower we resolve it here and now.
// "Clean" solution would require more classes/code and would be more confusing.
if (resolver instanceof CountMappingResolver<?, ?>) {
return ((CountMappingResolver<Q, R>) resolver).createExistsPredicate(context);
}

ItemRelationResolver.ResolutionResult<TQ, TR> resolution = resolver.resolve(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,19 @@
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.mapping.ItemRelationResolver;
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> {
public class CountMappingResolver<Q extends FlexibleRelationalPathBase<R>, R>
implements ItemRelationResolver<Q, R, Q, R> {

private final Function<Q, NumberPath<Integer>> rootToCount;

Expand All @@ -41,14 +37,6 @@ 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);
Expand Down

0 comments on commit f3d13b5

Please sign in to comment.