Skip to content

Commit b7cfe6e

Browse files
committed
DATACMNS-1601 - Polishing.
Document throws on save(…). Align documentation for reactive repositories. Original pull request: #412.
1 parent f78d49e commit b7cfe6e

File tree

3 files changed

+82
-52
lines changed

3 files changed

+82
-52
lines changed

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

+11-12
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,17 @@ public interface CrudRepository<T, ID> extends Repository<T, ID> {
3232
*
3333
* @param entity must not be {@literal null}.
3434
* @return the saved entity; will never be {@literal null}.
35+
* @throws IllegalArgumentException in case the given {@code entity} is {@literal null}.
3536
*/
3637
<S extends T> S save(S entity);
3738

3839
/**
3940
* Saves all given entities.
4041
*
41-
* @param entities must not be {@literal null} nor must it contain {@literal null}
42+
* @param entities must not be {@literal null} nor must it contain {@literal null}.
4243
* @return the saved entities; will never be {@literal null}. The returned {@literal Iterable} will have the same size
4344
* as the {@literal Iterable} passed as an argument.
44-
* @throws IllegalArgumentException in case the given {@literal Iterable} or one of its contained entities is
45+
* @throws IllegalArgumentException in case the given {@link Iterable entities} or one of its entities is
4546
* {@literal null}.
4647
*/
4748
<S extends T> Iterable<S> saveAll(Iterable<S> entities);
@@ -50,7 +51,7 @@ public interface CrudRepository<T, ID> extends Repository<T, ID> {
5051
* Retrieves an entity by its id.
5152
*
5253
* @param id must not be {@literal null}.
53-
* @return the entity with the given id or {@literal Optional#empty()} if none found
54+
* @return the entity with the given id or {@literal Optional#empty()} if none found.
5455
* @throws IllegalArgumentException if {@code id} is {@literal null}.
5556
*/
5657
Optional<T> findById(ID id);
@@ -72,23 +73,22 @@ public interface CrudRepository<T, ID> extends Repository<T, ID> {
7273
Iterable<T> findAll();
7374

7475
/**
75-
* Returns all instances of the type with the given IDs.
76+
* Returns all instances of the type {@code T} with the given IDs.
7677
* <p>
77-
* If some or all ids are not found no entities are returned for these IDs.
78+
* If some or all ids are not found, no entities are returned for these IDs.
7879
* <p>
7980
* Note that the order of elements in the result is not guaranteed.
8081
*
8182
* @param ids must not be {@literal null} nor contain any {@literal null} values.
82-
* @return guaranteed to be not {@literal null}. The size will be equal or smaller than that of the argument.
83-
* @throws IllegalArgumentException in case the given {@literal Iterable} or one of its contained entities is
84-
* {@literal null}.
83+
* @return guaranteed to be not {@literal null}. The size can be equal or less than the number of given {@code ids}.
84+
* @throws IllegalArgumentException in case the given {@link Iterable ids} or one of its items is {@literal null}.
8585
*/
8686
Iterable<T> findAllById(Iterable<ID> ids);
8787

8888
/**
8989
* Returns the number of entities available.
9090
*
91-
* @return the number of entities
91+
* @return the number of entities.
9292
*/
9393
long count();
9494

@@ -111,9 +111,8 @@ public interface CrudRepository<T, ID> extends Repository<T, ID> {
111111
/**
112112
* Deletes the given entities.
113113
*
114-
* @param entities must not be {@literal null}. Must not contain {@literal null} elements
115-
* @throws IllegalArgumentException in case the given {@literal Iterable} or one of its contained entities is
116-
* {@literal null}.
114+
* @param entities must not be {@literal null}. Must not contain {@literal null} elements.
115+
* @throws IllegalArgumentException in case the given {@literal entities} or one of its entities is {@literal null}.
117116
*/
118117
void deleteAll(Iterable<? extends T> entities);
119118

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

+26-15
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
5050
*
5151
* @param entities must not be {@literal null}.
5252
* @return {@link Flux} emitting the saved entities.
53-
* @throws IllegalArgumentException in case the given {@link Iterable} {@code entities} is {@literal null}.
53+
* @throws IllegalArgumentException in case the given {@link Iterable entities} or one of its entities is
54+
* {@literal null}.
5455
*/
5556
<S extends T> Flux<S> saveAll(Iterable<S> entities);
5657

@@ -59,7 +60,7 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
5960
*
6061
* @param entityStream must not be {@literal null}.
6162
* @return {@link Flux} emitting the saved entities.
62-
* @throws IllegalArgumentException in case the given {@code Publisher} {@code entityStream} is {@literal null}.
63+
* @throws IllegalArgumentException in case the given {@link Publisher entityStream} is {@literal null}.
6364
*/
6465
<S extends T> Flux<S> saveAll(Publisher<S> entityStream);
6566

@@ -77,12 +78,12 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
7778
*
7879
* @param id must not be {@literal null}. Uses the first emitted element to perform the find-query.
7980
* @return {@link Mono} emitting the entity with the given id or {@link Mono#empty()} if none found.
80-
* @throws IllegalArgumentException in case the given {@link Publisher} {@code id} is {@literal null}.
81+
* @throws IllegalArgumentException in case the given {@link Publisher id} is {@literal null}.
8182
*/
8283
Mono<T> findById(Publisher<ID> id);
8384

8485
/**
85-
* Returns whether an entity with the id exists.
86+
* Returns whether an entity with the given {@code id} exists.
8687
*
8788
* @param id must not be {@literal null}.
8889
* @return {@link Mono} emitting {@literal true} if an entity with the given id exists, {@literal false} otherwise.
@@ -95,8 +96,8 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
9596
* element to perform the exists-query.
9697
*
9798
* @param id must not be {@literal null}.
98-
* @return {@link Mono} emitting {@literal true} if an entity with the given id exists, {@literal false} otherwise
99-
* @throws IllegalArgumentException in case the given {@link Publisher} {@code id} is {@literal null}.
99+
* @return {@link Mono} emitting {@literal true} if an entity with the given id exists, {@literal false} otherwise.
100+
* @throws IllegalArgumentException in case the given {@link Publisher id} is {@literal null}.
100101
*/
101102
Mono<Boolean> existsById(Publisher<ID> id);
102103

@@ -108,20 +109,29 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
108109
Flux<T> findAll();
109110

110111
/**
111-
* Returns all instances with the given IDs.
112+
* Returns all instances of the type {@code T} with the given IDs.
113+
* <p>
114+
* If some or all ids are not found, no entities are returned for these IDs.
115+
* <p>
116+
* Note that the order of elements in the result is not guaranteed.
112117
*
113-
* @param ids must not be {@literal null}.
114-
* @return {@link Flux} emitting the found entities.
115-
* @throws IllegalArgumentException in case the given {@link Iterable} {@code ids} is {@literal null}.
118+
* @param ids must not be {@literal null} nor contain any {@literal null} values.
119+
* @return {@link Flux} emitting the found entities. The size can be equal or less than the number of given
120+
* {@code ids}.
121+
* @throws IllegalArgumentException in case the given {@link Iterable ids} or one of its items is {@literal null}.
116122
*/
117123
Flux<T> findAllById(Iterable<ID> ids);
118124

119125
/**
120-
* Returns all instances of the type with the given IDs supplied by a {@link Publisher}.
126+
* Returns all instances of the type {@code T} with the given IDs supplied by a {@link Publisher}.
127+
* <p>
128+
* If some or all ids are not found, no entities are returned for these IDs.
129+
* <p>
130+
* Note that the order of elements in the result is not guaranteed.
121131
*
122132
* @param idStream must not be {@literal null}.
123133
* @return {@link Flux} emitting the found entities.
124-
* @throws IllegalArgumentException in case the given {@link Publisher} {@code idStream} is {@literal null}.
134+
* @throws IllegalArgumentException in case the given {@link Publisher idStream} is {@literal null}.
125135
*/
126136
Flux<T> findAllById(Publisher<ID> idStream);
127137

@@ -146,7 +156,7 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
146156
*
147157
* @param id must not be {@literal null}.
148158
* @return {@link Mono} signaling when operation has completed.
149-
* @throws IllegalArgumentException in case the given {@link Publisher} {@code id} is {@literal null}.
159+
* @throws IllegalArgumentException in case the given {@link Publisher id} is {@literal null}.
150160
*/
151161
Mono<Void> deleteById(Publisher<ID> id);
152162

@@ -164,7 +174,8 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
164174
*
165175
* @param entities must not be {@literal null}.
166176
* @return {@link Mono} signaling when operation has completed.
167-
* @throws IllegalArgumentException in case the given {@link Iterable} {@code entities} is {@literal null}.
177+
* @throws IllegalArgumentException in case the given {@link Iterable entities} or one of its entities is
178+
* {@literal null}.
168179
*/
169180
Mono<Void> deleteAll(Iterable<? extends T> entities);
170181

@@ -173,7 +184,7 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
173184
*
174185
* @param entityStream must not be {@literal null}.
175186
* @return {@link Mono} signaling when operation has completed.
176-
* @throws IllegalArgumentException in case the given {@link Publisher} {@code entityStream} is {@literal null}.
187+
* @throws IllegalArgumentException in case the given {@link Publisher entityStream} is {@literal null}.
177188
*/
178189
Mono<Void> deleteAll(Publisher<? extends T> entityStream);
179190

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

+45-25
Original file line numberDiff line numberDiff line change
@@ -42,98 +42,112 @@ public interface RxJava2CrudRepository<T, ID> extends Repository<T, ID> {
4242
* entity instance completely.
4343
*
4444
* @param entity must not be {@literal null}.
45-
* @return the saved entity.
45+
* @return {@link Single} emitting the saved entity.
46+
* @throws IllegalArgumentException in case the given {@code entity} is {@literal null}.
4647
*/
4748
<S extends T> Single<S> save(S entity);
4849

4950
/**
5051
* Saves all given entities.
5152
*
5253
* @param entities must not be {@literal null}.
53-
* @return the saved entities.
54-
* @throws IllegalArgumentException in case the given entity is {@literal null}.
54+
* @return {@link Flowable} emitting the saved entities.
55+
* @throws IllegalArgumentException in case the given {@link Iterable entities} or one of its entities is
56+
* {@literal null}.
5557
*/
5658
<S extends T> Flowable<S> saveAll(Iterable<S> entities);
5759

5860
/**
5961
* Saves all given entities.
6062
*
6163
* @param entityStream must not be {@literal null}.
62-
* @return the saved entities.
63-
* @throws IllegalArgumentException in case the given {@code Publisher} is {@literal null}.
64+
* @return {@link Flowable} emitting the saved entities.
65+
* @throws IllegalArgumentException in case the given {@link Flowable entityStream} is {@literal null}.
6466
*/
6567
<S extends T> Flowable<S> saveAll(Flowable<S> entityStream);
6668

6769
/**
6870
* Retrieves an entity by its id.
6971
*
7072
* @param id must not be {@literal null}.
71-
* @return the entity with the given id or {@link Maybe#empty()} if none found.
72-
* @throws IllegalArgumentException if {@code id} is {@literal null}.
73+
* @return {@link Maybe} emitting the entity with the given id or {@link Maybe#empty()} if none found.
74+
* @throws IllegalArgumentException in case the given {@code id} is {@literal null}.
7375
*/
7476
Maybe<T> findById(ID id);
7577

7678
/**
7779
* Retrieves an entity by its id supplied by a {@link Single}.
7880
*
79-
* @param id must not be {@literal null}.
80-
* @return the entity with the given id or {@link Maybe#empty()} if none found.
81-
* @throws IllegalArgumentException if {@code id} is {@literal null}.
81+
* @param id must not be {@literal null}. Uses the first emitted element to perform the find-query.
82+
* @return {@link Maybe} emitting the entity with the given id or {@link Maybe#empty()} if none found.
83+
* @throws IllegalArgumentException in case the given {@link Single id} is {@literal null}.
8284
*/
8385
Maybe<T> findById(Single<ID> id);
8486

8587
/**
86-
* Returns whether an entity with the given id exists.
88+
* Returns whether an entity with the given {@code id} exists.
8789
*
8890
* @param id must not be {@literal null}.
89-
* @return {@literal true} if an entity with the given id exists, {@literal false} otherwise.
90-
* @throws IllegalArgumentException if {@code id} is {@literal null}.
91+
* @return {@link Single} emitting {@literal true} if an entity with the given id exists, {@literal false} otherwise.
92+
* @throws IllegalArgumentException in case the given {@code id} is {@literal null}.
9193
*/
9294
Single<Boolean> existsById(ID id);
9395

9496
/**
9597
* Returns whether an entity with the given id, supplied by a {@link Single}, exists.
9698
*
9799
* @param id must not be {@literal null}.
98-
* @return {@literal true} if an entity with the given id exists, {@literal false} otherwise.
99-
* @throws IllegalArgumentException if {@code id} is {@literal null}
100+
* @return {@link Single} emitting {@literal true} if an entity with the given id exists, {@literal false} otherwise.
101+
* @throws IllegalArgumentException in case the given {@link Single id} is {@literal null}.
100102
*/
101103
Single<Boolean> existsById(Single<ID> id);
102104

103105
/**
104106
* Returns all instances of the type.
105107
*
106-
* @return all entities.
108+
* @return {@link Flowable} emitting all entities.
107109
*/
108110
Flowable<T> findAll();
109111

110112
/**
111-
* Returns all instances of the type with the given IDs.
113+
* Returns all instances of the type {@code T} with the given IDs.
114+
* <p>
115+
* If some or all ids are not found, no entities are returned for these IDs.
116+
* <p>
117+
* Note that the order of elements in the result is not guaranteed.
112118
*
113-
* @param ids must not be {@literal null}.
114-
* @return the found entities.
119+
* @param ids must not be {@literal null} nor contain any {@literal null} values.
120+
* @return {@link Flowable} emitting the found entities. The size can be equal or less than the number of given
121+
* {@code ids}.
122+
* @throws IllegalArgumentException in case the given {@link Iterable ids} or one of its items is {@literal null}.
115123
*/
116124
Flowable<T> findAllById(Iterable<ID> ids);
117125

118126
/**
119-
* Returns all instances of the type with the given IDs.
127+
* Returns all instances of the type {@code T} with the given IDs supplied by a {@link Flowable}.
128+
* <p>
129+
* If some or all ids are not found, no entities are returned for these IDs.
130+
* <p>
131+
* Note that the order of elements in the result is not guaranteed.
120132
*
121133
* @param idStream must not be {@literal null}.
122-
* @return the found entities.
134+
* @return {@link Flowable} emitting the found entities.
135+
* @throws IllegalArgumentException in case the given {@link Flowable idStream} is {@literal null}.
123136
*/
124137
Flowable<T> findAllById(Flowable<ID> idStream);
125138

126139
/**
127140
* Returns the number of entities available.
128141
*
129-
* @return the number of entities.
142+
* @return {@link Single} emitting the number of entities.
130143
*/
131144
Single<Long> count();
132145

133146
/**
134147
* Deletes the entity with the given id.
135148
*
136149
* @param id must not be {@literal null}.
150+
* @return {@link Completable} signaling when operation has completed.
137151
* @throws IllegalArgumentException in case the given {@code id} is {@literal null}.
138152
*/
139153
Completable deleteById(ID id);
@@ -142,6 +156,7 @@ public interface RxJava2CrudRepository<T, ID> extends Repository<T, ID> {
142156
* Deletes a given entity.
143157
*
144158
* @param entity must not be {@literal null}.
159+
* @return {@link Completable} signaling when operation has completed.
145160
* @throws IllegalArgumentException in case the given entity is {@literal null}.
146161
*/
147162
Completable delete(T entity);
@@ -150,20 +165,25 @@ public interface RxJava2CrudRepository<T, ID> extends Repository<T, ID> {
150165
* Deletes the given entities.
151166
*
152167
* @param entities must not be {@literal null}.
153-
* @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}.
168+
* @return {@link Completable} signaling when operation has completed.
169+
* @throws IllegalArgumentException in case the given {@link Iterable entities} or one of its entities is
170+
* {@literal null}.
154171
*/
155172
Completable deleteAll(Iterable<? extends T> entities);
156173

157174
/**
158-
* Deletes the given entities.
175+
* Deletes the given entities supplied by a {@link Flowable}.
159176
*
160177
* @param entityStream must not be {@literal null}.
161-
* @throws IllegalArgumentException in case the given {@link Flowable} is {@literal null}.
178+
* @return {@link Completable} signaling when operation has completed.
179+
* @throws IllegalArgumentException in case the given {@link Flowable entityStream} is {@literal null}.
162180
*/
163181
Completable deleteAll(Flowable<? extends T> entityStream);
164182

165183
/**
166184
* Deletes all entities managed by the repository.
185+
*
186+
* @return {@link Completable} signaling when operation has completed.
167187
*/
168188
Completable deleteAll();
169189
}

0 commit comments

Comments
 (0)