Reputation: 1030
I know this has been asked before, but Spring Data is growing a lot with time.
How would you implement a findAll() that returns millions of rows? I know Spring Data has stream API, even though I'm not exactly sure if it would be safe with so much data. From my understanding, this is not going to retrieve all data at once, but while processing it.
Stream<T> streamAllBy...(...);
Also, a second approach would be this, only downside would be that I have to deal manually with pagination.
Slice<T> findAllBy...(..., Pageable pageable)
Any ideas?
Upvotes: 0
Views: 333
Reputation: 18129
Declaring Stream<T>
as a return type for a query method is indeed the preferred approach. The repository layer adapts query execution to the declared type and performs transparent forward-pagination while consuming the stream.
Spring Data's repository approach requires certain method signatures, that might be not practical in each scenario.
Upvotes: 1