0

I have a problem with implementation of lazy-loading for Grid. The following code represent DataProvider:

private DataProvider<ReservationDTO, Void> buildDataProvider() {
    return DataProvider.fromCallbacks(
        query -> {
            final List<SortDTO.OrderDTO> orders = query.getSortOrders().stream()
                .map(queryOrder -> SortDTO.OrderDTO.builder()
                    .property(queryOrder.getSorted())
                    .direction(queryOrder.getDirection() == SortDirection.DESCENDING ? DirectionEnum.ASC : DirectionEnum.DESC)
                    .build()
                )
                .collect(Collectors.toList());

            if (orders.isEmpty()) {
                orders.add(SortDTO.OrderDTO.builder()
                    .property("createdAt")
                    .direction(DirectionEnum.ASC)
                    .build());
            }

            final FindReservationsRequestDTO request = FindReservationsRequestDTO.builder()
                .criteria(buildSearchCriteria())
                .sort(SortDTO.builder()
                    .orders(orders)
                    .build())
                .build();

            return reservationsResource.getAllReservations(request, query.getOffset(), query.getLimit()).getContent().stream();
        },
        query -> reservationsResource.getReservationCount(FindReservationsRequestDTO.builder()
            .criteria(buildSearchCriteria())
            .build())
    );
}

If i understand it right, "offset" and "limit" values of query have to be defined automatically by Vaadin. But when i debug peace of code above i can see that offset = 0, limit = 2147483647. It means that all data from database is loaded by first and only one query. So, lazy-loading in this case doesn't make any sense.

Please help to understand what i did wrong!

  • what happens if you change `query.getLimit()` to `10`? – petey Jun 06 '17 at 18:35
  • 1
    This part of the code does not look like it's responsible (it's pretty standard). So the error must come from somewhere else. The values for offset/limit you see there are the defaults for a `new Query()` which is only used to write a declarative design or on "select all". – cfrick Jun 07 '17 at 09:31

0 Answers0