Browse Source

#235 - Polishing.

Added test and tweaked documentation to clarify that other numeric types beyond `Integer` are admissible.
Split a test in order to have meaningful test names.

Original pull request: #238.
pull/1188/head
Jens Schauder 6 years ago
parent
commit
d442fca38d
No known key found for this signature in database
GPG Key ID: 996B1389BA0721C3
  1. 6
      src/main/asciidoc/reference/r2dbc-repositories.adoc
  2. 12
      src/test/java/org/springframework/data/r2dbc/repository/H2R2dbcRepositoryIntegrationTests.java
  3. 9
      src/test/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryMethodUnitTests.java

6
src/main/asciidoc/reference/r2dbc-repositories.adoc

@ -142,9 +142,9 @@ Mono<Integer> setFixedFirstnameFor(String firstname, String lastname);
The result of a modifying query can be: The result of a modifying query can be:
* `Void` to discard update count and await completion * `Void` to discard update count and await completion.
* `Integer` emitting the affected rows count * `Integer` or another numeric type emitting the affected rows count.
* `Boolean` to emit whether at least one row was updated * `Boolean` to emit whether at least one row was updated.
The `@Modifying` annotation is only relevant in combination with the `@Query` annotation. The `@Modifying` annotation is only relevant in combination with the `@Query` annotation.
Derived custom methods do not require this annotation. Derived custom methods do not require this annotation.

12
src/test/java/org/springframework/data/r2dbc/repository/H2R2dbcRepositoryIntegrationTests.java

@ -89,6 +89,14 @@ public class H2R2dbcRepositoryIntegrationTests extends AbstractR2dbcRepositoryIn
repository.updateManual(42).as(StepVerifier::create).expectNext(2L).verifyComplete(); repository.updateManual(42).as(StepVerifier::create).expectNext(2L).verifyComplete();
} }
@Test // gh-235
public void shouldReturnUpdateCountAsDouble() {
shouldInsertNewItems();
repository.updateManualAndReturnDouble(42).as(StepVerifier::create).expectNext(2.0).verifyComplete();
}
@Test // gh-235 @Test // gh-235
public void shouldReturnUpdateSuccess() { public void shouldReturnUpdateSuccess() {
@ -134,5 +142,9 @@ public class H2R2dbcRepositoryIntegrationTests extends AbstractR2dbcRepositoryIn
@Query("UPDATE legoset set manual = :manual") @Query("UPDATE legoset set manual = :manual")
@Modifying @Modifying
Mono<Void> updateManualAndReturnNothing(int manual); Mono<Void> updateManualAndReturnNothing(int manual);
@Query("UPDATE legoset set manual = :manual")
@Modifying
Mono<Double> updateManualAndReturnDouble(int manual);
} }
} }

9
src/test/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryMethodUnitTests.java

@ -72,6 +72,14 @@ public class R2dbcQueryMethodUnitTests {
} }
@Test // gh-235 @Test // gh-235
public void detectsNotModifyingQuery() throws Exception {
R2dbcQueryMethod queryMethod = queryMethod(SampleRepository.class, "differentTable");
assertThat(queryMethod.isModifyingQuery()).isFalse();
}
@Test
public void detectsTableNameFromRepoTypeIfReturnTypeNotAssignable() throws Exception { public void detectsTableNameFromRepoTypeIfReturnTypeNotAssignable() throws Exception {
R2dbcQueryMethod queryMethod = queryMethod(SampleRepository.class, "differentTable"); R2dbcQueryMethod queryMethod = queryMethod(SampleRepository.class, "differentTable");
@ -79,7 +87,6 @@ public class R2dbcQueryMethodUnitTests {
assertThat(metadata.getJavaType()).isAssignableFrom(Address.class); assertThat(metadata.getJavaType()).isAssignableFrom(Address.class);
assertThat(metadata.getTableName()).isEqualTo("contact"); assertThat(metadata.getTableName()).isEqualTo("contact");
assertThat(queryMethod.isModifyingQuery()).isFalse();
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)

Loading…
Cancel
Save