Package org.graylog2.database.pagination
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 Summary
ConstructorsConstructorDescriptionDefaultMongoPaginationHelper(com.mongodb.client.MongoCollection<T> collection) -
Method Summary
Modifier and TypeMethodDescriptioncollation(com.mongodb.client.model.Collation collation) Sets a collation to be used in the find operation.filter(org.bson.conversions.Bson filter) Sets the query filter to apply to the query.grandTotalFilter(org.bson.conversions.Bson grandTotalFilter) Sets a filter to be applied to the query to count the grand total of documents in the collection.includeGrandTotal(boolean includeGrandTotal) Specifies whether to include a grand total number of all documents in the collection.page(int pageNumber) Perform the MongoDB request and return the specified page.Perform the MongoDB request but apply the given predicate to each document in the list of results and only keep documents matching the predicate.perPage(int perPage) Sets the page size.projection(org.bson.conversions.Bson projection) Sets the projection BSON to apply to the query.sort(org.bson.conversions.Bson sort) Sets the sort criteria to apply to the query.
-
Constructor Details
-
DefaultMongoPaginationHelper
-
-
Method Details
-
filter
Description copied from interface:MongoPaginationHelperSets the query filter to apply to the query.- Specified by:
filterin interfaceMongoPaginationHelper<T extends MongoEntity>- Parameters:
filter- the filter, which may be null.- Returns:
- A new pagination helper with the setting applied
-
sort
Description copied from interface:MongoPaginationHelperSets the sort criteria to apply to the query.- Specified by:
sortin interfaceMongoPaginationHelper<T extends MongoEntity>- Parameters:
sort- the sort criteria, which may be null.- Returns:
- A new pagination helper with the setting applied
-
projection
Description copied from interface:MongoPaginationHelperSets 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:
projectionin interfaceMongoPaginationHelper<T extends MongoEntity>- Parameters:
projection- the projection BSON, which may be null.- Returns:
- A new pagination helper with the setting applied
-
perPage
Description copied from interface:MongoPaginationHelperSets the page size.- Specified by:
perPagein interfaceMongoPaginationHelper<T extends MongoEntity>- Parameters:
perPage- the number of documents to put on one page- Returns:
- A new pagination helper with the setting applied
-
includeGrandTotal
Description copied from interface:MongoPaginationHelperSpecifies whether to include a grand total number of all documents in the collection. No filters, except, if set, theMongoPaginationHelper.grandTotalFilter(Bson)will be applied to the count query.- Specified by:
includeGrandTotalin interfaceMongoPaginationHelper<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
Description copied from interface:MongoPaginationHelperSets a filter to be applied to the query to count the grand total of documents in the collection.- Specified by:
grandTotalFilterin interfaceMongoPaginationHelper<T extends MongoEntity>- Parameters:
grandTotalFilter- the filter, which may be null- Returns:
- A new pagination helper with the setting applied
-
collation
Description copied from interface:MongoPaginationHelperSets a collation to be used in the find operation.- Specified by:
collationin interfaceMongoPaginationHelper<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
Description copied from interface:MongoPaginationHelperPerform the MongoDB request and return the specified page.- Specified by:
pagein interfaceMongoPaginationHelper<T extends MongoEntity>- Parameters:
pageNumber- The number of the page to be returned.- Returns:
- a paginated list of documents
-
page
Description copied from interface:MongoPaginationHelperPerform 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:
pagein interfaceMongoPaginationHelper<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
-