Package org.axonframework.modelling
Interface StateManager
- All Known Implementing Classes:
HierarchicalStateManager,SimpleStateManager
public interface StateManager
The
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 <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> Repository <ID, T> repository(Class<T> entityType, Class<ID> idType) Returns theRepositoryfor the giventype.
-
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 id.T- 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(@Nonnull Class<ID> idType, @Nonnull Class<T> entityType, @Nonnull SimpleRepositoryEntityLoader<ID, T> loader, @Nonnull 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 id.T- The type of state.- Parameters:
idType- The type of the identifier.entityType- The type of the state.loader- The function to load state.persister- 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
@Nonnull default <I,T> CompletableFuture<T> loadEntity(@Nonnull Class<T> type, @Nonnull I id, @Nonnull 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 entity.T- The type of state to retrieve.- Parameters:
type- The type of state to retrieve.id- The id of the state to retrieve.context- Thecontextto load the entity in.- Returns:
- a
CompletableFuturewhich resolves to the entity instance.
-
loadManagedEntity
<ID,T> CompletableFuture<ManagedEntity<ID,T>> loadManagedEntity(@Nonnull Class<T> type, @Nonnull ID id, @Nonnull 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 entity.T- The type of the entity.- Parameters:
type- The type of state to retrieve.id- The id of the state to retrieve.context- Thecontextto load the entity in.- Returns:
- a
CompletableFuturewhich resolves to the entity instance.
-
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. Returnsnullif no repository is registered for the given type and id.- Type Parameters:
ID- The type of the identifier of the entity.T- The type of the entity.- Parameters:
entityType- The type of the entity.idType- The type of the identifier of the entity.- Returns:
- The
Repositoryfor the givenidTypeandentityType.
-