DTO - public abstract class PaginatedDbService<DTO> extends Object
It makes only a few assumptions, which are common to many Graylog entities:
Subclasses can add more sophisticated query methods by access the protected "db" property.
Indices can be added in the constructor.
| Modifier and Type | Field and Description |
|---|---|
protected org.mongojack.JacksonDBCollection<DTO,org.bson.types.ObjectId> |
db |
| Modifier | Constructor and Description |
|---|---|
protected |
PaginatedDbService(MongoConnection mongoConnection,
MongoJackObjectMapperProvider mapper,
Class<DTO> dtoClass,
String collectionName) |
protected |
PaginatedDbService(MongoConnection mongoConnection,
MongoJackObjectMapperProvider mapper,
Class<DTO> dtoClass,
String collectionName,
Class<?> view) |
| Modifier and Type | Method and Description |
|---|---|
protected com.google.common.collect.ImmutableList<DTO> |
asImmutableList(Iterator<? extends DTO> cursor) |
int |
delete(String id)
Deletes the
DTO for the given ID from the database. |
protected PaginatedList<DTO> |
findPaginatedWithQueryAndSort(org.mongojack.DBQuery.Query query,
org.mongojack.DBSort.SortBuilder sort,
int page,
int perPage)
Returns a
PaginatedList for the given query and pagination parameters. |
protected PaginatedList<DTO> |
findPaginatedWithQueryFilterAndSort(org.mongojack.DBQuery.Query query,
Predicate<DTO> filter,
org.mongojack.DBSort.SortBuilder sort,
int page,
int perPage)
Returns a
PaginatedList for the given query, filter and pagination parameters. |
Optional<DTO> |
get(String id)
Get the
DTO for the given ID. |
protected org.mongojack.DBSort.SortBuilder |
getSortBuilder(String order,
String field)
Returns a sort builder for the given order and field name.
|
DTO |
save(DTO dto)
Stores the given
DTO in the database. |
Stream<DTO> |
streamAll()
Returns an unordered stream of all entries in the database.
|
Stream<DTO> |
streamByIds(Set<String> idSet)
Returns an unordered stream of all entries in the database for the given IDs.
|
protected Stream<DTO> |
streamQuery(org.mongojack.DBQuery.Query query)
Returns an unordered stream of database entries for the given
DBQuery.Query. |
protected Stream<DTO> |
streamQueryWithSort(org.mongojack.DBQuery.Query query,
org.mongojack.DBSort.SortBuilder sort)
Returns a stream of database entries for the given
DBQuery.Query sorted by the give DBSort.SortBuilder. |
protected final org.mongojack.JacksonDBCollection<DTO,org.bson.types.ObjectId> db
protected PaginatedDbService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper, Class<DTO> dtoClass, String collectionName)
protected PaginatedDbService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper, Class<DTO> dtoClass, String collectionName, Class<?> view)
public Optional<DTO> get(String id)
DTO for the given ID.id - the ID of the objectpublic DTO save(DTO dto)
DTO in the database.dto - the DTO to saveDTOpublic int delete(String id)
DTO for the given ID from the database.id - ID of the DTO to deleteprotected PaginatedList<DTO> findPaginatedWithQueryAndSort(org.mongojack.DBQuery.Query query, org.mongojack.DBSort.SortBuilder sort, int page, int perPage)
PaginatedList for the given query and pagination parameters.
This method is only accessible by subclasses to avoid exposure of the DBQuery and DBSort
interfaces to consumers.
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 unlimitedprotected com.google.common.collect.ImmutableList<DTO> asImmutableList(Iterator<? extends DTO> cursor)
protected PaginatedList<DTO> findPaginatedWithQueryFilterAndSort(org.mongojack.DBQuery.Query query, Predicate<DTO> filter, org.mongojack.DBSort.SortBuilder sort, int page, int perPage)
PaginatedList 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 DBQuery and DBSort
interfaces to consumers.
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 unlimitedpublic Stream<DTO> streamAll()
The returned stream needs to be closed to free the underlying database resources.
public Stream<DTO> streamByIds(Set<String> idSet)
The returned stream needs to be closed to free the underlying database resources.
idSet - set of IDs to queryprotected Stream<DTO> streamQuery(org.mongojack.DBQuery.Query query)
DBQuery.Query.
The returned stream needs to be closed to free the underlying database resources.
query - the query to executeprotected Stream<DTO> streamQueryWithSort(org.mongojack.DBQuery.Query query, org.mongojack.DBSort.SortBuilder sort)
DBQuery.Query sorted by the give DBSort.SortBuilder.
The returned stream needs to be closed to free the underlying database resources.
query - the query to executesort - the sort order for the queryCopyright © 2012–2021 Graylog, Inc.. All rights reserved.