Adopt to Spring R2DBC changes.
Update counts now return Long instead of Integer. Closes #1198
This commit is contained in:
@@ -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 {
|
||||
* @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
|
||||
|
||||
@@ -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
|
||||
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
|
||||
* @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
|
||||
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
|
||||
}
|
||||
|
||||
PreparedOperation<?> operation = statementMapper.getMappedObject(deleteSpec);
|
||||
return this.databaseClient.sql(operation).fetch().rowsUpdated().defaultIfEmpty(0);
|
||||
return this.databaseClient.sql(operation).fetch().rowsUpdated().defaultIfEmpty(0L);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -113,7 +113,7 @@ public interface ReactiveDeleteOperation {
|
||||
* @return the number of affected rows; never {@literal null}.
|
||||
* @see Mono
|
||||
*/
|
||||
Mono<Integer> all();
|
||||
Mono<Long> all();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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())) {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 {
|
||||
|
||||
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"));
|
||||
|
||||
@@ -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 {
|
||||
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 {
|
||||
.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 {
|
||||
.matching(query(where("name").is("Walter"))) //
|
||||
.all() //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(1) //
|
||||
.expectNext(1L) //
|
||||
.verifyComplete();
|
||||
|
||||
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("DELETE"));
|
||||
|
||||
@@ -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 {
|
||||
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 {
|
||||
.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 {
|
||||
.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"));
|
||||
|
||||
@@ -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 {
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user