Skip to content

Commit 2831685

Browse files
committed
Adopt to Spring R2DBC changes.
Update counts now return Long instead of Integer. Closes #1198
1 parent ce83eac commit 2831685

13 files changed

+26
-26
lines changed

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityOperations.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public interface R2dbcEntityOperations extends FluentR2dbcOperations {
129129
* @return the number of affected rows.
130130
* @throws DataAccessException if there is any problem executing the query.
131131
*/
132-
Mono<Integer> update(Query query, Update update, Class<?> entityClass) throws DataAccessException;
132+
Mono<Long> update(Query query, Update update, Class<?> entityClass) throws DataAccessException;
133133

134134
/**
135135
* Remove entities (rows)/columns from the table by {@link Query}.
@@ -139,7 +139,7 @@ public interface R2dbcEntityOperations extends FluentR2dbcOperations {
139139
* @return the number of affected rows.
140140
* @throws DataAccessException if there is any problem issuing the execution.
141141
*/
142-
Mono<Integer> delete(Query query, Class<?> entityClass) throws DataAccessException;
142+
Mono<Long> delete(Query query, Class<?> entityClass) throws DataAccessException;
143143

144144
// -------------------------------------------------------------------------
145145
// Methods dealing with org.springframework.r2dbc.core.PreparedOperation

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ public <T> Mono<T> selectOne(Query query, Class<T> entityClass) throws DataAcces
428428
* @see org.springframework.data.r2dbc.core.R2dbcEntityOperations#update(org.springframework.data.r2dbc.query.Query, org.springframework.data.r2dbc.query.Update, java.lang.Class)
429429
*/
430430
@Override
431-
public Mono<Integer> update(Query query, Update update, Class<?> entityClass) throws DataAccessException {
431+
public Mono<Long> update(Query query, Update update, Class<?> entityClass) throws DataAccessException {
432432

433433
Assert.notNull(query, "Query must not be null");
434434
Assert.notNull(update, "Update must not be null");
@@ -437,7 +437,7 @@ public Mono<Integer> update(Query query, Update update, Class<?> entityClass) th
437437
return doUpdate(query, update, entityClass, getTableName(entityClass));
438438
}
439439

440-
Mono<Integer> doUpdate(Query query, Update update, Class<?> entityClass, SqlIdentifier tableName) {
440+
Mono<Long> doUpdate(Query query, Update update, Class<?> entityClass, SqlIdentifier tableName) {
441441

442442
StatementMapper statementMapper = dataAccessStrategy.getStatementMapper().forType(entityClass);
443443

@@ -458,15 +458,15 @@ Mono<Integer> doUpdate(Query query, Update update, Class<?> entityClass, SqlIden
458458
* @see org.springframework.data.r2dbc.core.R2dbcEntityOperations#delete(org.springframework.data.r2dbc.query.Query, java.lang.Class)
459459
*/
460460
@Override
461-
public Mono<Integer> delete(Query query, Class<?> entityClass) throws DataAccessException {
461+
public Mono<Long> delete(Query query, Class<?> entityClass) throws DataAccessException {
462462

463463
Assert.notNull(query, "Query must not be null");
464464
Assert.notNull(entityClass, "Entity class must not be null");
465465

466466
return doDelete(query, entityClass, getTableName(entityClass));
467467
}
468468

469-
Mono<Integer> doDelete(Query query, Class<?> entityClass, SqlIdentifier tableName) {
469+
Mono<Long> doDelete(Query query, Class<?> entityClass, SqlIdentifier tableName) {
470470

471471
StatementMapper statementMapper = dataAccessStrategy.getStatementMapper().forType(entityClass);
472472

@@ -479,7 +479,7 @@ Mono<Integer> doDelete(Query query, Class<?> entityClass, SqlIdentifier tableNam
479479
}
480480

481481
PreparedOperation<?> operation = statementMapper.getMappedObject(deleteSpec);
482-
return this.databaseClient.sql(operation).fetch().rowsUpdated().defaultIfEmpty(0);
482+
return this.databaseClient.sql(operation).fetch().rowsUpdated().defaultIfEmpty(0L);
483483
}
484484

485485
// -------------------------------------------------------------------------

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/ReactiveDeleteOperation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ interface TerminatingDelete {
113113
* @return the number of affected rows; never {@literal null}.
114114
* @see Mono
115115
*/
116-
Mono<Integer> all();
116+
Mono<Long> all();
117117
}
118118

119119
/**

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/ReactiveDeleteOperationSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public TerminatingDelete matching(Query query) {
9292
* (non-Javadoc)
9393
* @see org.springframework.data.r2dbc.core.ReactiveDeleteOperation.TerminatingDelete#all()
9494
*/
95-
public Mono<Integer> all() {
95+
public Mono<Long> all() {
9696
return template.doDelete(query, domainType, getTableName());
9797
}
9898

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/ReactiveUpdateOperation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ interface TerminatingUpdate {
117117
* @return the number of affected rows by the update; never {@literal null}.
118118
* @see Mono
119119
*/
120-
Mono<Integer> apply(Update update);
120+
Mono<Long> apply(Update update);
121121
}
122122

123123
/**

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/ReactiveUpdateOperationSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public TerminatingUpdate matching(Query query) {
9494
* @see org.springframework.data.r2dbc.core.ReactiveUpdateOperation.TerminatingUpdate#apply(org.springframework.data.r2dbc.query.Update)
9595
*/
9696
@Override
97-
public Mono<Integer> apply(Update update) {
97+
public Mono<Long> apply(Update update) {
9898

9999
Assert.notNull(update, "Update must not be null");
100100

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/repository/query/AbstractR2dbcQuery.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private R2dbcQueryExecution getExecutionToWrap(ReturnedType returnedType) {
137137
if (Number.class.isAssignableFrom(returnedType.getReturnedType())) {
138138

139139
return fs.rowsUpdated()
140-
.map(integer -> converter.getConversionService().convert(integer, returnedType.getReturnedType()));
140+
.map(count -> converter.getConversionService().convert(count, returnedType.getReturnedType()));
141141
}
142142

143143
if (ReflectionUtils.isVoid(returnedType.getReturnedType())) {

spring-data-r2dbc/src/main/kotlin/org/springframework/data/r2dbc/core/ReactiveDeleteOperationExtensions.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ inline fun <reified T : Any> ReactiveDeleteOperation.delete(): ReactiveDeleteOpe
3333
/**
3434
* Coroutines variant of [ReactiveDeleteOperation.TerminatingDelete.all].
3535
*/
36-
suspend fun ReactiveDeleteOperation.TerminatingDelete.allAndAwait(): Int =
36+
suspend fun ReactiveDeleteOperation.TerminatingDelete.allAndAwait(): Long =
3737
all().awaitSingle()

spring-data-r2dbc/src/main/kotlin/org/springframework/data/r2dbc/core/ReactiveUpdateOperationExtensions.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ inline fun <reified T : Any> ReactiveUpdateOperation.update(): ReactiveUpdateOpe
3434
/**
3535
* Coroutines variant of [ReactiveUpdateOperation.TerminatingUpdate.apply].
3636
*/
37-
suspend fun ReactiveUpdateOperation.TerminatingUpdate.applyAndAwait(update: Update): Int = apply(update).awaitSingle()
37+
suspend fun ReactiveUpdateOperation.TerminatingUpdate.applyAndAwait(update: Update): Long = apply(update).awaitSingle()

spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplateUnitTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ void shouldUpdateByQuery() {
214214
entityTemplate
215215
.update(Query.query(Criteria.where("name").is("Walter")), Update.update("name", "Heisenberg"), Person.class) //
216216
.as(StepVerifier::create) //
217-
.expectNext(1) //
217+
.expectNext(1L) //
218218
.verifyComplete();
219219

220220
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("UPDATE"));
@@ -235,7 +235,7 @@ void shouldDeleteByQuery() {
235235

236236
entityTemplate.delete(Query.query(Criteria.where("name").is("Walter")), Person.class) //
237237
.as(StepVerifier::create) //
238-
.expectNext(1) //
238+
.expectNext(1L) //
239239
.verifyComplete();
240240

241241
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("DELETE"));

spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/ReactiveDeleteOperationUnitTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void shouldDelete() {
6262
entityTemplate.delete(Person.class) //
6363
.all() //
6464
.as(StepVerifier::create) //
65-
.expectNext(1) //
65+
.expectNext(1L) //
6666
.verifyComplete();
6767

6868
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("DELETE"));
@@ -80,7 +80,7 @@ void shouldDeleteWithTable() {
8080
entityTemplate.delete(Person.class) //
8181
.from("table").all() //
8282
.as(StepVerifier::create) //
83-
.expectNext(1) //
83+
.expectNext(1L) //
8484
.verifyComplete();
8585

8686
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("DELETE"));
@@ -99,7 +99,7 @@ void shouldDeleteWithQuery() {
9999
.matching(query(where("name").is("Walter"))) //
100100
.all() //
101101
.as(StepVerifier::create) //
102-
.expectNext(1) //
102+
.expectNext(1L) //
103103
.verifyComplete();
104104

105105
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("DELETE"));
@@ -120,7 +120,7 @@ void shouldDeleteInTable() {
120120
.matching(query(where("name").is("Walter"))) //
121121
.all() //
122122
.as(StepVerifier::create) //
123-
.expectNext(1) //
123+
.expectNext(1L) //
124124
.verifyComplete();
125125

126126
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("DELETE"));

spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/ReactiveUpdateOperationUnitTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void shouldUpdate() {
6363
entityTemplate.update(Person.class) //
6464
.apply(Update.update("name", "Heisenberg")) //
6565
.as(StepVerifier::create) //
66-
.expectNext(1) //
66+
.expectNext(1L) //
6767
.verifyComplete();
6868

6969
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("UPDATE"));
@@ -82,7 +82,7 @@ void shouldUpdateWithTable() {
8282
entityTemplate.update(Person.class) //
8383
.inTable("table").apply(Update.update("name", "Heisenberg")) //
8484
.as(StepVerifier::create) //
85-
.expectNext(1) //
85+
.expectNext(1L) //
8686
.verifyComplete();
8787

8888
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("UPDATE"));
@@ -102,7 +102,7 @@ void shouldUpdateWithQuery() {
102102
.matching(query(where("name").is("Walter"))) //
103103
.apply(Update.update("name", "Heisenberg")) //
104104
.as(StepVerifier::create) //
105-
.expectNext(1) //
105+
.expectNext(1L) //
106106
.verifyComplete();
107107

108108
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("UPDATE"));
@@ -124,7 +124,7 @@ void shouldUpdateInTable() {
124124
.matching(query(where("name").is("Walter"))) //
125125
.apply(Update.update("name", "Heisenberg")) //
126126
.as(StepVerifier::create) //
127-
.expectNext(1) //
127+
.expectNext(1L) //
128128
.verifyComplete();
129129

130130
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("UPDATE"));

spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/documentation/R2dbcEntityTemplateSnippets.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void insert(R2dbcEntityTemplate template) {
8383
void fluentUpdate(R2dbcEntityTemplate template) {
8484

8585
// tag::update[]
86-
Mono<Integer> update = template.update(Person.class) // <1>
86+
Mono<Long> update = template.update(Person.class) // <1>
8787
.inTable("other_table") // <2>
8888
.matching(query(where("firstname").is("John"))) // <3>
8989
.apply(update("age", 42)); // <4>
@@ -93,7 +93,7 @@ void fluentUpdate(R2dbcEntityTemplate template) {
9393
void delete(R2dbcEntityTemplate template) {
9494

9595
// tag::delete[]
96-
Mono<Integer> delete = template.delete(Person.class) // <1>
96+
Mono<Long> delete = template.delete(Person.class) // <1>
9797
.from("other_table") // <2>
9898
.matching(query(where("firstname").is("John"))) // <3>
9999
.all(); // <4>

0 commit comments

Comments
 (0)