Let’s define an entity as follows:
@Entity
public Foo{
...
private ZonedDateTime marketDate;
...
}
And its corresponding repository interface:
@Repository
public interface FooRepository extends JpaRepository<Foo, Long> {
List<Foo> findTop99OrderByMarketDateDesc();
}
The method findTop99OrderByMarketDateDesc() effectively serves its purpose. However, if different result sizes are required, similar methods would be necessary. This can lead to the proliferation of similar methods to accommodate various result sizes.
To address this flexibility issue, employing a method with a Page return type might be a more elegant solution:
Page<Foo> findAllOrderByMarketDateDesc(Pageable pageable);
This approach allows for dynamic assignment of the page size programmatically, catering to different result size requirements. Additionally, it ensures that only the necessary data for the current page is retrieved, enhancing efficiency. To retrieve data with a specified size, the data on the first page is needed. If this approach works in general, can this approach handle large datasets, such as 1,000 entries?