15
15
*/
16
16
package org .springframework .data .r2dbc .repository .support ;
17
17
18
+ import org .springframework .transaction .annotation .Transactional ;
18
19
import reactor .core .publisher .Flux ;
19
20
import reactor .core .publisher .Mono ;
20
21
42
43
* Simple {@link ReactiveCrudRepository} implementation using R2DBC through {@link DatabaseClient}.
43
44
*
44
45
* @author Mark Paluch
46
+ * @author Jens Schauder
45
47
*/
48
+ @ Transactional (readOnly = true )
46
49
public class SimpleR2dbcRepository <T , ID > implements ReactiveCrudRepository <T , ID > {
47
50
48
51
private final RelationalEntityInformation <T , ID > entity ;
@@ -62,6 +65,7 @@ public SimpleR2dbcRepository(RelationalEntityInformation<T, ID> entity, Database
62
65
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#save(S)
63
66
*/
64
67
@ Override
68
+ @ Transactional
65
69
public <S extends T > Mono <S > save (S objectToSave ) {
66
70
67
71
Assert .notNull (objectToSave , "Object to save must not be null!" );
@@ -87,6 +91,7 @@ public <S extends T> Mono<S> save(S objectToSave) {
87
91
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#saveAll(java.lang.Iterable)
88
92
*/
89
93
@ Override
94
+ @ Transactional
90
95
public <S extends T > Flux <S > saveAll (Iterable <S > objectsToSave ) {
91
96
92
97
Assert .notNull (objectsToSave , "Objects to save must not be null!" );
@@ -98,6 +103,7 @@ public <S extends T> Flux<S> saveAll(Iterable<S> objectsToSave) {
98
103
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#saveAll(org.reactivestreams.Publisher)
99
104
*/
100
105
@ Override
106
+ @ Transactional
101
107
public <S extends T > Flux <S > saveAll (Publisher <S > objectsToSave ) {
102
108
103
109
Assert .notNull (objectsToSave , "Object publisher must not be null!" );
@@ -237,6 +243,7 @@ public Mono<Long> count() {
237
243
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteById(java.lang.Object)
238
244
*/
239
245
@ Override
246
+ @ Transactional
240
247
public Mono <Void > deleteById (ID id ) {
241
248
242
249
Assert .notNull (id , "Id must not be null!" );
@@ -254,6 +261,7 @@ public Mono<Void> deleteById(ID id) {
254
261
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteById(org.reactivestreams.Publisher)
255
262
*/
256
263
@ Override
264
+ @ Transactional
257
265
public Mono <Void > deleteById (Publisher <ID > idPublisher ) {
258
266
259
267
Assert .notNull (idPublisher , "The Id Publisher must not be null!" );
@@ -278,6 +286,7 @@ public Mono<Void> deleteById(Publisher<ID> idPublisher) {
278
286
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#delete(java.lang.Object)
279
287
*/
280
288
@ Override
289
+ @ Transactional
281
290
public Mono <Void > delete (T objectToDelete ) {
282
291
283
292
Assert .notNull (objectToDelete , "Object to delete must not be null!" );
@@ -289,6 +298,7 @@ public Mono<Void> delete(T objectToDelete) {
289
298
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAll(java.lang.Iterable)
290
299
*/
291
300
@ Override
301
+ @ Transactional
292
302
public Mono <Void > deleteAll (Iterable <? extends T > iterable ) {
293
303
294
304
Assert .notNull (iterable , "The iterable of Id's must not be null!" );
@@ -300,6 +310,7 @@ public Mono<Void> deleteAll(Iterable<? extends T> iterable) {
300
310
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAll(org.reactivestreams.Publisher)
301
311
*/
302
312
@ Override
313
+ @ Transactional
303
314
public Mono <Void > deleteAll (Publisher <? extends T > objectPublisher ) {
304
315
305
316
Assert .notNull (objectPublisher , "The Object Publisher must not be null!" );
@@ -314,6 +325,7 @@ public Mono<Void> deleteAll(Publisher<? extends T> objectPublisher) {
314
325
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAll()
315
326
*/
316
327
@ Override
328
+ @ Transactional
317
329
public Mono <Void > deleteAll () {
318
330
return this .databaseClient .delete ().from (this .entity .getTableName ()).then ();
319
331
}
0 commit comments