|
| 1 | +/* |
| 2 | + * Copyright 2020-2021 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.repository.reactive; |
| 17 | + |
| 18 | +import io.smallrye.mutiny.Multi; |
| 19 | +import io.smallrye.mutiny.Uni; |
| 20 | +import io.smallrye.mutiny.operators.uni.UniNever; |
| 21 | +import org.springframework.data.repository.NoRepositoryBean; |
| 22 | +import org.springframework.data.repository.Repository; |
| 23 | + |
| 24 | +/** |
| 25 | + * Interface for generic CRUD operations on a repository for a specific type. This repository follows reactive paradigms |
| 26 | + * and uses SmallRye Mutiny types, see:https://smallrye.io/smallrye-mutiny/. |
| 27 | + * |
| 28 | + * @author Hantsy Bai |
| 29 | + * @since 2.6 |
| 30 | + * @see io.smallrye.mutiny.Uni |
| 31 | + * @see io.smallrye.mutiny.Multi |
| 32 | + */ |
| 33 | +@NoRepositoryBean |
| 34 | +public interface MutinyCrudRepository<T, ID> extends Repository<T, ID> { |
| 35 | + |
| 36 | + /** |
| 37 | + * Saves a given entity. Use the returned instance for further operations as the save operation might have changed the |
| 38 | + * entity instance completely. |
| 39 | + * |
| 40 | + * @param entity must not be {@literal null}. |
| 41 | + * @return {@link Uni} emitting the saved entity. |
| 42 | + * @throws IllegalArgumentException in case the given {@literal entity} is {@literal null}. |
| 43 | + */ |
| 44 | + <S extends T> Uni<S> save(S entity); |
| 45 | + |
| 46 | + /** |
| 47 | + * Saves all given entities. |
| 48 | + * |
| 49 | + * @param entities must not be {@literal null}. |
| 50 | + * @return {@link Multi} emitting the saved entities. |
| 51 | + * @throws IllegalArgumentException in case the given {@link Iterable entities} or one of its entities is |
| 52 | + * {@literal null}. |
| 53 | + */ |
| 54 | + <S extends T> Multi<S> saveAll(Iterable<S> entities); |
| 55 | + |
| 56 | + /** |
| 57 | + * Saves all given entities. |
| 58 | + * |
| 59 | + * @param entityStream must not be {@literal null}. |
| 60 | + * @return {@link Multi} emitting the saved entities. |
| 61 | + * @throws IllegalArgumentException in case the given {@link Multi entityStream} is {@literal null}. |
| 62 | + */ |
| 63 | + <S extends T> Multi<S> saveAll(Multi<S> entityStream); |
| 64 | + |
| 65 | + /** |
| 66 | + * Retrieves an entity by its id. |
| 67 | + * |
| 68 | + * @param id must not be {@literal null}. |
| 69 | + * @return {@link Uni} emitting the entity with the given id or {@link UniNever} if none found. |
| 70 | + * @throws IllegalArgumentException in case the given {@literal id} is {@literal null}. |
| 71 | + */ |
| 72 | + Uni<T> findById(ID id); |
| 73 | + |
| 74 | + /** |
| 75 | + * Retrieves an entity by its id supplied by a {@link Uni}. |
| 76 | + * |
| 77 | + * @param id must not be {@literal null}. Uses the first emitted element to perform the find-query. |
| 78 | + * @return {@link Uni} emitting the entity with the given id or {@link UniNever} if none found. |
| 79 | + * @throws IllegalArgumentException in case the given {@link Uni id} is {@literal null}. |
| 80 | + */ |
| 81 | + Uni<T> findById(Uni<ID> id); |
| 82 | + |
| 83 | + /** |
| 84 | + * Returns whether an entity with the given {@literal id} exists. |
| 85 | + * |
| 86 | + * @param id must not be {@literal null}. |
| 87 | + * @return {@link Uni} emitting {@literal true} if an entity with the given id exists, {@literal false} otherwise. |
| 88 | + * @throws IllegalArgumentException in case the given {@literal id} is {@literal null}. |
| 89 | + */ |
| 90 | + Uni<Boolean> existsById(ID id); |
| 91 | + |
| 92 | + /** |
| 93 | + * Returns whether an entity with the given id, supplied by a {@link Uni}, exists. |
| 94 | + * |
| 95 | + * @param id must not be {@literal null}. |
| 96 | + * @return {@link Uni} emitting {@literal true} if an entity with the given id exists, {@literal false} otherwise. |
| 97 | + * @throws IllegalArgumentException in case the given {@link Uni id} is {@literal null}. |
| 98 | + */ |
| 99 | + Uni<Boolean> existsById(Uni<ID> id); |
| 100 | + |
| 101 | + /** |
| 102 | + * Returns all instances of the type. |
| 103 | + * |
| 104 | + * @return {@link Multi} emitting all entities. |
| 105 | + */ |
| 106 | + Multi<T> findAll(); |
| 107 | + |
| 108 | + /** |
| 109 | + * Returns all instances of the type {@code T} with the given IDs. |
| 110 | + * <p> |
| 111 | + * If some or all ids are not found, no entities are returned for these IDs. |
| 112 | + * <p> |
| 113 | + * Note that the order of elements in the result is not guaranteed. |
| 114 | + * |
| 115 | + * @param ids must not be {@literal null} nor contain any {@literal null} values. |
| 116 | + * @return {@link Multi} emitting the found entities. The size can be equal or less than the number of given |
| 117 | + * {@literal ids}. |
| 118 | + * @throws IllegalArgumentException in case the given {@link Iterable ids} or one of its items is {@literal null}. |
| 119 | + */ |
| 120 | + Multi<T> findAllById(Iterable<ID> ids); |
| 121 | + |
| 122 | + /** |
| 123 | + * Returns all instances of the type {@code T} with the given IDs supplied by a {@link Multi}. |
| 124 | + * <p> |
| 125 | + * If some or all ids are not found, no entities are returned for these IDs. |
| 126 | + * <p> |
| 127 | + * Note that the order of elements in the result is not guaranteed. |
| 128 | + * |
| 129 | + * @param idStream must not be {@literal null}. |
| 130 | + * @return {@link Multi} emitting the found entities. |
| 131 | + * @throws IllegalArgumentException in case the given {@link Multi idStream} is {@literal null}. |
| 132 | + */ |
| 133 | + Multi<T> findAllById(Multi<ID> idStream); |
| 134 | + |
| 135 | + /** |
| 136 | + * Returns the number of entities available. |
| 137 | + * |
| 138 | + * @return {@link Uni} emitting the number of entities. |
| 139 | + */ |
| 140 | + Uni<Long> count(); |
| 141 | + |
| 142 | + /** |
| 143 | + * Deletes the entity with the given id. |
| 144 | + * |
| 145 | + * @param id must not be {@literal null}. |
| 146 | + * @return {@link Uni} signaling when operation has completed. |
| 147 | + * @throws IllegalArgumentException in case the given {@literal id} is {@literal null}. |
| 148 | + */ |
| 149 | + Uni<Void> deleteById(ID id); |
| 150 | + |
| 151 | + /** |
| 152 | + * Deletes a given entity. |
| 153 | + * |
| 154 | + * @param entity must not be {@literal null}. |
| 155 | + * @return {@link Uni} signaling when operation has completed. |
| 156 | + * @throws IllegalArgumentException in case the given entity is {@literal null}. |
| 157 | + */ |
| 158 | + Uni<Void> delete(T entity); |
| 159 | + |
| 160 | + /** |
| 161 | + * Deletes all instances of the type {@code T} with the given IDs. |
| 162 | + * |
| 163 | + * @param ids must not be {@literal null}. |
| 164 | + * @return {@link Uni} signaling when operation has completed. |
| 165 | + * @throws IllegalArgumentException in case the given {@literal ids} or one of its elements is {@literal null}. |
| 166 | + * {@literal null}. |
| 167 | + * @since 2.5 |
| 168 | + */ |
| 169 | + Uni<Void> deleteAllById(Iterable<? extends ID> ids); |
| 170 | + |
| 171 | + /** |
| 172 | + * Deletes the given entities. |
| 173 | + * |
| 174 | + * @param entities must not be {@literal null}. |
| 175 | + * @return {@link Uni} signaling when operation has completed. |
| 176 | + * @throws IllegalArgumentException in case the given {@link Iterable entities} or one of its entities is |
| 177 | + * {@literal null}. |
| 178 | + */ |
| 179 | + Uni<Void> deleteAll(Iterable<? extends T> entities); |
| 180 | + |
| 181 | + /** |
| 182 | + * Deletes the given entities supplied by a {@link Multi}. |
| 183 | + * |
| 184 | + * @param entityStream must not be {@literal null}. |
| 185 | + * @return {@link Uni} signaling when operation has completed. |
| 186 | + * @throws IllegalArgumentException in case the given {@link Multi entityStream} is {@literal null}. |
| 187 | + */ |
| 188 | + Uni<Void> deleteAll(Multi<? extends T> entityStream); |
| 189 | + |
| 190 | + /** |
| 191 | + * Deletes all entities managed by the repository. |
| 192 | + * |
| 193 | + * @return {@link Uni} signaling when operation has completed. |
| 194 | + */ |
| 195 | + Uni<Void> deleteAll(); |
| 196 | +} |
0 commit comments