DATACMNS-1063 - Polishing.

Add deleteById accepting Publisher and alter JavaDoc to be more explicit about illegal arguments.

Original Pull Request: #226
This commit is contained in:
Christoph Strobl
2017-06-13 10:04:07 +02:00
parent 9f1af1fb09
commit f913aa7439
2 changed files with 47 additions and 26 deletions

View File

@@ -27,6 +27,7 @@ import org.springframework.data.repository.Repository;
* and uses Project Reactor types which are built on top of Reactive Streams.
*
* @author Mark Paluch
* @author Christph Strobl
* @since 2.0
* @see Mono
* @see Flux
@@ -39,7 +40,8 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
* entity instance completely.
*
* @param entity must not be {@literal null}.
* @return the saved entity.
* @return {@link Mono} emitting the saved entity.
* @throws IllegalArgumentException in case the given {@code entity} is {@literal null}.
*/
<S extends T> Mono<S> save(S entity);
@@ -47,8 +49,8 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
* Saves all given entities.
*
* @param entities must not be {@literal null}.
* @return the saved entities.
* @throws IllegalArgumentException in case the given entity is {@literal null}.
* @return {@link Flux} emitting the saved entities.
* @throws IllegalArgumentException in case the given {@link Iterable} {@code entities} is {@literal null}.
*/
<S extends T> Flux<S> saveAll(Iterable<S> entities);
@@ -56,8 +58,8 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
* Saves all given entities.
*
* @param entityStream must not be {@literal null}.
* @return the saved entities.
* @throws IllegalArgumentException in case the given {@code Publisher} is {@literal null}.
* @return {@link Flux} emitting the saved entities.
* @throws IllegalArgumentException in case the given {@code Publisher} {@code entityStream} is {@literal null}.
*/
<S extends T> Flux<S> saveAll(Publisher<S> entityStream);
@@ -65,66 +67,68 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
* Retrieves an entity by its id.
*
* @param id must not be {@literal null}.
* @return the entity with the given id or {@link Mono#empty()} if none found.
* @throws IllegalArgumentException if {@code id} is {@literal null}.
* @return {@link Mono} emitting the entity with the given id or {@link Mono#empty()} if none found.
* @throws IllegalArgumentException in case the given {@code id} is {@literal null}.
*/
Mono<T> findById(ID id);
/**
* Retrieves an entity by its id supplied by a {@link Mono}.
* Retrieves an entity by its id supplied by a {@link Publisher}.
*
* @param id must not be {@literal null}. Uses the first emitted element to perform the find-query.
* @return the entity with the given id or {@link Mono#empty()} if none found.
* @throws IllegalArgumentException if {@code id} is {@literal null}.
* @return {@link Mono} emitting the entity with the given id or {@link Mono#empty()} if none found.
* @throws IllegalArgumentException in case the given {@link Publisher} {@code id} is {@literal null}.
*/
Mono<T> findById(Publisher<ID> id);
/**
* Returns whether an entity with the given id exists.
* Returns whether an entity with the id exists.
*
* @param id must not be {@literal null}.
* @return {@literal true} if an entity with the given id exists, {@literal false} otherwise.
* @throws IllegalArgumentException if {@code id} is {@literal null}.
* @return {@link Mono} emitting {@literal true} if an entity with the given id exists, {@literal false} otherwise.
* @throws IllegalArgumentException in case the given {@code id} is {@literal null}.
*/
Mono<Boolean> existsById(ID id);
/**
* Returns whether an entity with the given id, supplied by a {@link Mono}, exists. Uses the first emitted element to
* perform the exists-query.
* Returns whether an entity with the given id, supplied by a {@link Publisher}, exists. Uses the first emitted
* element to perform the exists-query.
*
* @param id must not be {@literal null}.
* @return {@literal true} if an entity with the given id exists, {@literal false} otherwise
* @throws IllegalArgumentException if {@code id} is {@literal null}
* @return {@link Mono} emitting {@literal true} if an entity with the given id exists, {@literal false} otherwise
* @throws IllegalArgumentException in case the given {@link Publisher} {@code id} is {@literal null}.
*/
Mono<Boolean> existsById(Publisher<ID> id);
/**
* Returns all instances of the type.
*
* @return all entities.
* @return {@link Flux} emitting all entities.
*/
Flux<T> findAll();
/**
* Returns all instances of the type with the given IDs.
* Returns all instances with the given IDs.
*
* @param ids must not be {@literal null}.
* @return the found entities.
* @return {@link Flux} emitting the found entities.
* @throws IllegalArgumentException in case the given {@link Iterable} {@code ids} is {@literal null}.
*/
Flux<T> findAllById(Iterable<ID> ids);
/**
* Returns all instances of the type with the given IDs.
* Returns all instances of the type with the given IDs supplied by a {@link Publisher}.
*
* @param idStream must not be {@literal null}.
* @return the found entities.
* @return {@link Flux} emitting the found entities.
* @throws IllegalArgumentException in case the given {@link Publisher} {@code idStream} is {@literal null}.
*/
Flux<T> findAllById(Publisher<ID> idStream);
/**
* Returns the number of entities available.
*
* @return the number of entities.
* @return {@link Mono} emitting the number of entities.
*/
Mono<Long> count();
@@ -132,14 +136,25 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
* Deletes the entity with the given id.
*
* @param id must not be {@literal null}.
* @return {@link Mono} signaling when operation has completed.
* @throws IllegalArgumentException in case the given {@code id} is {@literal null}.
*/
Mono<Void> deleteById(ID id);
/**
* Deletes the entity with the given id supplied by a {@link Publisher}.
*
* @param id must not be {@literal null}.
* @return {@link Mono} signaling when operation has completed.
* @throws IllegalArgumentException in case the given {@link Publisher} {@code id} is {@literal null}.
*/
Mono<Void> deleteById(Publisher<ID> id);
/**
* Deletes a given entity.
*
* @param entity must not be {@literal null}.
* @return {@link Mono} signaling when operation has completed.
* @throws IllegalArgumentException in case the given entity is {@literal null}.
*/
Mono<Void> delete(T entity);
@@ -148,20 +163,24 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
* Deletes the given entities.
*
* @param entities must not be {@literal null}.
* @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}.
* @return {@link Mono} signaling when operation has completed.
* @throws IllegalArgumentException in case the given {@link Iterable} {@code entities} is {@literal null}.
*/
Mono<Void> deleteAll(Iterable<? extends T> entities);
/**
* Deletes the given entities.
* Deletes the given entities supplied by a {@link Publisher}.
*
* @param entityStream must not be {@literal null}.
* @throws IllegalArgumentException in case the given {@link Publisher} is {@literal null}.
* @return {@link Mono} signaling when operation has completed.
* @throws IllegalArgumentException in case the given {@link Publisher} {@code entityStream} is {@literal null}.
*/
Mono<Void> deleteAll(Publisher<? extends T> entityStream);
/**
* Deletes all entities managed by the repository.
*
* @return {@link Mono} signaling when operation has completed.
*/
Mono<Void> deleteAll();
}

View File

@@ -26,6 +26,7 @@ import org.springframework.data.repository.NoRepositoryBean;
* abstraction.
*
* @author Mark Paluch
* @author Christoph Strobl
* @since 2.0
* @see Sort
* @see Mono
@@ -39,6 +40,7 @@ public interface ReactiveSortingRepository<T, ID> extends ReactiveCrudRepository
*
* @param sort must not be {@literal null}.
* @return all entities sorted by the given options.
* @throws IllegalArgumentException in case the given {@link Sort} is {@literal null}.
*/
Flux<T> findAll(Sort sort);
}