spring-data-commons icon indicating copy to clipboard operation
spring-data-commons copied to clipboard

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

Open spring-projects-issues opened this issue 10 years ago • 2 comments

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 avatar Mar 12 '15 04:03 spring-projects-issues

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?

spring-projects-issues avatar Jul 06 '17 10:07 spring-projects-issues

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.

rstoyanchev avatar Mar 23 '23 10:03 rstoyanchev