spring-projects / spring-data-commons

Spring Data Commons. Interfaces and code shared between the various datastore specific implementations.
https://spring.io/projects/spring-data
Apache License 2.0
770 stars 670 forks source link

Consider PageableDefaults and SortDefaults on query methods [DATACMNS-657] #1121

Open spring-projects-issues opened 9 years ago

spring-projects-issues commented 9 years ago

Oliver Drotbohm opened DATACMNS-657 and commented

It would be cool if query methods on repositories would consider @PageableDefaults and @SortDefaults on Pageable and Sort parameters and expose them via the QueryMethod API.

The annotation configuration should be used when null is provided for the corresponding parameter


Affects: 1.9.2 (Evans SR2), 1.10 RC1 (Fowler)

2 votes, 3 watchers

spring-projects-issues commented 7 years ago

Oliver Drotbohm commented

Three ways to skin the cat here:

  1. Introduce QueryMethod.getDefaulted(Pageable pageable) and pipe the Pageable obtained from the ParameterAccessor through that method.
  2. Introduce constructor in ParametersParameterAccessor to take a QueryMethod and expose the defaults defined on QueryMethod.
  3. Introduce QueryMethodParameterAccessor as subtype of ParametersAccessor to take a QueryMethod instead of a Parameters instance to overwrite getPageable() and getSort() to consider the defaults declared on the method.

Thought about the conflict of both a Pageable and Sort declared, the latter defining a default and a value provided for the former containing a Sort.unsorted() which would raise the question of whether to apply the sorting default rules but it seems that QueryMethod currently does not allow both types do be declared in a single method.

Is it worth considering to allow @PageableDefault and @SortDefault on the type level so that it applies to all methods using Pageable and Sort as parameters?

rstoyanchev commented 1 year ago

Is it worth considering to allow @PageableDefault and @SortDefault on the type level so that it applies to all methods using Pageable and Sort as parameters?

We've a case for type level @SortDefault. In Spring for GraphQL, there is auto-registration of Querydsl and Query by Example repositories to perform GraphQL queries. For pagination and sorting support, https://github.com/spring-projects/spring-graphql/issues/597, for auto-registration cases it would be useful to specify sorting preferences on such an @GraphQlRepository.