Browse Source

Adopt to Spring R2DBC changes.

Update counts now return Long instead of Integer.

Closes #1198
pull/1209/head
Mark Paluch 4 years ago
parent
commit
2831685c9d
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 4
      spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityOperations.java
  2. 10
      spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java
  3. 2
      spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/ReactiveDeleteOperation.java
  4. 2
      spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/ReactiveDeleteOperationSupport.java
  5. 2
      spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/ReactiveUpdateOperation.java
  6. 2
      spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/core/ReactiveUpdateOperationSupport.java
  7. 2
      spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/repository/query/AbstractR2dbcQuery.java
  8. 2
      spring-data-r2dbc/src/main/kotlin/org/springframework/data/r2dbc/core/ReactiveDeleteOperationExtensions.kt
  9. 2
      spring-data-r2dbc/src/main/kotlin/org/springframework/data/r2dbc/core/ReactiveUpdateOperationExtensions.kt
  10. 4
      spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplateUnitTests.java
  11. 8
      spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/ReactiveDeleteOperationUnitTests.java
  12. 8
      spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/ReactiveUpdateOperationUnitTests.java
  13. 4
      spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/documentation/R2dbcEntityTemplateSnippets.java

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

@ -129,7 +129,7 @@ public interface R2dbcEntityOperations extends FluentR2dbcOperations { @@ -129,7 +129,7 @@ public interface R2dbcEntityOperations extends FluentR2dbcOperations {
* @return the number of affected rows.
* @throws DataAccessException if there is any problem executing the query.
*/
Mono<Integer> update(Query query, Update update, Class<?> entityClass) throws DataAccessException;
Mono<Long> update(Query query, Update update, Class<?> entityClass) throws DataAccessException;
/**
* Remove entities (rows)/columns from the table by {@link Query}.
@ -139,7 +139,7 @@ public interface R2dbcEntityOperations extends FluentR2dbcOperations { @@ -139,7 +139,7 @@ public interface R2dbcEntityOperations extends FluentR2dbcOperations {
* @return the number of affected rows.
* @throws DataAccessException if there is any problem issuing the execution.
*/
Mono<Integer> delete(Query query, Class<?> entityClass) throws DataAccessException;
Mono<Long> delete(Query query, Class<?> entityClass) throws DataAccessException;
// -------------------------------------------------------------------------
// Methods dealing with org.springframework.r2dbc.core.PreparedOperation

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

@ -428,7 +428,7 @@ public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAw @@ -428,7 +428,7 @@ public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAw
* @see org.springframework.data.r2dbc.core.R2dbcEntityOperations#update(org.springframework.data.r2dbc.query.Query, org.springframework.data.r2dbc.query.Update, java.lang.Class)
*/
@Override
public Mono<Integer> update(Query query, Update update, Class<?> entityClass) throws DataAccessException {
public Mono<Long> update(Query query, Update update, Class<?> entityClass) throws DataAccessException {
Assert.notNull(query, "Query must not be null");
Assert.notNull(update, "Update must not be null");
@ -437,7 +437,7 @@ public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAw @@ -437,7 +437,7 @@ public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAw
return doUpdate(query, update, entityClass, getTableName(entityClass));
}
Mono<Integer> doUpdate(Query query, Update update, Class<?> entityClass, SqlIdentifier tableName) {
Mono<Long> doUpdate(Query query, Update update, Class<?> entityClass, SqlIdentifier tableName) {
StatementMapper statementMapper = dataAccessStrategy.getStatementMapper().forType(entityClass);
@ -458,7 +458,7 @@ public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAw @@ -458,7 +458,7 @@ public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAw
* @see org.springframework.data.r2dbc.core.R2dbcEntityOperations#delete(org.springframework.data.r2dbc.query.Query, java.lang.Class)
*/
@Override
public Mono<Integer> delete(Query query, Class<?> entityClass) throws DataAccessException {
public Mono<Long> delete(Query query, Class<?> entityClass) throws DataAccessException {
Assert.notNull(query, "Query must not be null");
Assert.notNull(entityClass, "Entity class must not be null");
@ -466,7 +466,7 @@ public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAw @@ -466,7 +466,7 @@ public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAw
return doDelete(query, entityClass, getTableName(entityClass));
}
Mono<Integer> doDelete(Query query, Class<?> entityClass, SqlIdentifier tableName) {
Mono<Long> doDelete(Query query, Class<?> entityClass, SqlIdentifier tableName) {
StatementMapper statementMapper = dataAccessStrategy.getStatementMapper().forType(entityClass);
@ -479,7 +479,7 @@ public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAw @@ -479,7 +479,7 @@ public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAw
}
PreparedOperation<?> operation = statementMapper.getMappedObject(deleteSpec);
return this.databaseClient.sql(operation).fetch().rowsUpdated().defaultIfEmpty(0);
return this.databaseClient.sql(operation).fetch().rowsUpdated().defaultIfEmpty(0L);
}
// -------------------------------------------------------------------------

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

@ -113,7 +113,7 @@ public interface ReactiveDeleteOperation { @@ -113,7 +113,7 @@ public interface ReactiveDeleteOperation {
* @return the number of affected rows; never {@literal null}.
* @see Mono
*/
Mono<Integer> all();
Mono<Long> all();
}
/**

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

@ -92,7 +92,7 @@ class ReactiveDeleteOperationSupport implements ReactiveDeleteOperation { @@ -92,7 +92,7 @@ class ReactiveDeleteOperationSupport implements ReactiveDeleteOperation {
* (non-Javadoc)
* @see org.springframework.data.r2dbc.core.ReactiveDeleteOperation.TerminatingDelete#all()
*/
public Mono<Integer> all() {
public Mono<Long> all() {
return template.doDelete(query, domainType, getTableName());
}

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

@ -117,7 +117,7 @@ public interface ReactiveUpdateOperation { @@ -117,7 +117,7 @@ public interface ReactiveUpdateOperation {
* @return the number of affected rows by the update; never {@literal null}.
* @see Mono
*/
Mono<Integer> apply(Update update);
Mono<Long> apply(Update update);
}
/**

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

@ -94,7 +94,7 @@ class ReactiveUpdateOperationSupport implements ReactiveUpdateOperation { @@ -94,7 +94,7 @@ class ReactiveUpdateOperationSupport implements ReactiveUpdateOperation {
* @see org.springframework.data.r2dbc.core.ReactiveUpdateOperation.TerminatingUpdate#apply(org.springframework.data.r2dbc.query.Update)
*/
@Override
public Mono<Integer> apply(Update update) {
public Mono<Long> apply(Update update) {
Assert.notNull(update, "Update must not be null");

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

@ -137,7 +137,7 @@ public abstract class AbstractR2dbcQuery implements RepositoryQuery { @@ -137,7 +137,7 @@ public abstract class AbstractR2dbcQuery implements RepositoryQuery {
if (Number.class.isAssignableFrom(returnedType.getReturnedType())) {
return fs.rowsUpdated()
.map(integer -> converter.getConversionService().convert(integer, returnedType.getReturnedType()));
.map(count -> converter.getConversionService().convert(count, returnedType.getReturnedType()));
}
if (ReflectionUtils.isVoid(returnedType.getReturnedType())) {

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

@ -33,5 +33,5 @@ inline fun <reified T : Any> ReactiveDeleteOperation.delete(): ReactiveDeleteOpe @@ -33,5 +33,5 @@ inline fun <reified T : Any> ReactiveDeleteOperation.delete(): ReactiveDeleteOpe
/**
* Coroutines variant of [ReactiveDeleteOperation.TerminatingDelete.all].
*/
suspend fun ReactiveDeleteOperation.TerminatingDelete.allAndAwait(): Int =
suspend fun ReactiveDeleteOperation.TerminatingDelete.allAndAwait(): Long =
all().awaitSingle()

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

@ -34,4 +34,4 @@ inline fun <reified T : Any> ReactiveUpdateOperation.update(): ReactiveUpdateOpe @@ -34,4 +34,4 @@ inline fun <reified T : Any> ReactiveUpdateOperation.update(): ReactiveUpdateOpe
/**
* Coroutines variant of [ReactiveUpdateOperation.TerminatingUpdate.apply].
*/
suspend fun ReactiveUpdateOperation.TerminatingUpdate.applyAndAwait(update: Update): Int = apply(update).awaitSingle()
suspend fun ReactiveUpdateOperation.TerminatingUpdate.applyAndAwait(update: Update): Long = apply(update).awaitSingle()

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

@ -214,7 +214,7 @@ public class R2dbcEntityTemplateUnitTests { @@ -214,7 +214,7 @@ public class R2dbcEntityTemplateUnitTests {
entityTemplate
.update(Query.query(Criteria.where("name").is("Walter")), Update.update("name", "Heisenberg"), Person.class) //
.as(StepVerifier::create) //
.expectNext(1) //
.expectNext(1L) //
.verifyComplete();
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("UPDATE"));
@ -235,7 +235,7 @@ public class R2dbcEntityTemplateUnitTests { @@ -235,7 +235,7 @@ public class R2dbcEntityTemplateUnitTests {
entityTemplate.delete(Query.query(Criteria.where("name").is("Walter")), Person.class) //
.as(StepVerifier::create) //
.expectNext(1) //
.expectNext(1L) //
.verifyComplete();
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("DELETE"));

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

@ -62,7 +62,7 @@ public class ReactiveDeleteOperationUnitTests { @@ -62,7 +62,7 @@ public class ReactiveDeleteOperationUnitTests {
entityTemplate.delete(Person.class) //
.all() //
.as(StepVerifier::create) //
.expectNext(1) //
.expectNext(1L) //
.verifyComplete();
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("DELETE"));
@ -80,7 +80,7 @@ public class ReactiveDeleteOperationUnitTests { @@ -80,7 +80,7 @@ public class ReactiveDeleteOperationUnitTests {
entityTemplate.delete(Person.class) //
.from("table").all() //
.as(StepVerifier::create) //
.expectNext(1) //
.expectNext(1L) //
.verifyComplete();
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("DELETE"));
@ -99,7 +99,7 @@ public class ReactiveDeleteOperationUnitTests { @@ -99,7 +99,7 @@ public class ReactiveDeleteOperationUnitTests {
.matching(query(where("name").is("Walter"))) //
.all() //
.as(StepVerifier::create) //
.expectNext(1) //
.expectNext(1L) //
.verifyComplete();
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("DELETE"));
@ -120,7 +120,7 @@ public class ReactiveDeleteOperationUnitTests { @@ -120,7 +120,7 @@ public class ReactiveDeleteOperationUnitTests {
.matching(query(where("name").is("Walter"))) //
.all() //
.as(StepVerifier::create) //
.expectNext(1) //
.expectNext(1L) //
.verifyComplete();
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("DELETE"));

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

@ -63,7 +63,7 @@ public class ReactiveUpdateOperationUnitTests { @@ -63,7 +63,7 @@ public class ReactiveUpdateOperationUnitTests {
entityTemplate.update(Person.class) //
.apply(Update.update("name", "Heisenberg")) //
.as(StepVerifier::create) //
.expectNext(1) //
.expectNext(1L) //
.verifyComplete();
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("UPDATE"));
@ -82,7 +82,7 @@ public class ReactiveUpdateOperationUnitTests { @@ -82,7 +82,7 @@ public class ReactiveUpdateOperationUnitTests {
entityTemplate.update(Person.class) //
.inTable("table").apply(Update.update("name", "Heisenberg")) //
.as(StepVerifier::create) //
.expectNext(1) //
.expectNext(1L) //
.verifyComplete();
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("UPDATE"));
@ -102,7 +102,7 @@ public class ReactiveUpdateOperationUnitTests { @@ -102,7 +102,7 @@ public class ReactiveUpdateOperationUnitTests {
.matching(query(where("name").is("Walter"))) //
.apply(Update.update("name", "Heisenberg")) //
.as(StepVerifier::create) //
.expectNext(1) //
.expectNext(1L) //
.verifyComplete();
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("UPDATE"));
@ -124,7 +124,7 @@ public class ReactiveUpdateOperationUnitTests { @@ -124,7 +124,7 @@ public class ReactiveUpdateOperationUnitTests {
.matching(query(where("name").is("Walter"))) //
.apply(Update.update("name", "Heisenberg")) //
.as(StepVerifier::create) //
.expectNext(1) //
.expectNext(1L) //
.verifyComplete();
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("UPDATE"));

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

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

Loading…
Cancel
Save