Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
spring-projects-issues opened this issue Mar 12, 2015 · 2 comments
Assignees
Labels
in: repository Repositories abstraction status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

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
Copy link
Author

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 spring-projects-issues added in: repository Repositories abstraction status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement labels Dec 30, 2020
@rstoyanchev
Copy link

rstoyanchev commented Mar 23, 2023

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, spring-projects/spring-graphql#597, for auto-registration cases it would be useful to specify sorting preferences on such an @GraphQlRepository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: repository Repositories abstraction status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants