#363 - Polishing.

Added an integration test and tweaked the conversions to make it succeed.
The converter now does not rely on the driver to do the conversion anymore.

Original pull request: #360.
This commit is contained in:
Jens Schauder
2020-05-11 11:27:33 +02:00
parent d004bc0dd9
commit 15c64a4ee1
3 changed files with 16 additions and 2 deletions

View File

@@ -186,7 +186,7 @@ abstract class R2dbcConverters {
@Override
public T convert(Row source) {
Object object = source.get(0, targetType);
Object object = source.get(0);
return (object != null ? NumberUtils.convertNumberToTargetClass((Number) object, this.targetType) : null);
}

View File

@@ -285,6 +285,18 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg
assertThat(count).hasEntrySatisfying("count", numberOf(2));
}
@Test // gh-363
public void derivedQueryWithCountProjection() {
shouldInsertNewItems();
repository.countByNameContains("SCH") //
.as(StepVerifier::create) //
.assertNext(i -> assertThat(i).isEqualTo(2))
.verifyComplete();
}
private Condition<? super Object> numberOf(int expected) {
return new Condition<>(it -> {
return it instanceof Number && ((Number) it).intValue() == expected;
@@ -312,6 +324,8 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg
@Query("DELETE from legoset where manual = :manual")
Mono<Void> deleteAllByManual(int manual);
Mono<Integer> countByNameContains(String namePart);
}
@Getter

View File

@@ -619,7 +619,7 @@ public class PartTreeR2dbcQueryUnitTests {
+ ".foo FROM " + TABLE + " WHERE " + TABLE + ".first_name = $1");
}
@Test // DATAJDBC-534
@Test // gh-363
public void createsQueryForCountProjection() throws Exception {
R2dbcQueryMethod queryMethod = getQueryMethod("countByFirstName", String.class);