Skip to content

DATACMNS-995 - Create ReactiveQueryByExampleExecutor allowing reactive query by example. #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.0.0.DATACMNS-995-SNAPSHOT</version>

<name>Spring Data Core</name>

Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ public interface QueryByExampleExecutor<T> {
/**
* Returns a single entity matching the given {@link Example} or {@literal null} if none was found.
*
* @param example can be {@literal null}.
* @param example must not be {@literal null}.
* @return a single entity matching the given {@link Example} or {@link Optional#empty()} if none was found.
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if the Example yields more than one result.
*/
@@ -45,7 +45,7 @@ public interface QueryByExampleExecutor<T> {
* 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}.
* @param example must not be {@literal null}.
* @return all entities matching the given {@link Example}.
*/
<S extends T> Iterable<S> findAll(Example<S> example);
@@ -54,7 +54,7 @@ public interface QueryByExampleExecutor<T> {
* 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 example must not 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}.
* @since 1.10
@@ -65,7 +65,7 @@ public interface QueryByExampleExecutor<T> {
* Returns a {@link Page} of entities matching the given {@link Example}. In case no match could be found, an empty
* {@link Page} is returned.
*
* @param example can be {@literal null}.
* @param example must not be {@literal null}.
* @param pageable can be {@literal null}.
* @return a {@link Page} of entities matching the given {@link Example}.
*/
@@ -74,15 +74,15 @@ public interface QueryByExampleExecutor<T> {
/**
* Returns the number of instances matching the given {@link Example}.
*
* @param example the {@link Example} to count instances for, can be {@literal null}.
* @param example the {@link Example} to count instances for. Must not be {@literal null}.
* @return the number of instances matching the {@link Example}.
*/
<S extends T> long count(Example<S> 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}.
* @param example the {@link Example} to use for the existence check. Must not be {@literal null}.
* @return {@literal true} if the data store contains elements that match the given {@link Example}.
*/
<S extends T> boolean exists(Example<S> example);
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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 <T>
* @author Mark Paluch
* @author Christoph Strobl
* @since 2.0
*/
public interface ReactiveQueryByExampleExecutor<T> {

/**
* Returns a single entity matching the given {@link Example} or {@link Mono#empty()} if none was found.
*
* @param example must not be {@literal null}.
* @return a single entity matching the given {@link Example} or {@link Mono#empty()} if none was found.
* @throws @throws org.springframework.dao.IncorrectResultSizeDataAccessException if the example yields more than one
* result.
*/
<S extends T> Mono<S> findOne(Example<S> example);

/**
* Returns all entities matching the given {@link Example}. In case no match could be found {@link Flux#empty()} is
* returned.
*
* @param example must not be {@literal null}.
* @return all entities matching the given {@link Example}.
*/
<S extends T> Flux<S> findAll(Example<S> example);

/**
* Returns all entities matching the given {@link Example} applying the given {@link Sort}. In case no match could be
* found {@link Flux#empty()} is returned.
*
* @param example must not 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}.
*/
<S extends T> Flux<S> findAll(Example<S> example, Sort sort);

/**
* Returns the number of instances matching the given {@link Example}.
*
* @param example the {@link Example} to count instances for. Must not be {@literal null}.
* @return the number of instances matching the {@link Example}.
*/
<S extends T> Mono<Long> count(Example<S> 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. Must not be {@literal null}.
* @return {@literal true} if the data store contains elements that match the given {@link Example}.
*/
<S extends T> Mono<Boolean> exists(Example<S> example);
}