Interface FeedEntityRepository
-
public interface FeedEntityRepository
Repository to store feed entities and what page they are assigned to.Entities are uniquely identified by their
ContentId
. Different methods alternatively take and return either full entities (Entity
) or a subset of header fields (FeedEntityRepository.PageAssignment
). All these methods act on the same data, they just provide different views onto the same records, to avoid having to load full entity bodies when they're not needed. The fields that need to be stored in this repository is the union of all fields in both classes. See the documentation forFeedEntityRepository.PageAssignment
on how to match the fields.As an exception to the rule above, the following fields don't need to be accurately saved:
FeedEntityHeader.extraHeaders()
may be ignored if you don't intend to use itEntity.userData()
explicitly does not have any meaning ascribed to it by the library; consequently, it is entirely up to the repository implementation how to handle this field
Consistency Requirements
This repository must fulfillthe common requirements for all feed producer repositories
.All write operations must be atomic for an individual entity, i.e. it must never be possible to observe a partially-written entity
Ordering
Any returned lists of entities must be sorted in the following way:- by their last-modified timestamp (
FeedEntityRepository.PageAssignment.lastModified()
), oldest to newest - any entities with the same timestamp must be sorted using their content ID as a tie breaker
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
FeedEntityRepository.PageAssignment
A subset of this repository's fields that are sufficient for operations that don't need the entity body.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description @NonNull java.util.concurrent.CompletionStage<java.lang.Void>
append(@NonNull Entity<@NonNull FeedEntityHeader> entity)
Add an entity to the repository.@NonNull java.util.concurrent.CompletionStage<@NonNull java.util.List<@NonNull Entity<@NonNull FeedEntityHeader>>>
get(@NonNull PageId pageId)
Load all entities whoseFeedEntityRepository.PageAssignment.pageId()
field is set to the given page.@NonNull java.util.concurrent.CompletionStage<@NonNull java.util.List<@NonNull FeedEntityRepository.PageAssignment>>
getPageAssignments(@NonNull PageId pageId)
Load all entities whoseFeedEntityRepository.PageAssignment.pageId()
field is set to the given page.@NonNull java.util.concurrent.CompletionStage<@NonNull java.util.List<@NonNull FeedEntityRepository.PageAssignment>>
getUnassigned(int limit)
Load all entities whoseFeedEntityRepository.PageAssignment.pageId()
field is empty.@NonNull java.util.concurrent.CompletionStage<java.lang.Void>
savePageAssignments(@NonNull java.util.List<@NonNull FeedEntityRepository.PageAssignment> pageAssignments)
Update the given entities.
-
-
-
Method Detail
-
append
@NonNull @NonNull java.util.concurrent.CompletionStage<java.lang.Void> append(@NonNull @NonNull Entity<@NonNull FeedEntityHeader> entity)
Add an entity to the repository. Once an entity has been saved successfully, this method won't be called again with the same content ID.The
Entity
object does not contain all fields that need to be saved in the repository. SeeFeedEntityRepository.PageAssignment
for the expected default values for any fields missing from the entity.- Parameters:
entity
- the entity to save- Returns:
- CompletionStage
-
get
@NonNull @NonNull java.util.concurrent.CompletionStage<@NonNull java.util.List<@NonNull Entity<@NonNull FeedEntityHeader>>> get(@NonNull @NonNull PageId pageId)
Load all entities whoseFeedEntityRepository.PageAssignment.pageId()
field is set to the given page.All fields necessary to create the
Entity
must be loaded, including the body. The returned list must be sorted by the entities' timestamps as described in the class documentation.- Parameters:
pageId
- the page ID to load- Returns:
- CompletionStage of all entities assigned to the given page
-
getUnassigned
@NonNull @NonNull java.util.concurrent.CompletionStage<@NonNull java.util.List<@NonNull FeedEntityRepository.PageAssignment>> getUnassigned(int limit)
Load all entities whoseFeedEntityRepository.PageAssignment.pageId()
field is empty.The returned list must be sorted by the entities' timestamps as described in the class documentation. Note that the limit must take place after sorting, i.e. logically the list of all available records is sorted and then the first
limit
elements from the sorted list are returned.- Parameters:
limit
- the maximum number of records to load- Returns:
- CompletionStage of all entities not assigned to a page
-
getPageAssignments
@NonNull @NonNull java.util.concurrent.CompletionStage<@NonNull java.util.List<@NonNull FeedEntityRepository.PageAssignment>> getPageAssignments(@NonNull @NonNull PageId pageId)
Load all entities whoseFeedEntityRepository.PageAssignment.pageId()
field is set to the given page.The returned list must be sorted by the entities' timestamps as described in the class documentation.
- Parameters:
pageId
- the page ID to load- Returns:
- CompletionStage of all entities assigned to the given page
-
savePageAssignments
@NonNull @NonNull java.util.concurrent.CompletionStage<java.lang.Void> savePageAssignments(@NonNull @NonNull java.util.List<@NonNull FeedEntityRepository.PageAssignment> pageAssignments)
Update the given entities.This method will only ever update existing entities, i.e. all content IDs in the list are guaranteed to exist in the repository.
- Parameters:
pageAssignments
- a list of updates to save to the repository- Returns:
- CompletionStage
-
-