Search in sources :

Example 1 with ExpressionUtils

use of com.querydsl.core.types.ExpressionUtils in project querydsl by querydsl.

the class AbstractMongodbQuery method createJoinFilter.

@SuppressWarnings("unchecked")
@Nullable
protected Predicate createJoinFilter(QueryMetadata metadata) {
    Map<Expression<?>, Predicate> predicates = new HashMap<>();
    List<JoinExpression> joins = metadata.getJoins();
    for (int i = joins.size() - 1; i >= 0; i--) {
        JoinExpression join = joins.get(i);
        Path<?> source = (Path) ((Operation<?>) join.getTarget()).getArg(0);
        Path<?> target = (Path) ((Operation<?>) join.getTarget()).getArg(1);
        final Predicate extraFilters = predicates.get(target.getRoot());
        Predicate filter = ExpressionUtils.allOf(join.getCondition(), extraFilters);
        List<? extends Object> ids = getIds(target.getType(), filter);
        if (ids.isEmpty()) {
            throw new NoResults();
        }
        Path<?> path = ExpressionUtils.path(String.class, source, "$id");
        predicates.merge(source.getRoot(), ExpressionUtils.in((Path<Object>) path, ids), ExpressionUtils::and);
    }
    Path<?> source = (Path) ((Operation) joins.get(0).getTarget()).getArg(0);
    return predicates.get(source.getRoot());
}
Also used : Path(com.querydsl.core.types.Path) ParamExpression(com.querydsl.core.types.ParamExpression) Expression(com.querydsl.core.types.Expression) JoinExpression(com.querydsl.core.JoinExpression) FactoryExpression(com.querydsl.core.types.FactoryExpression) HashMap(java.util.HashMap) JoinExpression(com.querydsl.core.JoinExpression) ExpressionUtils(com.querydsl.core.types.ExpressionUtils) Predicate(com.querydsl.core.types.Predicate) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JoinExpression (com.querydsl.core.JoinExpression)1 Expression (com.querydsl.core.types.Expression)1 ExpressionUtils (com.querydsl.core.types.ExpressionUtils)1 FactoryExpression (com.querydsl.core.types.FactoryExpression)1 ParamExpression (com.querydsl.core.types.ParamExpression)1 Path (com.querydsl.core.types.Path)1 Predicate (com.querydsl.core.types.Predicate)1 HashMap (java.util.HashMap)1 Nullable (org.jetbrains.annotations.Nullable)1