Search in sources :

Example 1 with DatastorePageable

use of org.springframework.cloud.gcp.data.datastore.repository.query.DatastorePageable in project spring-cloud-gcp by spring-cloud.

the class DatastoreTemplate method applyPageable.

private StructuredQuery applyPageable(StructuredQuery query, Pageable pageable) {
    if (pageable == Pageable.unpaged()) {
        return query;
    }
    Cursor cursor = null;
    if (pageable instanceof DatastorePageable) {
        cursor = ((DatastorePageable) pageable).toCursor();
    }
    StructuredQuery.Builder builder = query.toBuilder();
    if (cursor != null) {
        builder.setStartCursor(cursor).setOffset(0);
    } else {
        builder.setOffset(Math.toIntExact(pageable.getOffset()));
    }
    return builder.setLimit(pageable.getPageSize()).build();
}
Also used : StructuredQuery(com.google.cloud.datastore.StructuredQuery) Cursor(com.google.cloud.datastore.Cursor) DatastorePageable(org.springframework.cloud.gcp.data.datastore.repository.query.DatastorePageable)

Aggregations

Cursor (com.google.cloud.datastore.Cursor)1 StructuredQuery (com.google.cloud.datastore.StructuredQuery)1 DatastorePageable (org.springframework.cloud.gcp.data.datastore.repository.query.DatastorePageable)1