Interface StateManager
- All Superinterfaces:
DescribableComponent
- All Known Implementing Classes:
HierarchicalStateManager,SimpleStateManager,TracingStateManager
StateManager enables applications to load entities based on the type of the entity and an id, and to
persist them. Implementations may specify whether they load entities through
Repository.load(Object, ProcessingContext) or Repository.loadOrCreate(Object, ProcessingContext).
Entities are registered by their type in combination with their id. The combination of
entity type and id type of all repositories must be
unique and unambiguous. This means you cannot register a repository if another conflicting repository already exists.
If you do, a RepositoryAlreadyRegisteredException will be thrown. Note that superclasses and subclasses of
each other are considered conflicting.
- Since:
- 5.0.0
- Author:
- Mitchell Herrijgers
-
Method Summary
Modifier and TypeMethodDescriptiondefault <I,T> CompletableFuture <@Nullable T> loadEntity(Class<T> type, I id, ProcessingContext context) Retrieves an entity of the giventypeandid.<ID,T> CompletableFuture <ManagedEntity<ID, T>> loadManagedEntity(Class<T> type, ID id, ProcessingContext context) default <ID,T> StateManager register(Class<ID> idType, Class<T> entityType, SimpleRepositoryEntityLoader<ID, T> loader, SimpleRepositoryEntityPersister<ID, T> persister) Registers a load and save function for state typeTwith id of typeID.<ID,T> StateManager register(Repository<ID, T> repository) Registers anRepositoryfor use with thisStateManager.The types of entities that are registered with thisStateManager.registeredIdsFor(Class<?> entityType) The types of identifiers that are registered with thisStateManagerfor the givenentityType.<ID,T> @Nullable Repository <ID, T> repository(Class<T> entityType, Class<ID> idType) Returns theRepositoryfor the giventype.Methods inherited from interface org.axonframework.common.infra.DescribableComponent
describeTo
-
Method Details
-
register
Registers anRepositoryfor use with thisStateManager. The combination ofRepository.entityType()andRepository.idType()must be unique for all registered repositories.- Type Parameters:
ID- the type of idT- the type of the entity- Parameters:
repository- theRepositoryto use for loading state- Returns:
- this
StateManagerfor fluent interfacing - Throws:
RepositoryAlreadyRegisteredException- if a repository with the same entity type and id type is already registered
-
register
default <ID,T> StateManager register(Class<ID> idType, Class<T> entityType, SimpleRepositoryEntityLoader<ID, T> loader, SimpleRepositoryEntityPersister<ID, T> persister) Registers a load and save function for state typeTwith id of typeID. Creates aSimpleRepositoryfor the given type with the given load and save functions.- Type Parameters:
ID- the type of idT- the type of state- Parameters:
idType- the type of the identifierentityType- the type of the stateloader- the function to load statepersister- the function to persist state- Returns:
- this
StateManagerfor fluent interfacing - Throws:
RepositoryAlreadyRegisteredException- if a repository with the same entity type and id type is already registered
-
loadEntity
default <I,T> CompletableFuture<@Nullable T> loadEntity(Class<T> type, I id, ProcessingContext context) Retrieves an entity of the giventypeandid. TheCompletableFuturewill resolve to the entity, or complete exceptionally if it could not be resolved.If multiple repositories are registered for the given
entityTypethat can handle the givenid(through superclass registration), the most specific repository is used.- Type Parameters:
I- the type of the identifier of the entityT- the type of state to retrieve- Parameters:
type- the type of state to retrieveid- the id of the state to retrievecontext- thecontextto load the entity in- Returns:
- a
CompletableFuturewhich resolves to the entity instance, or completes exceptionally with aMissingRepositoryExceptionwhen thisStateManagerdoes not control theRepositoryto load the entity from
-
loadManagedEntity
<ID,T> CompletableFuture<ManagedEntity<ID,T>> loadManagedEntity(Class<T> type, ID id, ProcessingContext context) Retrieves aManagedEntityof the giventypeandid. TheCompletableFuturewill resolve to aManagedEntity, or complete exceptionally if it could not be resolved.- Type Parameters:
ID- the type of the identifier of the entityT- the type of the entity- Parameters:
type- the type of state to retrieveid- the id of the state to retrievecontext- thecontextto load the entity in- Returns:
- a
CompletableFuturewhich resolves to the entity instance, or completes exceptionally with aMissingRepositoryExceptionwhen thisStateManagerdoes not control theRepositoryto load theManagedEntityfrom
-
registeredEntities
The types of entities that are registered with thisStateManager.- Returns:
- the types of entities that are registered with this
StateManager
-
registeredIdsFor
The types of identifiers that are registered with thisStateManagerfor the givenentityType.- Parameters:
entityType- the type of the entity- Returns:
- the types of identifiers that are registered with this
StateManagerfor the givenentityType
-
repository
Returns theRepositoryfor the giventype.Returns
nullif no repository is registered for the given type and id.Unlike
loadManagedEntity(Class, Object, ProcessingContext), which resolves aRepositoryregistered for a supertype when asked for a subtype, this method only matches an exactly registered(entityType, idType)pair. Hence, there is no supertype or subtype resolution.- Type Parameters:
ID- the type of the identifier of the entityT- the type of the entity- Parameters:
entityType- the type of the entityidType- the type of the identifier of the entity- Returns:
- the
Repositoryfor the givenidTypeandentityType
-