private Predicate allOf(Collection<Predicate> predicates) { return predicates != null ? ExpressionUtils.allOf(predicates) : null; }
private Predicate allOf(Collection<Predicate> predicates) { return predicates != null ? ExpressionUtils.allOf(predicates) : null; }
/** * Create a {@code this or all(predicates)} expression * * <p>Return a union of this and the intersection of the given predicates</p> * * @param predicates intersection of predicates * @return this or all(predicates) */ public BooleanExpression orAllOf(Predicate... predicates) { return or(ExpressionUtils.allOf(predicates)); }
/** * Create the union of this and the intersection of the given args * {@code (this || (arg1 && arg2 ... && argN))} * * @param args intersection of predicates * @return the current object */ public BooleanBuilder orAllOf(Predicate... args) { if (args.length > 0) { or(ExpressionUtils.allOf(args)); } return this; }
public Q on(Predicate... conditions) { return queryMixin.where(ExpressionUtils.predicate( MongodbOps.ELEM_MATCH, collection, ExpressionUtils.allOf(conditions))); }
/** * Add the given where conditions. * * @param conditions must not be {@literal null}. * @return the target {@link QueryMixin}. * @see QueryMixin#where(Predicate) */ public Q on(Predicate... conditions) { return queryMixin .where(ExpressionUtils.predicate(MongodbOps.ELEM_MATCH, collection, ExpressionUtils.allOf(conditions))); } }
@Nullable protected Predicate createFilter(QueryMetadata metadata) { Predicate filter; if (!metadata.getJoins().isEmpty()) { filter = ExpressionUtils.allOf(metadata.getWhere(), createJoinFilter(metadata)); } else { filter = metadata.getWhere(); } return filter; }
@Nullable protected Predicate createFilter(QueryMetadata metadata) { Predicate filter; if (!metadata.getJoins().isEmpty()) { filter = ExpressionUtils.allOf(metadata.getWhere(), createJoinFilter(metadata)); } else { filter = metadata.getWhere(); } return filter; }
protected Mono<Predicate> createFilter(QueryMetadata metadata) { if (!metadata.getJoins().isEmpty()) { return createJoinFilter(metadata).map(it -> ExpressionUtils.allOf(metadata.getWhere(), it)) .switchIfEmpty(Mono.justOrEmpty(metadata.getWhere())); } return Mono.justOrEmpty(metadata.getWhere()); }
@SuppressWarnings("unchecked") @Nullable protected Predicate createJoinFilter(QueryMetadata metadata) { Multimap<Expression<?>, Predicate> predicates = HashMultimap.create(); 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); Collection<Predicate> extraFilters = predicates.get(target.getRoot()); Predicate filter = ExpressionUtils.allOf(join.getCondition(), allOf(extraFilters)); List<? extends Object> ids = getIds(target.getType(), filter); if (ids.isEmpty()) { throw new NoResults(); } Path<?> path = ExpressionUtils.path(String.class, source, "$id"); predicates.put(source.getRoot(), ExpressionUtils.in((Path<Object>) path, ids)); } Path<?> source = (Path) ((Operation) joins.get(0).getTarget()).getArg(0); return allOf(predicates.get(source.getRoot())); }
@SuppressWarnings("unchecked") @Nullable protected Predicate createJoinFilter(QueryMetadata metadata) { LinkedMultiValueMap<Expression<?>, Predicate> predicates = new LinkedMultiValueMap<>(); 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); Collection<Predicate> extraFilters = predicates.get(target.getRoot()); Predicate filter = ExpressionUtils.allOf(join.getCondition(), allOf(extraFilters)); List<? extends Object> ids = getIds(target.getType(), filter); if (ids.isEmpty()) { return ExpressionUtils.predicate(QuerydslMongoOps.NO_MATCH, source); } Path<?> path = ExpressionUtils.path(String.class, source, "$id"); predicates.add(source.getRoot(), ExpressionUtils.in((Path<Object>) path, ids)); } Path<?> source = (Path) ((Operation) joins.get(0).getTarget()).getArg(0); return allOf(predicates.get(source.getRoot())); }
private Predicate allOf(Collection<Predicate> predicates) { return predicates != null ? ExpressionUtils.allOf(predicates) : null; }
Collection<Mono<Predicate>> extraFilters = predicates.get(target.getRoot()); Mono<Predicate> filter = allOf(extraFilters).map(it -> ExpressionUtils.allOf(join.getCondition(), it)) .switchIfEmpty(Mono.justOrEmpty(join.getCondition()));
/** * Add the given where conditions. * * @param conditions must not be {@literal null}. * @return the target {@link QueryMixin}. * @see QueryMixin#where(Predicate) */ public Q on(Predicate... conditions) { return queryMixin .where(ExpressionUtils.predicate(MongodbOps.ELEM_MATCH, collection, ExpressionUtils.allOf(conditions))); } }
@Nullable protected Predicate createFilter(QueryMetadata metadata) { Predicate filter; if (!metadata.getJoins().isEmpty()) { filter = ExpressionUtils.allOf(metadata.getWhere(), createJoinFilter(metadata)); } else { filter = metadata.getWhere(); } return filter; }
@SuppressWarnings("unchecked") @Nullable protected Predicate createJoinFilter(QueryMetadata metadata) { LinkedMultiValueMap<Expression<?>, Predicate> predicates = new LinkedMultiValueMap<>(); 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); Collection<Predicate> extraFilters = predicates.get(target.getRoot()); Predicate filter = ExpressionUtils.allOf(join.getCondition(), allOf(extraFilters)); List<? extends Object> ids = getIds(target.getType(), filter); if (ids.isEmpty()) { return ExpressionUtils.predicate(QuerydslMongoOps.NO_MATCH, source); } Path<?> path = ExpressionUtils.path(String.class, source, "$id"); predicates.add(source.getRoot(), ExpressionUtils.in((Path<Object>) path, ids)); } Path<?> source = (Path) ((Operation) joins.get(0).getTarget()).getArg(0); return allOf(predicates.get(source.getRoot())); }
/** * 用and组合多个条件 * * @param predicate 多个条件 * @return 最终条件 */ @Nullable default Predicate predicates(@Nonnull Predicate... predicate) { return ExpressionUtils.allOf(predicate); }
/** * 用and组合多个条件,等同predicates * * @param predicate 多个条件 * @return 最终条件 */ @Nullable default Predicate and(@Nonnull Predicate... predicate) { return ExpressionUtils.allOf(predicate); }
/** * 删除 * * @param id ID * @param predicate 条件 * @return 变更条数 */ default long delete(long id, @Nullable Predicate... predicate) { return delete(pk().eq(id), null == predicate ? null : ExpressionUtils.allOf(predicate)); }
/** * 是否存在 * * @param id 主键ID * @param predicate 条件 * @return 是否存在 */ default boolean exists(long id, @Nullable Predicate... predicate) { return exists(pk().eq(id), null == predicate ? null : ExpressionUtils.allOf(predicate)); }