Decouple Paging and Sorting repositories from CrudRepository.

This way they can be combined with different variants of CrudRepositories.

This affects
`PagingAndSortingRepository`, `ReactiveSortingRepository`, `CoroutineSortingRepository`, and `RxJavaSortingRepository`.

Any repository implementing those interfaces now needs to also implement a suitable CRUD repository, or needs to manually add the methods from a CRUD repository as needed.

Closes #2537
Original pull request: #2540.
This commit is contained in:
Jens Schauder
2022-01-28 14:35:20 +01:00
committed by Mark Paluch
parent c9cdc93809
commit 37eee0e35d
16 changed files with 80 additions and 158 deletions

View File

@@ -20,16 +20,19 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
/**
* Extension of {@link CrudRepository} to provide additional methods to retrieve entities using the pagination and
* sorting abstraction.
* Repository fragment to provide methods to retrieve entities using the pagination and sorting abstraction. In many
* cases this will be combined with {@link CrudRepository} or similar or with manually added methods to provide CRUD
* functionality.
*
* @author Oliver Gierke
* @author Jens Schauder
* @see Sort
* @see Pageable
* @see Page
* @see CrudRepository
*/
@NoRepositoryBean
public interface PagingAndSortingRepository<T, ID> extends CrudRepository<T, ID> {
public interface PagingAndSortingRepository<T, ID> extends Repository<T, ID> {
/**
* Returns all entities sorted by the given options.

View File

@@ -20,20 +20,24 @@ import reactor.core.publisher.Mono;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.Repository;
/**
* Extension of {@link ReactiveCrudRepository} to provide additional methods to retrieve entities using the sorting
* abstraction.
* Repository fragment to provide methods to retrieve entities using the sorting abstraction. In many cases it
* should be combined with {@link ReactiveCrudRepository} or a similar repository interface in order to add CRUD
* functionality.
*
* @author Mark Paluch
* @author Christoph Strobl
* @author Jens Schauder
* @since 2.0
* @see Sort
* @see Mono
* @see Flux
* @see ReactiveCrudRepository
*/
@NoRepositoryBean
public interface ReactiveSortingRepository<T, ID> extends ReactiveCrudRepository<T, ID> {
public interface ReactiveSortingRepository<T, ID> extends Repository<T, ID> {
/**
* Returns all entities sorted by the given options.

View File

@@ -19,18 +19,21 @@ import io.reactivex.rxjava3.core.Flowable;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.Repository;
/**
* Extension of {@link RxJava3CrudRepository} to provide additional methods to retrieve entities using the sorting
* abstraction.
*
* Repository fragment to provide methods to retrieve entities using the sorting abstraction. In many cases this
* should be combined with {@link RxJava3CrudRepository} or a similar interface to provide CRUD functionality.
*
* @author Mark Paluch
* @author Jens Schauder
* @since 2.4
* @see Sort
* @see Flowable
* @see RxJava3CrudRepository
*/
@NoRepositoryBean
public interface RxJava3SortingRepository<T, ID> extends RxJava3CrudRepository<T, ID> {
public interface RxJava3SortingRepository<T, ID> extends Repository<T, ID> {
/**
* Returns all entities sorted by the given options.

View File

@@ -35,6 +35,7 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
* @author Christoph Strobl
* @author Jens Schauder
* @since 1.10
*/
public class DefaultRepositoryInvokerFactory implements RepositoryInvokerFactory {
@@ -93,7 +94,7 @@ public class DefaultRepositoryInvokerFactory implements RepositoryInvokerFactory
@SuppressWarnings("unchecked")
protected RepositoryInvoker createInvoker(RepositoryInformation information, Object repository) {
if (repository instanceof PagingAndSortingRepository) {
if (repository instanceof PagingAndSortingRepository && repository instanceof CrudRepository) {
return new PagingAndSortingRepositoryInvoker((PagingAndSortingRepository<Object, Object>) repository, information,
conversionService);
} else if (repository instanceof CrudRepository) {

View File

@@ -21,6 +21,7 @@ import java.util.Optional;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.core.RepositoryMetadata;
@@ -29,6 +30,7 @@ import org.springframework.data.repository.core.RepositoryMetadata;
* avoid reflection overhead introduced by the superclass.
*
* @author Oliver Gierke
* @author Jens Schauder
* @since 1.10
*/
class PagingAndSortingRepositoryInvoker extends CrudRepositoryInvoker {
@@ -47,7 +49,7 @@ class PagingAndSortingRepositoryInvoker extends CrudRepositoryInvoker {
public PagingAndSortingRepositoryInvoker(PagingAndSortingRepository<Object, Object> repository,
RepositoryMetadata metadata, ConversionService conversionService) {
super(repository, metadata, conversionService);
super((CrudRepository<Object, Object>) repository, metadata, conversionService);
var crudMethods = metadata.getCrudMethods();