#469 - Suppress emission of null values when using simple and primitive result types.
Results projected onto simple and primitive types that are null are no longer emitted. A SQL query SELECT MAX(age) FROM my_table that returns a SQL NULL and that would be consumed as Long.class (Publisher<Long>) is an example for a primitive type that can be null. Since Reactive Streams prohibits the propagation of null values by a Publisher to a Subscriber the only viable option is to suppress null results by wrapping the mapping function into Optional result values and filter these values later to avoid null being emitted.
This commit is contained in:
@@ -104,7 +104,25 @@ public class R2dbcEntityTemplateUnitTests {
|
||||
assertThat(statement.getBindings()).hasSize(1).containsEntry(0, Parameter.from("Walter"));
|
||||
}
|
||||
|
||||
@Test // gh-220
|
||||
@Test // gh-469
|
||||
public void shouldProjectExistsResult() {
|
||||
|
||||
MockRowMetadata metadata = MockRowMetadata.builder()
|
||||
.columnMetadata(MockColumnMetadata.builder().name("name").build()).build();
|
||||
MockResult result = MockResult.builder().rowMetadata(metadata)
|
||||
.row(MockRow.builder().identified(0, Object.class, null).build()).build();
|
||||
|
||||
recorder.addStubbing(s -> s.startsWith("SELECT"), result);
|
||||
|
||||
entityTemplate.select(Person.class) //
|
||||
.as(Integer.class) //
|
||||
.matching(Query.empty().columns("MAX(age)")) //
|
||||
.all() //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // gh-469
|
||||
public void shouldExistsByCriteria() {
|
||||
|
||||
MockRowMetadata metadata = MockRowMetadata.builder()
|
||||
|
||||
@@ -92,6 +92,11 @@ public class H2R2dbcRepositoryIntegrationTests extends AbstractR2dbcRepositoryIn
|
||||
return H2LegoSetRepository.class;
|
||||
}
|
||||
|
||||
@Test // gh-469
|
||||
public void shouldSuppressNullValues() {
|
||||
repository.findMax("doo").as(StepVerifier::create).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // gh-235
|
||||
public void shouldReturnUpdateCount() {
|
||||
|
||||
@@ -139,6 +144,9 @@ public class H2R2dbcRepositoryIntegrationTests extends AbstractR2dbcRepositoryIn
|
||||
|
||||
interface H2LegoSetRepository extends LegoSetRepository {
|
||||
|
||||
@Query("SELECT MAX(manual) FROM legoset WHERE name = :name")
|
||||
Mono<Integer> findMax(String name);
|
||||
|
||||
@Override
|
||||
@Query("SELECT name FROM legoset")
|
||||
Flux<Named> findAsProjection();
|
||||
|
||||
Reference in New Issue
Block a user