![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
io.github.halfweight:spring-data-jpa-cursor-paging
Advanced tools
The spring-data-jpa-cursor-paging Java library allows to easily implement cursor pagination for Spring Boot projects. This is a community-based project, not maintained by the Spring Framework Contributors (Pivotal)
Add the following dependency
<groupId>io.github.halfweight</groupId>
<artifactId>spring-data-jpa-cursor-paging</artifactId>
<version>last-version</version>
Configure the repository base class to be used to create repository proxies for this particular configuration
@EnableJpaRepositories(repositoryBaseClass = CustomRepositoryImpl.class)
Create a jpa repository that extends the CustomRepository
public interface UserRepository extends CustomRepository<User, Long> {
}
Use the created repository and call findAllBy
to execute cursor pagination.
The first parameter is a specification to filter for.
The second parameter is a CursorPageRequest
. For the first query, you have to fill the size and sort fields.
From the second query onwards make sure to provide the continuationToken
userRepository.findAllBy(null, CursorPageRequest.of(1, Sort.by(Sort.Order.desc("id"))))
This query returns a CursorPaginationSlice
that contains
field | description |
---|---|
content | list of found rows |
hasNext | if there are other elements |
continuationToken | token to use to execute the next query. Keep in mind that it changes for every query |
size | size of content |
You can use every field in your entity to sort, but keep in mind that :
When you use the continuationToken you have to use always the same sort fields
Be sure to use always a unique field as a sorting field for your query as the last parameter (for example the column id)
To convert values to strings and vice-versa the library uses the ConvertUtils
from it.halfweight.spring.cursor.pagination.jpa.util
. This is useful
to store information into the continuationToken.
If in your entity you are using a not mapped type you would use to sort, you can add a custom converter in this way:
ConverterUtil.config(Map.of(Instant.class,new AbstractConverter() {
@Override
protected <T> T convertToType(Class<T> type, Object value) throws Throwable {
return (T) Instant.ofEpochMilli(Long.parseLong((String) value));
}
@Override
protected String convertToString(Object value) throws Throwable {
return Long.toString(((Instant)value).toEpochMilli());
}
@Override
protected Class<?> getDefaultType() {
return Instant.class;
}
}));
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
FAQs
Cursor pagination jpa
We found that io.github.halfweight:spring-data-jpa-cursor-paging demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.