code: protected <E> Page<E> findPaginatedGeneric(Pageable pageable, JPAQuery<E> query, boolean determineTotal) {
  
      long total = -1;
      if (determineTotal) {
        total = query.clone().fetchCount();
      }
      long offset = 0;
      if (pageable != null) {
        offset = pageable.getOffset();
        query.offset(offset);
        query.limit(pageable.getPageSize());
        applySort(query, pageable.getSort());
      }
      List<E> hits = query.fetch();
      if (total == -1) {
        total = offset + hits.size();
      }
      return new PageImpl<>(hits, pageable, total);
    }
docs: Returns a {@link Page} of entities according to the supplied {@link Pageable} and {@link JPAQuery}.
  
  @param <E> generic type of the entity.
  @param pageable contains information about the requested page and sorting.
  @param query is a query which is pre-configured with the desired conditions for the search.
  @param determineTotal - {@code true} to determine the {@link Page#getTotalElements() total number of hits},
  {@code false} otherwise.
  @return a paginated list.