From 1158b5fedaf4c86e6edbc4d5eec940ee355d4f82 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 22 Feb 2017 09:50:47 -0500 Subject: [PATCH] DATACMNS-995 - Create ReactiveQueryByExampleExecutor allowing reactive query by example. Provide a mix-in interface to be used in store modules providing reactive Query by Example query execution. Mono findOne(Example sample); Flux findAll(Example sample); Mono count(Example sample); //... Original Pull Request: #197 --- .../query/ReactiveQueryByExampleExecutor.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/main/java/org/springframework/data/repository/query/ReactiveQueryByExampleExecutor.java diff --git a/src/main/java/org/springframework/data/repository/query/ReactiveQueryByExampleExecutor.java b/src/main/java/org/springframework/data/repository/query/ReactiveQueryByExampleExecutor.java new file mode 100644 index 000000000..cff9890b5 --- /dev/null +++ b/src/main/java/org/springframework/data/repository/query/ReactiveQueryByExampleExecutor.java @@ -0,0 +1,75 @@ +/* + * Copyright 2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.repository.query; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import org.springframework.data.domain.Example; +import org.springframework.data.domain.Sort; + +/** + * Interface to allow execution of Query by Example {@link Example} instances using a reactive infrastructure. + * + * @param + * @author Mark Paluch + * @since 2.0 + */ +public interface ReactiveQueryByExampleExecutor { + + /** + * Returns a single entity matching the given {@link Example} or {@literal null} if none was found. + * + * @param example can be {@literal null}. + * @return a single entity matching the given {@link Example} or {@literal null} if none was found. + */ + Mono findOne(Example example); + + /** + * Returns all entities matching the given {@link Example}. In case no match could be found an empty {@link Iterable} + * is returned. + * + * @param example can be {@literal null}. + * @return all entities matching the given {@link Example}. + */ + Flux findAll(Example example); + + /** + * Returns all entities matching the given {@link Example} applying the given {@link Sort}. In case no match could be + * found an empty {@link Iterable} is returned. + * + * @param example can be {@literal null}. + * @param sort the {@link Sort} specification to sort the results by, must not be {@literal null}. + * @return all entities matching the given {@link Example}. + */ + Flux findAll(Example example, Sort sort); + + /** + * Returns the number of instances matching the given {@link Example}. + * + * @param example the {@link Example} to count instances for, can be {@literal null}. + * @return the number of instances matching the {@link Example}. + */ + Mono count(Example example); + + /** + * Checks whether the data store contains elements that match the given {@link Example}. + * + * @param example the {@link Example} to use for the existence check, can be {@literal null}. + * @return {@literal true} if the data store contains elements that match the given {@link Example}. + */ + Mono exists(Example example); +}