Search in sources :

Example 1 with CassandraPageRequest

use of org.springframework.data.cassandra.core.query.CassandraPageRequest in project spring-data-cassandra by spring-projects.

the class SimpleCassandraRepositoryUnitTests method shouldSelectWithPaging.

// DATACASS-56
@Test
void shouldSelectWithPaging() {
    CassandraPageRequest pageRequest = CassandraPageRequest.first(10, Direction.ASC, "foo");
    repository = new SimpleCassandraRepository<Object, String>(new MappingCassandraEntityInformation(converter.getMappingContext().getRequiredPersistentEntity(SimplePerson.class), converter), cassandraOperations);
    repository.findAll(pageRequest);
    verify(cassandraOperations).slice(Query.empty().sort(pageRequest.getSort()).queryOptions(QueryOptions.builder().pageSize(10).build()), SimplePerson.class);
}
Also used : CassandraPageRequest(org.springframework.data.cassandra.core.query.CassandraPageRequest) Test(org.junit.jupiter.api.Test)

Example 2 with CassandraPageRequest

use of org.springframework.data.cassandra.core.query.CassandraPageRequest in project spring-data-cassandra by spring-projects.

the class EntityQueryUtils method readSlice.

/**
 * Read a {@link Slice} of data from the {@link Iterable} of {@link Row}s for a {@link Pageable}.
 *
 * @param rows must not be {@literal null}.
 * @param pagingState
 * @param mapper must not be {@literal null}.
 * @param page
 * @param pageSize
 * @return the resulting {@link Slice}.
 * @since 2.1
 */
static <T> Slice<T> readSlice(Iterable<Row> rows, @Nullable ByteBuffer pagingState, RowMapper<T> mapper, int page, int pageSize) {
    List<T> result = new ArrayList<>(pageSize);
    Iterator<Row> iterator = rows.iterator();
    int index = 0;
    while (iterator.hasNext()) {
        T element = mapper.mapRow(iterator.next(), index++);
        result.add(element);
    }
    CassandraPageRequest pageRequest = CassandraPageRequest.of(PageRequest.of(page, pageSize), pagingState);
    return new SliceImpl<>(result, pageRequest, pagingState != null);
}
Also used : CassandraPageRequest(org.springframework.data.cassandra.core.query.CassandraPageRequest) ArrayList(java.util.ArrayList) Row(com.datastax.oss.driver.api.core.cql.Row) SliceImpl(org.springframework.data.domain.SliceImpl)

Aggregations

CassandraPageRequest (org.springframework.data.cassandra.core.query.CassandraPageRequest)2 Row (com.datastax.oss.driver.api.core.cql.Row)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 SliceImpl (org.springframework.data.domain.SliceImpl)1