|
| 1 | +/* |
| 2 | + * Copyright 2016 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 | + * http://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 java.io.Serializable; |
| 19 | + |
| 20 | +import org.reactivestreams.Publisher; |
| 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 Reactive Streams types. |
| 27 | + * |
| 28 | + * @author Mark Paluch |
| 29 | + * @see Publisher |
| 30 | + */ |
| 31 | +@NoRepositoryBean |
| 32 | +public interface ReactiveStreamsCrudRepository<T, ID extends Serializable> extends Repository<T, ID> { |
| 33 | + |
| 34 | + /** |
| 35 | + * Saves a given entity. Use the returned instance for further operations as the save operation might have changed the |
| 36 | + * entity instance completely. |
| 37 | + * |
| 38 | + * @param entity |
| 39 | + * @return the saved entity |
| 40 | + */ |
| 41 | + <S extends T> Publisher<S> save(S entity); |
| 42 | + |
| 43 | + /** |
| 44 | + * Saves all given entities. |
| 45 | + * |
| 46 | + * @param entities must not be {@literal null}. |
| 47 | + * @return the saved entities |
| 48 | + * @throws IllegalArgumentException in case the given entity is {@literal null}. |
| 49 | + */ |
| 50 | + <S extends T> Publisher<S> save(Iterable<S> entities); |
| 51 | + |
| 52 | + /** |
| 53 | + * Saves all given entities. |
| 54 | + * |
| 55 | + * @param entityStream must not be {@literal null}. |
| 56 | + * @return the saved entities |
| 57 | + * @throws IllegalArgumentException in case the given {@code Publisher} is {@literal null}. |
| 58 | + */ |
| 59 | + <S extends T> Publisher<S> save(Publisher<S> entityStream); |
| 60 | + |
| 61 | + /** |
| 62 | + * Retrieves an entity by its id. |
| 63 | + * |
| 64 | + * @param id must not be {@literal null}. |
| 65 | + * @return the entity with the given id or {@literal null} if none found |
| 66 | + * @throws IllegalArgumentException if {@code id} is {@literal null} |
| 67 | + */ |
| 68 | + Publisher<T> findOne(ID id); |
| 69 | + |
| 70 | + /** |
| 71 | + * Retrieves an entity by its id supplied by a {@link Publisher}. |
| 72 | + * |
| 73 | + * @param id must not be {@literal null}. |
| 74 | + * @return the entity with the given id or {@literal null} if none found |
| 75 | + * @throws IllegalArgumentException if {@code id} is {@literal null} |
| 76 | + */ |
| 77 | + Publisher<T> findOne(Publisher<ID> id); |
| 78 | + |
| 79 | + /** |
| 80 | + * Returns whether an entity with the given id exists. |
| 81 | + * |
| 82 | + * @param id must not be {@literal null}. |
| 83 | + * @return true if an entity with the given id exists, {@literal false} otherwise |
| 84 | + * @throws IllegalArgumentException if {@code id} is {@literal null} |
| 85 | + */ |
| 86 | + Publisher<Boolean> exists(ID id); |
| 87 | + |
| 88 | + /** |
| 89 | + * Returns whether an entity with the given id exists supplied by a {@link Publisher}. |
| 90 | + * |
| 91 | + * @param id must not be {@literal null}. |
| 92 | + * @return true if an entity with the given id exists, {@literal false} otherwise |
| 93 | + * @throws IllegalArgumentException if {@code id} is {@literal null} |
| 94 | + */ |
| 95 | + Publisher<Boolean> exists(Publisher<ID> id); |
| 96 | + |
| 97 | + /** |
| 98 | + * Returns all instances of the type. |
| 99 | + * |
| 100 | + * @return all entities |
| 101 | + */ |
| 102 | + Publisher<T> findAll(); |
| 103 | + |
| 104 | + /** |
| 105 | + * Returns all instances of the type with the given IDs. |
| 106 | + * |
| 107 | + * @param ids |
| 108 | + * @return |
| 109 | + */ |
| 110 | + Publisher<T> findAll(Iterable<ID> ids); |
| 111 | + |
| 112 | + /** |
| 113 | + * Returns all instances of the type with the given IDs. |
| 114 | + * |
| 115 | + * @param idStream |
| 116 | + * @return |
| 117 | + */ |
| 118 | + Publisher<T> findAll(Publisher<ID> idStream); |
| 119 | + |
| 120 | + /** |
| 121 | + * Returns the number of entities available. |
| 122 | + * |
| 123 | + * @return the number of entities |
| 124 | + */ |
| 125 | + Publisher<Long> count(); |
| 126 | + |
| 127 | + /** |
| 128 | + * Deletes the entity with the given id. |
| 129 | + * |
| 130 | + * @param id must not be {@literal null}. |
| 131 | + * @throws IllegalArgumentException in case the given {@code id} is {@literal null} |
| 132 | + */ |
| 133 | + Publisher<Void> delete(ID id); |
| 134 | + |
| 135 | + /** |
| 136 | + * Deletes a given entity. |
| 137 | + * |
| 138 | + * @param entity |
| 139 | + * @throws IllegalArgumentException in case the given entity is {@literal null}. |
| 140 | + */ |
| 141 | + Publisher<Void> delete(T entity); |
| 142 | + |
| 143 | + /** |
| 144 | + * Deletes the given entities. |
| 145 | + * |
| 146 | + * @param entities |
| 147 | + * @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}. |
| 148 | + */ |
| 149 | + Publisher<Void> delete(Iterable<? extends T> entities); |
| 150 | + |
| 151 | + /** |
| 152 | + * Deletes the given entities. |
| 153 | + * |
| 154 | + * @param entityStream |
| 155 | + * @throws IllegalArgumentException in case the given {@link Publisher} is {@literal null}. |
| 156 | + */ |
| 157 | + Publisher<Void> delete(Publisher<? extends T> entityStream); |
| 158 | + |
| 159 | + /** |
| 160 | + * Deletes all entities managed by the repository. |
| 161 | + */ |
| 162 | + Publisher<Void> deleteAll(); |
| 163 | +} |
0 commit comments