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:
AccessSerializingRepository, EventSourcingRepository, InMemoryRepository, SimpleRepository

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
  • Method Details

    • entityType

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

      @Nonnull 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(@Nonnull ID identifier, @Nonnull 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.
      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, or null if it can't be found.
    • loadOrCreate

      CompletableFuture<ManagedEntity<ID,E>> loadOrCreate(@Nonnull ID identifier, @Nonnull ProcessingContext processingContext)
      Loads an entity from the repository.
      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, or a newly constructed entity instance based on the factoryMethod.
    • persist

      ManagedEntity<ID,E> persist(@Nonnull ID identifier, @Nonnull E entity, @Nonnull 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.