Class DefaultMongoPaginationHelper<T extends MongoEntity>

java.lang.Object
org.graylog2.database.pagination.DefaultMongoPaginationHelper<T>
Type Parameters:
T - Type of documents in the underlying MongoDB collection.
All Implemented Interfaces:
MongoPaginationHelper<T>

public class DefaultMongoPaginationHelper<T extends MongoEntity> extends Object implements MongoPaginationHelper<T>
Default implementation for pagination support.

Objects of this class are immutable and can be re-used.

  • Constructor Details

    • DefaultMongoPaginationHelper

      public DefaultMongoPaginationHelper(com.mongodb.client.MongoCollection<T> collection)
  • Method Details

    • filter

      public MongoPaginationHelper<T> filter(org.bson.conversions.Bson filter)
      Description copied from interface: MongoPaginationHelper
      Sets the query filter to apply to the query.
      Specified by:
      filter in interface MongoPaginationHelper<T extends MongoEntity>
      Parameters:
      filter - the filter, which may be null.
      Returns:
      A new pagination helper with the setting applied
    • sort

      public MongoPaginationHelper<T> sort(org.bson.conversions.Bson sort)
      Description copied from interface: MongoPaginationHelper
      Sets the sort criteria to apply to the query.
      Specified by:
      sort in interface MongoPaginationHelper<T extends MongoEntity>
      Parameters:
      sort - the sort criteria, which may be null.
      Returns:
      A new pagination helper with the setting applied
    • projection

      public MongoPaginationHelper<T> projection(org.bson.conversions.Bson projection)
      Description copied from interface: MongoPaginationHelper
      Sets the projection BSON to apply to the query. It will limit the number of fields retrieved from MongoDB for each document. Keep in mind that you can only exclude fields that are optional in related MongoEntity and you are responsible for ensuring that excluded fields are not needed in your use case.
      Specified by:
      projection in interface MongoPaginationHelper<T extends MongoEntity>
      Parameters:
      projection - the projection BSON, which may be null.
      Returns:
      A new pagination helper with the setting applied
    • perPage

      public MongoPaginationHelper<T> perPage(int perPage)
      Description copied from interface: MongoPaginationHelper
      Sets the page size.
      Specified by:
      perPage in interface MongoPaginationHelper<T extends MongoEntity>
      Parameters:
      perPage - the number of documents to put on one page
      Returns:
      A new pagination helper with the setting applied
    • includeGrandTotal

      public MongoPaginationHelper<T> includeGrandTotal(boolean includeGrandTotal)
      Description copied from interface: MongoPaginationHelper
      Specifies whether to include a grand total number of all documents in the collection. No filters, except, if set, the MongoPaginationHelper.grandTotalFilter(Bson) will be applied to the count query.
      Specified by:
      includeGrandTotal in interface MongoPaginationHelper<T extends MongoEntity>
      Parameters:
      includeGrandTotal - true if a grand total should be included. Otherwise, by default, no grand total will be included.
      Returns:
      A new pagination helper with the setting applied
    • grandTotalFilter

      public MongoPaginationHelper<T> grandTotalFilter(org.bson.conversions.Bson grandTotalFilter)
      Description copied from interface: MongoPaginationHelper
      Sets a filter to be applied to the query to count the grand total of documents in the collection.
      Specified by:
      grandTotalFilter in interface MongoPaginationHelper<T extends MongoEntity>
      Parameters:
      grandTotalFilter - the filter, which may be null
      Returns:
      A new pagination helper with the setting applied
    • collation

      public MongoPaginationHelper<T> collation(com.mongodb.client.model.Collation collation)
      Description copied from interface: MongoPaginationHelper
      Sets a collation to be used in the find operation.
      Specified by:
      collation in interface MongoPaginationHelper<T extends MongoEntity>
      Parameters:
      collation - The collation to set. If null, uses the default server collation
      Returns:
      A new pagination helper with the setting applied
    • page

      public PaginatedList<T> page(int pageNumber)
      Description copied from interface: MongoPaginationHelper
      Perform the MongoDB request and return the specified page.
      Specified by:
      page in interface MongoPaginationHelper<T extends MongoEntity>
      Parameters:
      pageNumber - The number of the page to be returned.
      Returns:
      a paginated list of documents
    • page

      public PaginatedList<T> page(int pageNumber, Predicate<T> selector)
      Description copied from interface: MongoPaginationHelper
      Perform the MongoDB request but apply the given predicate to each document in the list of results and only keep documents matching the predicate.

      This is a potentially expensive operation because the selector can only be applied after the documents have been fetched from MongoDB and this might result in a full collection scan. Use with care!

      Specified by:
      page in interface MongoPaginationHelper<T extends MongoEntity>
      Parameters:
      pageNumber - The number of the page to be returned.
      selector - predicate to filter documents after fetching them from MongoDB.
      Returns:
      a paginated list of documents