Skip to content

Commit 928ac09

Browse files
schaudermp911de
authored andcommitted
#151 - SimpleR2dbcRepository is now transactional.
Original pull request: #152.
1 parent ec8f540 commit 928ac09

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/main/java/org/springframework/data/r2dbc/repository/support/SimpleR2dbcRepository.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.data.r2dbc.repository.support;
1717

18+
import org.springframework.transaction.annotation.Transactional;
1819
import reactor.core.publisher.Flux;
1920
import reactor.core.publisher.Mono;
2021

@@ -42,7 +43,9 @@
4243
* Simple {@link ReactiveCrudRepository} implementation using R2DBC through {@link DatabaseClient}.
4344
*
4445
* @author Mark Paluch
46+
* @author Jens Schauder
4547
*/
48+
@Transactional(readOnly = true)
4649
public class SimpleR2dbcRepository<T, ID> implements ReactiveCrudRepository<T, ID> {
4750

4851
private final RelationalEntityInformation<T, ID> entity;
@@ -62,6 +65,7 @@ public SimpleR2dbcRepository(RelationalEntityInformation<T, ID> entity, Database
6265
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#save(S)
6366
*/
6467
@Override
68+
@Transactional
6569
public <S extends T> Mono<S> save(S objectToSave) {
6670

6771
Assert.notNull(objectToSave, "Object to save must not be null!");
@@ -87,6 +91,7 @@ public <S extends T> Mono<S> save(S objectToSave) {
8791
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#saveAll(java.lang.Iterable)
8892
*/
8993
@Override
94+
@Transactional
9095
public <S extends T> Flux<S> saveAll(Iterable<S> objectsToSave) {
9196

9297
Assert.notNull(objectsToSave, "Objects to save must not be null!");
@@ -98,6 +103,7 @@ public <S extends T> Flux<S> saveAll(Iterable<S> objectsToSave) {
98103
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#saveAll(org.reactivestreams.Publisher)
99104
*/
100105
@Override
106+
@Transactional
101107
public <S extends T> Flux<S> saveAll(Publisher<S> objectsToSave) {
102108

103109
Assert.notNull(objectsToSave, "Object publisher must not be null!");
@@ -237,6 +243,7 @@ public Mono<Long> count() {
237243
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteById(java.lang.Object)
238244
*/
239245
@Override
246+
@Transactional
240247
public Mono<Void> deleteById(ID id) {
241248

242249
Assert.notNull(id, "Id must not be null!");
@@ -254,6 +261,7 @@ public Mono<Void> deleteById(ID id) {
254261
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteById(org.reactivestreams.Publisher)
255262
*/
256263
@Override
264+
@Transactional
257265
public Mono<Void> deleteById(Publisher<ID> idPublisher) {
258266

259267
Assert.notNull(idPublisher, "The Id Publisher must not be null!");
@@ -278,6 +286,7 @@ public Mono<Void> deleteById(Publisher<ID> idPublisher) {
278286
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#delete(java.lang.Object)
279287
*/
280288
@Override
289+
@Transactional
281290
public Mono<Void> delete(T objectToDelete) {
282291

283292
Assert.notNull(objectToDelete, "Object to delete must not be null!");
@@ -289,6 +298,7 @@ public Mono<Void> delete(T objectToDelete) {
289298
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAll(java.lang.Iterable)
290299
*/
291300
@Override
301+
@Transactional
292302
public Mono<Void> deleteAll(Iterable<? extends T> iterable) {
293303

294304
Assert.notNull(iterable, "The iterable of Id's must not be null!");
@@ -300,6 +310,7 @@ public Mono<Void> deleteAll(Iterable<? extends T> iterable) {
300310
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAll(org.reactivestreams.Publisher)
301311
*/
302312
@Override
313+
@Transactional
303314
public Mono<Void> deleteAll(Publisher<? extends T> objectPublisher) {
304315

305316
Assert.notNull(objectPublisher, "The Object Publisher must not be null!");
@@ -314,6 +325,7 @@ public Mono<Void> deleteAll(Publisher<? extends T> objectPublisher) {
314325
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#deleteAll()
315326
*/
316327
@Override
328+
@Transactional
317329
public Mono<Void> deleteAll() {
318330
return this.databaseClient.delete().from(this.entity.getTableName()).then();
319331
}

0 commit comments

Comments
 (0)