Class PaginationServiceImpl

    • Constructor Detail

      • PaginationServiceImpl

        public PaginationServiceImpl​(org.springframework.transaction.PlatformTransactionManager transactionManager,
                                     org.hibernate.SessionFactory sessionFactory)
    • Method Detail

      • performPaginationRequest

        public <H,​M> PageResponse<M> performPaginationRequest​(LimitedRequest initialRequest,
                                                                    PaginationBatch<H> fetchPage,
                                                                    Function<? super H,​M> modelConverter)
        Description copied from interface: PaginationService
        Perform a pagination request, this will execute the fetchBatch function as many times as necessary to retrieve the page of results. Each execution of the fetch page function will pull at most LimitedRequest.getMaxLimit() results from the datasource. FetchBatch will be executed in a new transaction for each batch to prevent excessive memory usage. It is expected that any permission checking is performed in the PaginationBatch.

        The PaginationService is responsible for ensuring that enough results are returned from the PaginationBatch to fulfill the request. The PaginationBatch should not treat the pageRequest getStart and getLimit values as user specific indexes, only results the user can see should be returned. If a user does not have permission to see any results in the requested range an empty list should be returned in the response and the hasMore flag set if there are more results still to check. The pagination service will call again if more results are required.

        Specified by:
        performPaginationRequest in interface PaginationService
        Parameters:
        initialRequest - - a request for a range of data
        fetchPage - - the function to supply the results
        modelConverter - - a function to convert from the supplied object to a model object, this will be executed within a transaction.
        Returns:
        a PageResponse of model objects, with results that the user is allowed to see.
      • performPaginationListRequest

        public <H,​M> PageResponse<M> performPaginationListRequest​(LimitedRequest initialRequest,
                                                                        PaginationBatch<H> fetchPage,
                                                                        Function<Iterable<H>,​Iterable<M>> modelConverter)
        Description copied from interface: PaginationService
        Perform a pagination request, this will execute the fetchBatch function as many times as necessary to retrieve the page of results. Each execution of the fetch page function will pull at most LimitedRequest.getMaxLimit() results from the datasource. FetchBatch will be executed in a new transaction for each batch to prevent excessive memory usage. It is expected that any permission checking is performed in the PaginationBatch.

        The PaginationService is responsible for ensuring that enough results are returned from the PaginationBatch to fulfill the request. The PaginationBatch should not treat the pageRequest getStart and getLimit values as user specific indexes, only results the user can see should be returned. If a user does not have permission to see any results in the requested range an empty list should be returned in the response and the hasMore flag set if there are more results still to check. The pagination service will call again if more results are required.

        Specified by:
        performPaginationListRequest in interface PaginationService
        Parameters:
        initialRequest - - a request for a range of data
        fetchPage - - the function to supply the results
        modelConverter - - a function to convert from the supplied object to a model object, this will be executed within a transaction.
        Returns:
        a PageResponse of model objects, with results that the user is allowed to see.
      • performPaginationListRequestWithCursor

        public <H,​M> PageResponse<M> performPaginationListRequestWithCursor​(LimitedRequest initialRequest,
                                                                                  Function<LimitedRequest,​PageResponse<H>> fetchBatch,
                                                                                  Function<Iterable<H>,​Iterable<M>> modelConverter,
                                                                                  BiFunction<H,​Boolean,​Cursor> cursorCalculator)
        Description copied from interface: PaginationService
        Perform a pagination request, this will execute the fetchBatch function as many times as to retrieve the page of results. Each execution of the fetch page function will pull at most LimitedRequest.getMaxLimit() results from the datasource. FetchBatch will be executed in a new transaction for each batch to prevent excessive memory usage. It is expected that any permission checking is performed in the PaginationBatch.

        The PaginationService is responsible for ensuring that enough results are returned from the fetchBatch to fulfill the request. Only results the user can see should be returned.

        Specified by:
        performPaginationListRequestWithCursor in interface PaginationService
        Parameters:
        initialRequest - - a request for a range of data
        fetchBatch - - the function to supply the results. Results should be sorted in order which match cursor fields ordering.
        modelConverter - - a function to convert from the supplied object to a model object, this will be executed within a transaction.
        cursorCalculator - - a function to calculate next cursor.
        Returns:
        a PageResponseWithCursor of model objects, with results that the user is allowed to see.
      • newPagingIterator

        public <F,​T> PagingIterator<T> newPagingIterator​(PaginationBatch<F> fetchBatch,
                                                               int resultsPerPage,
                                                               Function<Iterable<F>,​Iterable<T>> modelConverter)
        Description copied from interface: PaginationServiceInternal
        Constructs a PagingIterator backed by the given PaginationBatch. The Iterator is guaranteed to yield all results provided by the PaginationBatch. No more than resultsPerPage are fetched from the PaginationBatch at one time, and each batch of data is only kept live for the time it takes callers to iterate through it.
        Specified by:
        newPagingIterator in interface PaginationServiceInternal
        Parameters:
        fetchBatch - - a request for a range of data
        resultsPerPage - - number of results to request from PaginationBatch each invocation.
        modelConverter - - a function to convert from the supplied object to a model object, this will be executed within a transaction.
        Returns:
        a PagingIterator of model objects, with results that the user is allowed to see.
        See Also:
        PagingIterator
      • newPaginated

        public <F,​T> Paginated<T> newPaginated​(PaginationBatch<F> fetchBatch,
                                                     Function<Iterable<F>,​Iterable<T>> modelConverter,
                                                     int maxLimit)
        Description copied from interface: PaginationServiceInternal
        Constructs a Paginated implementation backed by the given PaginationBatch.
        Specified by:
        newPaginated in interface PaginationServiceInternal
        Parameters:
        fetchBatch - - a request for a range of data
        modelConverter - - a function to convert from the supplied object to a model object, this will be executed within a transaction.
        maxLimit - - the max limit to apply when creating LimitedRequests for paged requests from the Paginated.
        See Also:
        Paginated