Skip to content

Commit 712fc07

Browse files
committed
Polishing.
Update Kotlin, Reactive and List repository variant documentation. See #2651 Original pull request: #2673.
1 parent 4261fd7 commit 712fc07

File tree

4 files changed

+102
-40
lines changed

4 files changed

+102
-40
lines changed

src/main/java/org/springframework/data/repository/CrudRepository.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public interface CrudRepository<T, ID> extends Repository<T, ID> {
3636
* @param entity must not be {@literal null}.
3737
* @return the saved entity; will never be {@literal null}.
3838
* @throws IllegalArgumentException in case the given {@literal entity} is {@literal null}.
39-
* @throws OptimisticLockingFailureException when the entity has a version attribute with a different value from that
40-
* found in the persistence store. This also occurs when the entity which has a version attribute does no
41-
* longer exist in the database.
39+
* @throws OptimisticLockingFailureException when the entity uses optimistic locking and has a version attribute with
40+
* a different value from that found in the persistence store. Also thrown if the entity is assumed to be
41+
* present but does not exist in the database.
4242
*/
4343
<S extends T> S save(S entity);
4444

@@ -50,9 +50,9 @@ public interface CrudRepository<T, ID> extends Repository<T, ID> {
5050
* as the {@literal Iterable} passed as an argument.
5151
* @throws IllegalArgumentException in case the given {@link Iterable entities} or one of its entities is
5252
* {@literal null}.
53-
* @throws OptimisticLockingFailureException when at least one entity has a version attribute with a different value from that
54-
* found in the persistence store. This also occurs when the entity which has a version attribute does no
55-
* longer exist in the database.
53+
* @throws OptimisticLockingFailureException when at least one entity uses optimistic locking and has a version
54+
* attribute with a different value from that found in the persistence store. Also thrown if at least one
55+
* entity is assumed to be present but does not exist in the database.
5656
*/
5757
<S extends T> Iterable<S> saveAll(Iterable<S> entities);
5858

@@ -105,8 +105,7 @@ public interface CrudRepository<T, ID> extends Repository<T, ID> {
105105
/**
106106
* Deletes the entity with the given id.
107107
* <p>
108-
* When no entity with the given id is available, <b>no</b> exception will be thrown.
109-
* </p>
108+
* If the entity is not found in the persistence store it is silently ignored.
110109
*
111110
* @param id must not be {@literal null}.
112111
* @throws IllegalArgumentException in case the given {@literal id} is {@literal null}
@@ -118,18 +117,16 @@ public interface CrudRepository<T, ID> extends Repository<T, ID> {
118117
*
119118
* @param entity must not be {@literal null}.
120119
* @throws IllegalArgumentException in case the given entity is {@literal null}.
121-
* @throws OptimisticLockingFailureException when the entity has a version attribute with a different value from that
122-
* found in the persistence store. This also occurs when the entity which has a version attribute does no
123-
* longer exist in the database.
120+
* @throws OptimisticLockingFailureException when the entity uses optimistic locking and has a version attribute with
121+
* a different value from that found in the persistence store. Also thrown if the entity is assumed to be
122+
* present but does not exist in the database.
124123
*/
125124
void delete(T entity);
126125

127126
/**
128127
* Deletes all instances of the type {@code T} with the given IDs.
129128
* <p>
130-
* When some or all of the ids aren't found in the persistence store this is silently ignored and <b>no</b> exception
131-
* is thrown.
132-
* </p>
129+
* Entities that aren't found in the persistence store are silently ignored.
133130
*
134131
* @param ids must not be {@literal null}. Must not contain {@literal null} elements.
135132
* @throws IllegalArgumentException in case the given {@literal ids} or one of its elements is {@literal null}.
@@ -142,9 +139,9 @@ public interface CrudRepository<T, ID> extends Repository<T, ID> {
142139
*
143140
* @param entities must not be {@literal null}. Must not contain {@literal null} elements.
144141
* @throws IllegalArgumentException in case the given {@literal entities} or one of its entities is {@literal null}.
145-
* @throws OptimisticLockingFailureException when at least one of the entities has a version attribute with a
146-
* different value from that found in the persistence store. This also occurs when the entity which has a
147-
* version attribute does no longer exist in the database.
142+
* @throws OptimisticLockingFailureException when at least one entity uses optimistic locking and has a version
143+
* attribute with a different value from that found in the persistence store. Also thrown if at least one
144+
* entity is assumed to be present but does not exist in the database.
148145
*/
149146
void deleteAll(Iterable<? extends T> entities);
150147

src/main/java/org/springframework/data/repository/reactive/ReactiveCrudRepository.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import reactor.core.publisher.Mono;
2020

2121
import org.reactivestreams.Publisher;
22+
23+
import org.springframework.dao.OptimisticLockingFailureException;
2224
import org.springframework.data.repository.NoRepositoryBean;
2325
import org.springframework.data.repository.Repository;
2426

@@ -52,6 +54,9 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
5254
* @param entity must not be {@literal null}.
5355
* @return {@link Mono} emitting the saved entity.
5456
* @throws IllegalArgumentException in case the given {@literal entity} is {@literal null}.
57+
* @throws OptimisticLockingFailureException when the entity uses optimistic locking and has a version attribute with
58+
* a different value from that found in the persistence store. Also thrown if the entity is assumed to be
59+
* present but does not exist in the database.
5560
*/
5661
<S extends T> Mono<S> save(S entity);
5762

@@ -62,6 +67,9 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
6267
* @return {@link Flux} emitting the saved entities.
6368
* @throws IllegalArgumentException in case the given {@link Iterable entities} or one of its entities is
6469
* {@literal null}.
70+
* @throws OptimisticLockingFailureException when at least one entity uses optimistic locking and has a version
71+
* attribute with a different value from that found in the persistence store. Also thrown if at least one
72+
* entity is assumed to be present but does not exist in the database.
6573
*/
6674
<S extends T> Flux<S> saveAll(Iterable<S> entities);
6775

@@ -71,6 +79,9 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
7179
* @param entityStream must not be {@literal null}.
7280
* @return {@link Flux} emitting the saved entities.
7381
* @throws IllegalArgumentException in case the given {@link Publisher entityStream} is {@literal null}.
82+
* @throws OptimisticLockingFailureException when at least one entity uses optimistic locking and has a version
83+
* attribute with a different value from that found in the persistence store. Also thrown if at least one
84+
* entity is assumed to be present but does not exist in the database.
7485
*/
7586
<S extends T> Flux<S> saveAll(Publisher<S> entityStream);
7687

@@ -154,6 +165,8 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
154165

155166
/**
156167
* Deletes the entity with the given id.
168+
* <p>
169+
* If the entity is not found in the persistence store it is silently ignored.
157170
*
158171
* @param id must not be {@literal null}.
159172
* @return {@link Mono} signaling when operation has completed.
@@ -163,6 +176,8 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
163176

164177
/**
165178
* Deletes the entity with the given id supplied by a {@link Publisher}.
179+
* <p>
180+
* If the entity is not found in the persistence store it is silently ignored.
166181
*
167182
* @param id must not be {@literal null}.
168183
* @return {@link Mono} signaling when operation has completed.
@@ -176,11 +191,16 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
176191
* @param entity must not be {@literal null}.
177192
* @return {@link Mono} signaling when operation has completed.
178193
* @throws IllegalArgumentException in case the given entity is {@literal null}.
194+
* @throws OptimisticLockingFailureException when the entity uses optimistic locking and has a version attribute with
195+
* a different value from that found in the persistence store. Also thrown if the entity is assumed to be
196+
* present but does not exist in the database.
179197
*/
180198
Mono<Void> delete(T entity);
181199

182200
/**
183201
* Deletes all instances of the type {@code T} with the given IDs.
202+
* <p>
203+
* Entities that aren't found in the persistence store are silently ignored.
184204
*
185205
* @param ids must not be {@literal null}.
186206
* @return {@link Mono} signaling when operation has completed.
@@ -197,6 +217,9 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
197217
* @return {@link Mono} signaling when operation has completed.
198218
* @throws IllegalArgumentException in case the given {@link Iterable entities} or one of its entities is
199219
* {@literal null}.
220+
* @throws OptimisticLockingFailureException when at least one entity uses optimistic locking and has a version
221+
* attribute with a different value from that found in the persistence store. Also thrown if at least one
222+
* entity is assumed to be present but does not exist in the database.
200223
*/
201224
Mono<Void> deleteAll(Iterable<? extends T> entities);
202225

@@ -206,6 +229,9 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
206229
* @param entityStream must not be {@literal null}.
207230
* @return {@link Mono} signaling when operation has completed.
208231
* @throws IllegalArgumentException in case the given {@link Publisher entityStream} is {@literal null}.
232+
* @throws OptimisticLockingFailureException when at least one entity uses optimistic locking and has a version
233+
* attribute with a different value from that found in the persistence store. Also thrown if at least one
234+
* entity is assumed to be present but does not exist in the database.
209235
*/
210236
Mono<Void> deleteAll(Publisher<? extends T> entityStream);
211237

src/main/java/org/springframework/data/repository/reactive/RxJava3CrudRepository.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@
2020
import io.reactivex.rxjava3.core.Maybe;
2121
import io.reactivex.rxjava3.core.Single;
2222

23+
import org.springframework.dao.OptimisticLockingFailureException;
2324
import org.springframework.data.repository.NoRepositoryBean;
2425
import org.springframework.data.repository.Repository;
2526

2627
/**
2728
* Interface for generic CRUD operations on a repository for a specific type. This repository follows reactive paradigms
2829
* and uses RxJava 3 types.
2930
* <p>
30-
* Save and delete operations with entities that have a version attribute trigger an {@code onError} with a {@link org.springframework.dao.OptimisticLockingFailureException} when they encounter a different version value in the persistence store than in the entity passed as an argument.
31+
* Save and delete operations with entities that have a version attribute trigger an {@code onError} with a
32+
* {@link org.springframework.dao.OptimisticLockingFailureException} when they encounter a different version value in
33+
* the persistence store than in the entity passed as an argument.
3134
* </p>
3235
* <p>
33-
* Other delete operations that only receive ids or entities without version attribute do not trigger an error when no matching data is found in the persistence store.
36+
* Other delete operations that only receive ids or entities without version attribute do not trigger an error when no
37+
* matching data is found in the persistence store.
3438
* </p>
3539
*
3640
* @author Mark Paluch
@@ -50,6 +54,9 @@ public interface RxJava3CrudRepository<T, ID> extends Repository<T, ID> {
5054
* @param entity must not be {@literal null}.
5155
* @return {@link Single} emitting the saved entity.
5256
* @throws IllegalArgumentException in case the given {@literal entity} is {@literal null}.
57+
* @throws OptimisticLockingFailureException when the entity uses optimistic locking and has a version attribute with
58+
* a different value from that found in the persistence store. Also thrown if the entity is assumed to be
59+
* present but does not exist in the database.
5360
*/
5461
<S extends T> Single<S> save(S entity);
5562

@@ -60,6 +67,9 @@ public interface RxJava3CrudRepository<T, ID> extends Repository<T, ID> {
6067
* @return {@link Flowable} emitting the saved entities.
6168
* @throws IllegalArgumentException in case the given {@link Iterable entities} or one of its entities is
6269
* {@literal null}.
70+
* @throws OptimisticLockingFailureException when at least one entity uses optimistic locking and has a version
71+
* attribute with a different value from that found in the persistence store. Also thrown if at least one
72+
* entity is assumed to be present but does not exist in the database.
6373
*/
6474
<S extends T> Flowable<S> saveAll(Iterable<S> entities);
6575

@@ -69,6 +79,9 @@ public interface RxJava3CrudRepository<T, ID> extends Repository<T, ID> {
6979
* @param entityStream must not be {@literal null}.
7080
* @return {@link Flowable} emitting the saved entities.
7181
* @throws IllegalArgumentException in case the given {@link Flowable entityStream} is {@literal null}.
82+
* @throws OptimisticLockingFailureException when at least one entity uses optimistic locking and has a version
83+
* attribute with a different value from that found in the persistence store. Also thrown if at least one
84+
* entity is assumed to be present but does not exist in the database.
7285
*/
7386
<S extends T> Flowable<S> saveAll(Flowable<S> entityStream);
7487

@@ -151,6 +164,8 @@ public interface RxJava3CrudRepository<T, ID> extends Repository<T, ID> {
151164

152165
/**
153166
* Deletes the entity with the given id.
167+
* <p>
168+
* If the entity is not found in the persistence store it is silently ignored.
154169
*
155170
* @param id must not be {@literal null}.
156171
* @return {@link Completable} signaling when operation has completed.
@@ -164,11 +179,16 @@ public interface RxJava3CrudRepository<T, ID> extends Repository<T, ID> {
164179
* @param entity must not be {@literal null}.
165180
* @return {@link Completable} signaling when operation has completed.
166181
* @throws IllegalArgumentException in case the given entity is {@literal null}.
182+
* @throws OptimisticLockingFailureException when the entity uses optimistic locking and has a version attribute with
183+
* a different value from that found in the persistence store. Also thrown if the entity is assumed to be
184+
* present but does not exist in the database.
167185
*/
168186
Completable delete(T entity);
169187

170188
/**
171189
* Deletes all instances of the type {@code T} with the given IDs.
190+
* <p>
191+
* Entities that aren't found in the persistence store are silently ignored.
172192
*
173193
* @param ids must not be {@literal null}.
174194
* @return {@link Completable} signaling when operation has completed.
@@ -185,6 +205,9 @@ public interface RxJava3CrudRepository<T, ID> extends Repository<T, ID> {
185205
* @return {@link Completable} signaling when operation has completed.
186206
* @throws IllegalArgumentException in case the given {@link Iterable entities} or one of its entities is
187207
* {@literal null}.
208+
* @throws OptimisticLockingFailureException when at least one entity uses optimistic locking and has a version
209+
* attribute with a different value from that found in the persistence store. Also thrown if at least one
210+
* entity is assumed to be present but does not exist in the database.
188211
*/
189212
Completable deleteAll(Iterable<? extends T> entities);
190213

@@ -194,6 +217,9 @@ public interface RxJava3CrudRepository<T, ID> extends Repository<T, ID> {
194217
* @param entityStream must not be {@literal null}.
195218
* @return {@link Completable} signaling when operation has completed.
196219
* @throws IllegalArgumentException in case the given {@link Flowable entityStream} is {@literal null}.
220+
* @throws OptimisticLockingFailureException when at least one entity uses optimistic locking and has a version
221+
* attribute with a different value from that found in the persistence store. Also thrown if at least one
222+
* entity is assumed to be present but does not exist in the database.
197223
*/
198224
Completable deleteAll(Flowable<? extends T> entityStream);
199225

0 commit comments

Comments
 (0)