Class EventSourcingRepository<ID,E>
- Type Parameters:
ID- The type of identifier used to identify the event sourced entity.E- The type of the event sourced entity to load.
- All Implemented Interfaces:
DescribableComponent,Repository<ID,,E> Repository.LifecycleManagement<ID,E>
Repository implementation that loads entities based on their historic event streams, provided by an
EventStore.- Since:
- 0.1
- Author:
- Allard Buijze, Steven van Beelen
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.axonframework.modelling.repository.Repository
Repository.LifecycleManagement<ID,E> -
Constructor Summary
ConstructorsConstructorDescriptionEventSourcingRepository(Class<ID> idType, Class<E> entityType, EventStore eventStore, EventSourcedEntityFactory<ID, E> entityFactory, CriteriaResolver<ID> criteriaResolver, EntityEvolver<E> entityEvolver) Initialize the repository to load events from the giveneventStoreusing the givenapplierto apply state transitions to the entity based on the events received, and givencriteriaResolverto resolve theEventCriteriaof the given identifier type used to source an entity. -
Method Summary
Modifier and TypeMethodDescriptionattach(ManagedEntity<ID, E> entity, ProcessingContext processingContext) Ensures that the givenentityhas its lifecycle managed in the givenprocessingContext.voiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.The type of entity stored in this repository.idType()The type of the identifier used to identify entities in this repository.load(ID identifier, ProcessingContext context) Load the entity with the given unique identifier.loadOrCreate(ID identifier, ProcessingContext context) Loads an entity from the repository.persist(ID identifier, E entity, ProcessingContext processingContext) Persists the givenentityin this repository
-
Constructor Details
-
EventSourcingRepository
public EventSourcingRepository(@Nonnull Class<ID> idType, @Nonnull Class<E> entityType, @Nonnull EventStore eventStore, @Nonnull EventSourcedEntityFactory<ID, E> entityFactory, @Nonnull CriteriaResolver<ID> criteriaResolver, @Nonnull EntityEvolver<E> entityEvolver) Initialize the repository to load events from the giveneventStoreusing the givenapplierto apply state transitions to the entity based on the events received, and givencriteriaResolverto resolve theEventCriteriaof the given identifier type used to source an entity.- Parameters:
idType- The type of the identifier for the event sourced entity this repository serves.entityType- The type of the event sourced entity this repository serves.eventStore- The event store to load events from.entityFactory- A factory method to create new instances of the entity based on the entity's type and a provided identifier.criteriaResolver- Converts the given identifier to anEventCriteriaused to load a matching event stream.entityEvolver- The function used to evolve the state of loaded entities based on events.
-
-
Method Details
-
attach
public ManagedEntity<ID,E> attach(@Nonnull ManagedEntity<ID, E> entity, @Nonnull ProcessingContext processingContext) Description copied from interface:Repository.LifecycleManagementEnsures that the givenentityhas its lifecycle managed in the givenprocessingContext. This ensures that when theprocessingContextcommits, any changes detected in the entity state are persisted in this repository's underlying storage, if present.If a managed entity for this identifier was already present in the
ProcessingContext, the new instance will replace it.Repositories may wrap entities. In that case, the returned instance may not be exactly the same (`==` comparison) as the instance provided. It is always recommended to use the returned instance.
- Specified by:
attachin interfaceRepository.LifecycleManagement<ID,E> - Parameters:
entity- The entity to have its lifecycle attached to the given processing context.processingContext- The processing context to link the lifecycle with.- Returns:
- The instance of the entity whose lifecycle is managed by this repository.
-
entityType
Description copied from interface:RepositoryThe type of entity stored in this repository.- Specified by:
entityTypein interfaceRepository<ID,E> - Returns:
- The type of entity stored in this repository.
-
idType
Description copied from interface:RepositoryThe type of the identifier used to identify entities in this repository.- Specified by:
idTypein interfaceRepository<ID,E> - Returns:
- The type of the identifier used to identify entities in this repository.
-
load
public CompletableFuture<ManagedEntity<ID,E>> load(@Nonnull ID identifier, @Nonnull ProcessingContext context) Description copied from interface:RepositoryLoad 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.- Specified by:
loadin interfaceRepository<ID,E> - Parameters:
identifier- The identifier of the entity to load.context- The processing context in which to manage the lifecycle of the entity.- Returns:
- A
CompletableFutureresolving to theManagedEntitywith the given identifier, ornullif it can't be found.
-
loadOrCreate
public CompletableFuture<ManagedEntity<ID,E>> loadOrCreate(@Nonnull ID identifier, @Nonnull ProcessingContext context) Description copied from interface:RepositoryLoads an entity from the repository.- Specified by:
loadOrCreatein interfaceRepository<ID,E> - Parameters:
identifier- The identifier of the entity to load.context- The processing context in which to manage the lifecycle of the entity.- Returns:
- A
CompletableFutureresolving to theManagedEntitywith the given identifier, or a newly constructed entity instance based on thefactoryMethod.
-
persist
public ManagedEntity<ID,E> persist(@Nonnull ID identifier, @Nonnull E entity, @Nonnull ProcessingContext processingContext) Description copied from interface:RepositoryPersists the givenentityin this repository- Specified by:
persistin interfaceRepository<ID,E> - 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.
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.Best Practices: As a general rule, all relevant fields of a
DescribableComponentimplementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing thedescribeTomethod, who should focus on providing information that is useful for understanding the component's configuration and state.Example implementation:
public void describeTo(ComponentDescriptor descriptor) { descriptor.describeProperty("name", this.name); descriptor.describeProperty("enabled", this.enabled); descriptor.describeProperty("configuration", this.configuration); // A nested component descriptor.describeProperty("handlers", this.eventHandlers); // A collection }- Specified by:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-