#407 - Add ReactiveSortingRepository support.

Implements ReactiveSortingRepository on SimpleR2dbcRepository. Also changed R2dbcRepository to extend ReactiveSortingRepository and updated comments where it felt reasonable.

Added a single unit test for the new method, and changed the base interface of LegoSetRepository in AbstractR2dbcRepositoryIntegrationTests for integration testing purposes.

Clarify documentation on reactive repository base interfaces

Adds some language calling out ReactiveSortingRepository and fixes consistency between related examples.

Original pull request: #408.
This commit is contained in:
Stephen Cohen
2020-07-21 20:12:33 -04:00
committed by Mark Paluch
parent d51586890c
commit 4da92bdc7c
6 changed files with 46 additions and 11 deletions

View File

@@ -48,7 +48,7 @@ import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory;
import org.springframework.data.r2dbc.testing.R2dbcIntegrationTestSupport;
import org.springframework.data.relational.core.mapping.Table;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.data.repository.reactive.ReactiveSortingRepository;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.reactive.TransactionalOperator;
@@ -56,6 +56,7 @@ import org.springframework.transaction.reactive.TransactionalOperator;
* Abstract base class for integration tests for {@link LegoSetRepository} using {@link R2dbcRepositoryFactory}.
*
* @author Mark Paluch
* @author Stephen Cohen
*/
public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcIntegrationTestSupport {
@@ -303,7 +304,7 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg
}
@NoRepositoryBean
interface LegoSetRepository extends ReactiveCrudRepository<LegoSet, Integer> {
interface LegoSetRepository extends ReactiveSortingRepository<LegoSet, Integer> {
Flux<LegoSet> findByNameContains(String name);

View File

@@ -39,6 +39,7 @@ import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.domain.Persistable;
import org.springframework.data.domain.Sort;
import org.springframework.data.r2dbc.convert.MappingR2dbcConverter;
import org.springframework.data.r2dbc.core.DatabaseClient;
import org.springframework.data.r2dbc.core.ReactiveDataAccessStrategy;
@@ -55,6 +56,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
*
* @author Mark Paluch
* @author Bogdan Ilchyshyn
* @author Stephen Cohen
*/
public abstract class AbstractSimpleR2dbcRepositoryIntegrationTests extends R2dbcIntegrationTestSupport {
@@ -313,6 +315,26 @@ public abstract class AbstractSimpleR2dbcRepositoryIntegrationTests extends R2db
}).verifyComplete();
}
@Test // gh-407
public void shouldFindAllWithSort() {
jdbc.execute("INSERT INTO legoset (name, manual) VALUES('FORSCHUNGSSCHIFF', 13)");
jdbc.execute("INSERT INTO legoset (name, manual) VALUES('SCHAUFELRADBAGGER', 12)");
jdbc.execute("INSERT INTO legoset (name, manual) VALUES('VOLTRON', 15)");
jdbc.execute("INSERT INTO legoset (name, manual) VALUES('RALLYEAUTO', 14)");
repository.findAll(Sort.by("manual").ascending()) //
.map(LegoSet::getName) //
.collectList() //
.as(StepVerifier::create) //
.assertNext(actual -> assertThat(actual).containsExactly(
"SCHAUFELRADBAGGER",
"FORSCHUNGSSCHIFF",
"RALLYEAUTO",
"VOLTRON"
)).verifyComplete();
}
@Test
public void shouldFindAllByIdUsingIterable() {