Interface Repository<ID,E>

Type Parameters:
ID - The type of identifier for entities in this repository.
E - The type of entity this repository stores.
All Superinterfaces:
DescribableComponent
All Known Subinterfaces:
Repository.LifecycleManagement<ID,E>
All Known Implementing Classes:
EventSourcingRepository, InMemoryRepository, SimpleRepository, TracingRepository

public sealed interface Repository<ID,E> extends DescribableComponent permits Repository.LifecycleManagement<ID,E>
The Repository provides an abstraction for the storage of entities.

When interacting with the Repository the framework expects an active ProcessingContext. If there is no active UnitOfWork an IllegalStateException is thrown.

Since:
0.1
Author:
Allard Buijze
Implementation Note:
Implementations of this interface must implement Repository.LifecycleManagement instead.
  • Method Details

    • entityType

      Class<E> entityType()
      The type of entity stored in this repository.
      Returns:
      The type of entity stored in this repository.
    • idType

      Class<ID> idType()
      The type of the identifier used to identify entities in this repository.
      Returns:
      The type of the identifier used to identify entities in this repository.
    • load

      CompletableFuture<ManagedEntity<ID,E>> load(ID identifier, ProcessingContext processingContext)
      Load the entity with the given unique identifier. No version checks are done when loading an entity, meaning that concurrent access will not be checked for.

      The returned CompletableFuture always resolves to a ManagedEntity for the given identifier. The entity managed by it may be null when none could be found. Implementations without an autonomous construction step (e.g. one driven entirely by a user-supplied loader) remain free to let the future complete exceptionally instead, if that loader does so.

      Parameters:
      identifier - the identifier of the entity to load
      processingContext - the processing context in which to manage the lifecycle of the entity
      Returns:
      a CompletableFuture resolving to the ManagedEntity with the given identifier
    • loadOrCreate

      CompletableFuture<ManagedEntity<ID,E>> loadOrCreate(ID identifier, ProcessingContext processingContext)
      Loads an entity from the repository, constructing a new instance when none exists yet.

      The returned CompletableFuture always resolves to a ManagedEntity for the given identifier. The entity managed by it may be null when none could be found. Implementations without an autonomous construction step (e.g. one driven entirely by a user-supplied loader) remain free to let the future complete exceptionally instead, if that loader does so.

      Parameters:
      identifier - the identifier of the entity to load
      processingContext - the processing context in which to manage the lifecycle of the entity
      Returns:
      a CompletableFuture resolving to the ManagedEntity with the given identifier, backed by a newly constructed entity instance when none existed yet
    • persist

      ManagedEntity<ID,E> persist(ID identifier, E entity, ProcessingContext processingContext)
      Persists the given entity in this repository
      Parameters:
      identifier - The identifier of the entity.
      entity - The current state of the entity to store.
      processingContext - The ProcessingContext in which the entity is active.
      Returns:
      a ManagedEntity wrapping the entity managed in the ProcessingContext.