Spring Cursor Paging - v0.8.0 Release
[TLDR]
Cursor based paging is an alternative to the offset/limit based paging supported by SQL/RDBMS and Spring, which avoids performance issues in case of large result-sets.
spring-cursorpaging-jpa is an open source library bringing this concept as fragment repository implementation to spring data.
The history
This library is in fact the 4th implementation where I was involved into.
The first I did in the context of an commercial product - still I didn't found the time clean up some loose ends and to make it really work as fragment interface.
The second was not done by myself, but some colleagues, but there the concept of spring-data and it's repository interfaces wasn't used at all.
The third was the first version of this library which I totally discarded again, mostly due to some issues I got in the serialization/deserialization support for the cursor (and java-generics).
And finally, here the first GA release of the cursorpaging libraries.
Release v0.8.0 published
Features included are:
Recommended by LinkedIn
Usage
The basic use should be very simple, after the basic setup, just add the CursorPageRepository<YourDataEntityClass> as interface to your repository bean.
Then start building page-requests. Here an example:
@Repository
public interface DataRecordRepository extends JpaRepository<DataRecord, UUID>, CursorPageRepository<DataRecord> {
}
public void queryData() {
final PageRequest<DataRecord> request = PageRequest.create( b -> b.pageSize( 100 )
.desc( Attribute.path( DataRecord_.auditInfo, AuditInfo_.createdAt ) )
.asc( DataRecord_.id )
.filter( Filter.attributeIs( DataRecord_.name, "Alpha" ) ) );
final Page<DataRecord> page = dataRecordRepository.findPage( request );
page.forEach( System.out::println );
}
Challenges
My biggest challenge in this project was not the implementation, but to be honest, the project setup with gradle, especially the "publishing" to maven central, where it was really hard to find a suitable plugin which worked with the buildSrc setup which I had chosen. Many thanks to Francisco Solis, for providing a working solution for me here!
Outlook
Depending on the feedback I get I will continue, heading for a v1.0, where also "previous" page cursor support is added.
Congratulations Peter V. for bringing it over the finish line. A really useful helper that everybody using Spring and JPA should checkout. I especially like that it's stateless on the server side.
Many thanks Peter V.. I‘m so curious to see your work - always appreciated it in the past
I will have a look at it!