T - The type of aggregate this repository storespublic class EventSourcingRepository<T> extends org.axonframework.modelling.command.LockingRepository<T,EventSourcedAggregate<T>>
EventBus and delegate event
storage to the provided EventStore.EventStore| Modifier and Type | Class and Description |
|---|---|
static class |
EventSourcingRepository.Builder<T>
Builder class to instantiate a
EventSourcingRepository. |
| Modifier | Constructor and Description |
|---|---|
protected |
EventSourcingRepository(EventSourcingRepository.Builder<T> builder)
Instantiate a
EventSourcingRepository based on the fields contained in the EventSourcingRepository.Builder. |
| Modifier and Type | Method and Description |
|---|---|
static <T> EventSourcingRepository.Builder<T> |
builder(Class<T> aggregateType)
Instantiate a Builder to be able to create a
EventSourcingRepository for aggregate type T. |
protected EventSourcedAggregate<T> |
doCreateNewForLock(Callable<T> factoryMethod) |
protected void |
doDeleteWithLock(EventSourcedAggregate<T> aggregate) |
protected EventSourcedAggregate<T> |
doLoadWithLock(String aggregateIdentifier,
Long expectedVersion)
Perform the actual loading of an aggregate.
|
protected void |
doSaveWithLock(EventSourcedAggregate<T> aggregate) |
AggregateFactory<T> |
getAggregateFactory()
Returns the factory used by this repository.
|
protected DomainEventStream |
readEvents(String aggregateIdentifier)
Reads the events for the given aggregateIdentifier from the eventStore. this method may be overridden to
add pre or postprocessing to the loading of an event stream
|
protected void |
reportIllegalState(org.axonframework.modelling.command.LockAwareAggregate<T,EventSourcedAggregate<T>> aggregate) |
protected void |
validateOnLoad(org.axonframework.modelling.command.Aggregate<T> aggregate,
Long expectedVersion) |
doCreateNew, doDelete, doLoad, doLoadOrCreate, doSave, prepareForCommitprotected EventSourcingRepository(EventSourcingRepository.Builder<T> builder)
EventSourcingRepository based on the fields contained in the EventSourcingRepository.Builder.
A goal of the provided Builder is to create an AggregateModel specifying generic T as the
aggregate type to be stored. All aggregates in this repository must be instanceOf this aggregate type. To
instantiate this AggregateModel, either an AggregateModel can be provided directly or an
aggregateType of type Class can be used. The latter will internally resolve to an AggregateModel.
Thus, either the AggregateModel or the aggregateType should be provided. An
AxonConfigurationException is thrown if these criteria are not met. The same
criteria holds for the AggregateFactory. Either the AggregateFactory can be set directly or it will be
instantiated internally based on the aggregateType. Hence, one of both is a hard requirement, and will
also result in an AxonConfigurationException if both are missing.
Additionally, the builder will assert that the LockFactory, EventStore and
SnapshotTriggerDefinition are not null, resulting in an AxonConfigurationException if for any of
these this is the case. The RepositorySpanFactory is defaulted to a
DefaultRepositorySpanFactory backed by a
NoOpSpanFactory.
builder - the EventSourcingRepository.Builder used to instantiate a EventSourcingRepository instancepublic static <T> EventSourcingRepository.Builder<T> builder(Class<T> aggregateType)
EventSourcingRepository for aggregate type T. Can
also be used to instantiate a CachingEventSourcingRepository for aggregate type T. This Builder
will check whether a Cache is provided. If this holds, the EventSourcingRepository.Builder.build() function returns a
CachingEventSourcingRepository instead of an EventSourcingRepository.
The LockFactory is defaulted to an PessimisticLockFactory and the
SnapshotTriggerDefinition to a NoSnapshotTriggerDefinition implementation. A goal of this Builder
goal is to create an AggregateModel specifying generic T as the aggregate type to be stored. All
aggregates in this repository must be instanceOf this aggregate type. To instantiate this AggregateModel,
either an AggregateModel can be provided directly or an aggregateType of type Class can
be used. The latter will internally resolve to an AggregateModel. Thus, either the AggregateModel or the
aggregateType should be provided. The same criteria holds for the AggregateFactory. Either the
AggregateFactory can be set directly or it will be instantiated internally based on the aggregateType.
Hence, one of both is a hard requirement.
Additionally, the EventStore is a hard requirement and as such should be provided.
EventSourcingRepositoryprotected EventSourcedAggregate<T> doLoadWithLock(String aggregateIdentifier, Long expectedVersion)
doLoadWithLock in class org.axonframework.modelling.command.LockingRepository<T,EventSourcedAggregate<T>>aggregateIdentifier - the identifier of the aggregate to loadexpectedVersion - The expected version of the loaded aggregateAggregateDeletedException - in case an aggregate existed in the past, but has been deletedorg.axonframework.modelling.command.AggregateNotFoundException - when an aggregate with the given identifier does not existprotected DomainEventStream readEvents(String aggregateIdentifier)
aggregateIdentifier - the identifier of the aggregate to loadeventStreamFilter applied if
one was configuredprotected void validateOnLoad(org.axonframework.modelling.command.Aggregate<T> aggregate, Long expectedVersion)
validateOnLoad in class org.axonframework.modelling.command.AbstractRepository<T,org.axonframework.modelling.command.LockAwareAggregate<T,EventSourcedAggregate<T>>>protected void reportIllegalState(org.axonframework.modelling.command.LockAwareAggregate<T,EventSourcedAggregate<T>> aggregate)
reportIllegalState in class org.axonframework.modelling.command.AbstractRepository<T,org.axonframework.modelling.command.LockAwareAggregate<T,EventSourcedAggregate<T>>>protected EventSourcedAggregate<T> doCreateNewForLock(Callable<T> factoryMethod) throws Exception
doCreateNewForLock in class org.axonframework.modelling.command.LockingRepository<T,EventSourcedAggregate<T>>Exceptionprotected void doSaveWithLock(EventSourcedAggregate<T> aggregate)
doSaveWithLock in class org.axonframework.modelling.command.LockingRepository<T,EventSourcedAggregate<T>>protected void doDeleteWithLock(EventSourcedAggregate<T> aggregate)
doDeleteWithLock in class org.axonframework.modelling.command.LockingRepository<T,EventSourcedAggregate<T>>public AggregateFactory<T> getAggregateFactory()
Copyright © 2010–2024. All rights reserved.