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
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.LifecycleManagementinstead.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceSpecialization of theRepositoryinterface that must be implemented by all implementations of theRepository. -
Method Summary
Modifier and TypeMethodDescriptionThe type of entity stored in this repository.idType()The type of the identifier used to identify entities in this repository.load(ID identifier, ProcessingContext processingContext) Load the entity with the given unique identifier.loadOrCreate(ID identifier, ProcessingContext processingContext) Loads an entity from the repository, constructing a new instance when none exists yet.persist(ID identifier, E entity, ProcessingContext processingContext) Persists the givenentityin this repositoryMethods inherited from interface org.axonframework.common.infra.DescribableComponent
describeTo
-
Method Details
-
entityType
The type of entity stored in this repository.- Returns:
- The type of entity stored in this repository.
-
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
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
CompletableFuturealways resolves to aManagedEntityfor the givenidentifier. Theentitymanaged by it may benullwhen 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 loadprocessingContext- the processing context in which to manage the lifecycle of the entity- Returns:
- a
CompletableFutureresolving to theManagedEntitywith 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
CompletableFuturealways resolves to aManagedEntityfor the givenidentifier. Theentitymanaged by it may benullwhen 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 loadprocessingContext- the processing context in which to manage the lifecycle of the entity- Returns:
- a
CompletableFutureresolving to theManagedEntitywith the given identifier, backed by a newly constructed entity instance when none existed yet
-
persist
Persists the givenentityin this repository- Parameters:
identifier- The identifier of the entity.entity- The current state of the entity to store.processingContext- TheProcessingContextin which the entity is active.- Returns:
- a
ManagedEntitywrapping the entity managed in theProcessingContext.
-