Class PaginatedDbService<DTO>
- Type Parameters:
DTO-
- Direct Known Subclasses:
CollectorService,ConfigurationService,ConfigurationVariableService,DBAuthServiceBackendService,DBGrantService,DBJobDefinitionService,DBNotificationGracePeriodService,IndexFieldTypeProfileService,PaginatedAuthzRolesService,PaginatedGrokPatternService,PaginatedMongoDbPipelineService,PaginatedMongoDbRuleService,PaginatedStreamService,PaginatedUserService,SidecarService,ViewSummaryService
It makes only a few assumptions, which are common to many Graylog entities:
- The DTO class has a name which is unique
Subclasses can add more sophisticated query methods by access the protected "db" property.
Indices can be added in the constructor.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final JacksonDBCollection<DTO,org.bson.types.ObjectId> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPaginatedDbService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper, Class<DTO> dtoClass, String collectionName) protectedPaginatedDbService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper, Class<DTO> dtoClass, String collectionName, com.mongodb.DBObject dbOptions) -
Method Summary
Modifier and TypeMethodDescriptionprotected com.google.common.collect.ImmutableList<DTO>asImmutableList(Iterator<? extends DTO> cursor) intDeletes thePaginatedDbServicefor the given ID from the database.protected PaginatedList<DTO>findPaginatedWithQueryAndSort(org.bson.conversions.Bson query, org.bson.conversions.Bson sort, int page, int perPage) Returns aPaginatedList<DTO>for the given query and pagination parameters.protected PaginatedList<DTO>findPaginatedWithQueryFilterAndSort(org.bson.conversions.Bson query, Predicate<DTO> filter, org.bson.conversions.Bson sort, int page, int perPage) Returns aPaginatedList<DTO>for the given query, filter and pagination parameters.protected PaginatedList<DTO>findPaginatedWithQueryFilterAndSortWithGrandTotal(org.bson.conversions.Bson query, Predicate<DTO> filter, org.bson.conversions.Bson sort, org.bson.conversions.Bson grandTotalQuery, int page, int perPage) Get thePaginatedDbServicefor the given ID.protected org.mongojack.DBSort.SortBuildergetMultiFieldSortBuilder(String order, List<String> fields) Deprecated.static <T> List<T>Utility method to use, if you can't page it inside of MongoDBprotected org.mongojack.DBSort.SortBuildergetSortBuilder(String order, String field) Deprecated.DBSortis deprecated.Stores the givenPaginatedDbServicein the database.Returns an unordered stream of all entries in the database.streamByIds(Set<String> idSet) Returns an unordered stream of all entries in the database for the given IDs.streamQuery(org.bson.conversions.Bson query) Returns an unordered stream of database entries for the givenDBQuery.Query.streamQueryWithSort(org.bson.conversions.Bson query, org.bson.conversions.Bson sort) Returns a stream of database entries for the givenDBQuery.Querysorted by the giveDBSort.SortBuilder.
-
Field Details
-
db
-
-
Constructor Details
-
PaginatedDbService
protected PaginatedDbService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper, Class<DTO> dtoClass, String collectionName) -
PaginatedDbService
protected PaginatedDbService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper, Class<DTO> dtoClass, String collectionName, @Nullable com.mongodb.DBObject dbOptions)
-
-
Method Details
-
get
Get thePaginatedDbServicefor the given ID.- Parameters:
id- the ID of the object- Returns:
- an Optional containing the found object or an empty Optional if no object can be found for the given ID
-
save
Stores the givenPaginatedDbServicein the database.- Parameters:
dto- thePaginatedDbServiceto save- Returns:
- the newly saved
PaginatedDbService
-
delete
Deletes thePaginatedDbServicefor the given ID from the database.- Parameters:
id- ID of thePaginatedDbServiceto delete- Returns:
- the number of deleted documents
-
findPaginatedWithQueryAndSort
protected PaginatedList<DTO> findPaginatedWithQueryAndSort(org.bson.conversions.Bson query, org.bson.conversions.Bson sort, int page, int perPage) Returns aPaginatedList<DTO>for the given query and pagination parameters.This method is only accessible by subclasses to avoid exposure of the
DBQueryandDBSortinterfaces to consumers.- Parameters:
query- the query to executesort- the sort builder for the querypage- the page number that should be returnedperPage- the number of entries per page, 0 is unlimited- Returns:
- the paginated list
-
asImmutableList
-
findPaginatedWithQueryFilterAndSort
protected PaginatedList<DTO> findPaginatedWithQueryFilterAndSort(org.bson.conversions.Bson query, Predicate<DTO> filter, org.bson.conversions.Bson sort, int page, int perPage) Returns aPaginatedList<DTO>for the given query, filter and pagination parameters.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. This increases memory consumption and should only be used if necessary. Use the
#findPaginatedWithQueryAndSort()method if possible.This method is only accessible by subclasses to avoid exposure of the query and sort interfaces to consumers.
- Parameters:
query- the query to executefilter- the filter to apply to each database entrysort- the sort builder for the querypage- the page number that should be returnedperPage- the number of entries per page, 0 is unlimited- Returns:
- the paginated list
-
findPaginatedWithQueryFilterAndSortWithGrandTotal
protected PaginatedList<DTO> findPaginatedWithQueryFilterAndSortWithGrandTotal(org.bson.conversions.Bson query, Predicate<DTO> filter, org.bson.conversions.Bson sort, org.bson.conversions.Bson grandTotalQuery, int page, int perPage) -
streamAll
Returns an unordered stream of all entries in the database.The returned stream needs to be closed to free the underlying database resources.
- Returns:
- stream of all database entries
-
streamByIds
Returns an unordered stream of all entries in the database for the given IDs.The returned stream needs to be closed to free the underlying database resources.
- Parameters:
idSet- set of IDs to query- Returns:
- stream of database entries for the given IDs
-
streamQuery
Returns an unordered stream of database entries for the givenDBQuery.Query.The returned stream needs to be closed to free the underlying database resources.
- Parameters:
query- the query to execute- Returns:
- stream of database entries that match the query
-
streamQueryWithSort
protected Stream<DTO> streamQueryWithSort(org.bson.conversions.Bson query, org.bson.conversions.Bson sort) Returns a stream of database entries for the givenDBQuery.Querysorted by the giveDBSort.SortBuilder.The returned stream needs to be closed to free the underlying database resources.
- Parameters:
query- the query to executesort- the sort order for the query- Returns:
- stream of database entries that match the query
-
getSortBuilder
Deprecated.DBSortis deprecated. Consider usingSortsinstead.Returns a sort builder for the given order and field name.- Parameters:
order- the order. either "asc" or "desc"field- the field to sort on- Returns:
- the sort builder
-
getMultiFieldSortBuilder
protected org.mongojack.DBSort.SortBuilder getMultiFieldSortBuilder(String order, List<String> fields) Deprecated.DBSortis deprecated. Consider usingSortsinstead. -
getPage
Utility method to use, if you can't page it inside of MongoDB- Type Parameters:
T-- Parameters:
sourceList-page-pageSize-- Returns:
-
DBSortis deprecated.