Skip to content

Add PageableItemReader - #5477

Open
scordio wants to merge 1 commit into
spring-projects:mainfrom
scordio:gh-910-pageable-item-reader
Open

Add PageableItemReader#5477
scordio wants to merge 1 commit into
spring-projects:mainfrom
scordio:gh-910-pageable-item-reader

Conversation

@scordio

@scordio scordio commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

This PR adds PageableItemReader, a type-safe RepositoryItemReader alternative that uses a Function<Pageable, Slice<?>> instead of the reflection-based strategy for query invocation.

PageableItemReader is deliberately designed after RepositoryItemReader in its paging, restart, and locking behavior. However, it favors constructor parameters instead of setters for mandatory configuration.

In addition, compared to RepositoryItemReader, there are two improvements:

  • Precomputes org.springframework.data.domain.Sort at construction time instead of inside doPageRead()
  • Simplifies concurrency by relying only on lock-based visibility/atomicity, as volatile field modifiers were redundant with the existing ReentrantLock

Such improvements could also be applied to RepositoryItemReader, but I preferred keeping this PR focused on the new class. Please let me know if RepositoryItemReader should get the same; I'll be happy to raise a separate PR for it.

Please note that I preferred introducing a dedicated reader rather than enhancing RepositoryItemReader to support both use cases (following the rationale at #4484 (comment)). However, in case enhancing RepositoryItemReader would be preferred, let me know and I'll take care of the changes.

Open Points

There are at least two more things to do:

  • Add PageableItemReader to the documentation
  • Deprecate RepositoryItemReader in favor of PageableItemReader?

However, before starting, I'd like a preliminary feedback to make sure I'm going in the right direction.


Signed-off-by: Stefano Cordio <stefano.cordio@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve JPA repository readers to be more typesafe [BATCH-2697]

1 participant