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

[Fix] Query with(pageable) and with(Pageable.unpaged) #1

Merged
merged 1 commit into from
Mar 25, 2022

Conversation

Jatish-Khanna
Copy link
Owner

There's a fix proposed when we want to use the same query for the pageable and unpaged instance. A typical case would be

Get all the Object using the mongoTemplate from the Repository
mongoTemplate.find(filterQuery.with(pageable), CustomBean.class)

Get the count of all the instance but unpaged
mongoTemplate.count(filterQuery.with(Pageable.unpaged()), CustomBean.class);

And implementing the page instance
new PageImpl<>(mongoDocumentsPaged, pageable, count);

In the order of invoking
with(pageable) comes first will set the parameters - "skip, limit, sort" and then invoking
with(Pageable.unpaged()) won't reset them to "0, 0, Sort.unsorted()"

The fix will reset

  1. in the with(Pageable pageable)

     	this.limit = 0; // default value
     	this.skip = 0; // default value
    
  2. in the with(Sort sort)
    this.sort = sort; // which will be Sort.unsorted()

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

There's a fix proposed when we want to use the same query for the pageable and unpaged instance. A typical case would be 

Get all the Object using the mongoTemplate from the Repository
      mongoTemplate.find(filterQuery.with(pageable), CustomBean.class)

Get the count of all the instance but unpaged
     mongoTemplate.count(filterQuery.with(Pageable.unpaged()), CustomBean.class);

And implementing the page instance
   new PageImpl<>(mongoDocumentsPaged, pageable, count);

In the order of invoking 
  with(pageable) comes first will set the parameters - "skip, limit, sort" and then invoking 
  with(Pageable.unpaged()) won't reset them to "0, 0, Sort.unsorted()" 

The fix will reset 

1) in the with(Pageable pageable)
  
			this.limit = 0; // default value
			this.skip = 0; // default value

2) in the with(Sort sort)
   this.sort = sort; // which will be Sort.unsorted()
@Jatish-Khanna Jatish-Khanna merged commit 950d485 into main Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant