code: protected PaginatedList<DTO> findPaginatedWithQueryFilterAndSort(DBQuery.Query query,
                                                                       Predicate<DTO> filter,
                                                                       DBSort.SortBuilder sort,
                                                                       int page,
                                                                       int perPage) {
          final AtomicInteger total = new AtomicInteger(0);
  
          try (final Stream<DTO> cursor = streamQueryWithSort(query, sort)) {
              // First created a filtered stream
              final Stream<DTO> dtoStream = cursor
                      .filter(filter)
                      .peek(dto -> total.incrementAndGet());
  
              // Then use that filtered stream and only collect the entries according to page and perPage
              final List<DTO> list = Stream.of(dtoStream)
                      .flatMap(stream -> stream)
                      .skip(perPage * Math.max(0, page - 1))
                      .limit(perPage)
                      .collect(Collectors.toList());
  
              return new PaginatedList<>(list, total.get(), page, perPage);
          }
      }
docs: Returns a {@link PaginatedList<DTO>} for the given query, filter and pagination parameters.
  <p>
  Since the database cannot execute the filter function directly, this method streams over the result cursor
  and executes the filter function for each database object. <strong>This increases memory consumption and should only be
  used if necessary.</strong> Use the
  {@link PaginatedDbService#findPaginatedWithQueryFilterAndSort(DBQuery.Query, Predicate, DBSort.SortBuilder, int, int) #findPaginatedWithQueryAndSort()}
  method if possible.
  <p>
  This method is only accessible by subclasses to avoid exposure of the {@link DBQuery} and {@link DBSort}
  interfaces to consumers.
  
  @param query the query to execute
  @param filter the filter to apply to each database entry
  @param sort the sort builder for the query
  @param page the page number that should be returned
  @param perPage the number of entries per page
  @return the paginated list