|
| 1 | +/* |
| 2 | + * Copyright 2022 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.data.querydsl; |
| 17 | + |
| 18 | +import java.util.List; |
| 19 | +import java.util.Optional; |
| 20 | +import java.util.function.Function; |
| 21 | + |
| 22 | +import org.springframework.data.domain.Page; |
| 23 | +import org.springframework.data.domain.Pageable; |
| 24 | +import org.springframework.data.domain.Sort; |
| 25 | +import org.springframework.data.repository.query.FluentQuery; |
| 26 | + |
| 27 | +import com.querydsl.core.types.OrderSpecifier; |
| 28 | +import com.querydsl.core.types.Predicate; |
| 29 | + |
| 30 | +/** |
| 31 | + * Interface to allow execution of QueryDsl {@link Predicate} instances.This identical to * |
| 32 | + * {@link QuerydslPredicateExecutor} but returns {@link List} instead of {@link Iterable} where applicable. |
| 33 | + * |
| 34 | + * @author Jens Schauder |
| 35 | + * @since 3.0 |
| 36 | + * @see QuerydslPredicateExecutor |
| 37 | + */ |
| 38 | +public interface ListQuerydslPredicateExecutor<T> { |
| 39 | + |
| 40 | + /** |
| 41 | + * Returns a single entity matching the given {@link Predicate} or {@link Optional#empty()} if none was found. |
| 42 | + * |
| 43 | + * @param predicate must not be {@literal null}. |
| 44 | + * @return a single entity matching the given {@link Predicate} or {@link Optional#empty()} if none was found. |
| 45 | + * @throws org.springframework.dao.IncorrectResultSizeDataAccessException if the predicate yields more than one |
| 46 | + * result. |
| 47 | + */ |
| 48 | + Optional<T> findOne(Predicate predicate); |
| 49 | + |
| 50 | + /** |
| 51 | + * Returns all entities matching the given {@link Predicate}. In case no match could be found an empty {@link List} is |
| 52 | + * returned. |
| 53 | + * |
| 54 | + * @param predicate must not be {@literal null}. |
| 55 | + * @return all entities matching the given {@link Predicate}. |
| 56 | + */ |
| 57 | + List<T> findAll(Predicate predicate); |
| 58 | + |
| 59 | + /** |
| 60 | + * Returns all entities matching the given {@link Predicate} applying the given {@link Sort}. In case no match could |
| 61 | + * be found an empty {@link List} is returned. |
| 62 | + * |
| 63 | + * @param predicate must not be {@literal null}. |
| 64 | + * @param sort the {@link Sort} specification to sort the results by, may be {@link Sort#unsorted()}, must not be |
| 65 | + * {@literal null}. |
| 66 | + * @return all entities matching the given {@link Predicate}. |
| 67 | + */ |
| 68 | + List<T> findAll(Predicate predicate, Sort sort); |
| 69 | + |
| 70 | + /** |
| 71 | + * Returns all entities matching the given {@link Predicate} applying the given {@link OrderSpecifier}s. In case no |
| 72 | + * match could be found an empty {@link List} is returned. |
| 73 | + * |
| 74 | + * @param predicate must not be {@literal null}. |
| 75 | + * @param orders the {@link OrderSpecifier}s to sort the results by, must not be {@literal null}. |
| 76 | + * @return all entities matching the given {@link Predicate} applying the given {@link OrderSpecifier}s. |
| 77 | + */ |
| 78 | + List<T> findAll(Predicate predicate, OrderSpecifier<?>... orders); |
| 79 | + |
| 80 | + /** |
| 81 | + * Returns all entities ordered by the given {@link OrderSpecifier}s. |
| 82 | + * |
| 83 | + * @param orders the {@link OrderSpecifier}s to sort the results by, must not be {@literal null}. |
| 84 | + * @return all entities ordered by the given {@link OrderSpecifier}s. |
| 85 | + */ |
| 86 | + List<T> findAll(OrderSpecifier<?>... orders); |
| 87 | + |
| 88 | + /** |
| 89 | + * Returns a {@link Page} of entities matching the given {@link Predicate}. In case no match could be found, an empty |
| 90 | + * {@link Page} is returned. |
| 91 | + * |
| 92 | + * @param predicate must not be {@literal null}. |
| 93 | + * @param pageable may be {@link Pageable#unpaged()}, must not be {@literal null}. |
| 94 | + * @return a {@link Page} of entities matching the given {@link Predicate}. |
| 95 | + */ |
| 96 | + Page<T> findAll(Predicate predicate, Pageable pageable); |
| 97 | + |
| 98 | + /** |
| 99 | + * Returns the number of instances matching the given {@link Predicate}. |
| 100 | + * |
| 101 | + * @param predicate the {@link Predicate} to count instances for, must not be {@literal null}. |
| 102 | + * @return the number of instances matching the {@link Predicate}. |
| 103 | + */ |
| 104 | + long count(Predicate predicate); |
| 105 | + |
| 106 | + /** |
| 107 | + * Checks whether the data store contains elements that match the given {@link Predicate}. |
| 108 | + * |
| 109 | + * @param predicate the {@link Predicate} to use for the existence check, must not be {@literal null}. |
| 110 | + * @return {@literal true} if the data store contains elements that match the given {@link Predicate}. |
| 111 | + */ |
| 112 | + boolean exists(Predicate predicate); |
| 113 | + |
| 114 | + /** |
| 115 | + * Returns entities matching the given {@link Predicate} applying the {@link Function queryFunction} that defines the |
| 116 | + * query and its result type. |
| 117 | + * |
| 118 | + * @param predicate must not be {@literal null}. |
| 119 | + * @param queryFunction the query function defining projection, sorting, and the result type |
| 120 | + * @return all entities matching the given {@link Predicate}. |
| 121 | + */ |
| 122 | + <S extends T, R> R findBy(Predicate predicate, Function<FluentQuery.FetchableFluentQuery<S>, R> queryFunction); |
| 123 | +} |
0 commit comments