Package org.axonframework.eventsourcing
Class AbstractAggregateFactory<T>
java.lang.Object
org.axonframework.eventsourcing.AbstractAggregateFactory<T>
- Type Parameters:
T- The type of Aggregate created by this factory
- All Implemented Interfaces:
AggregateFactory<T>
- Direct Known Subclasses:
GenericAggregateFactory
Abstract AggregateFactory implementation that is aware of snapshot events. If an incoming event is not a snapshot
event, creation is delegated to the subclass.
- Since:
- 2.0
- Author:
- Allard Buijze
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractAggregateFactory(Class<T> aggregateBaseType) Initialize anAggregateFactoryfor the givenaggregateBaseType.protectedInitialize anAggregateFactoryfor the given polymorphicaggregateBaseTypeand it'saggregateSubTypes.protectedAbstractAggregateFactory(AggregateModel<T> aggregateModel) Initializes anAggregateFactoryfor the givenaggregateModel. -
Method Summary
Modifier and TypeMethodDescriptionprotected AggregateModel<T> Gets the aggregate model.final TcreateAggregateRoot(String aggregateIdentifier, DomainEventMessage<?> firstEvent) Instantiate the aggregate root using the given aggregate identifier and first event.protected abstract TdoCreateAggregate(String aggregateIdentifier, DomainEventMessage firstEvent) Create an uninitialized Aggregate instance with the givenaggregateIdentifier.Returns the type of aggregate this factory creates.protected TpostProcessInstance(T aggregate) Perform any processing that must be done on an aggregate instance that was reconstructed from a Snapshot Event.
-
Constructor Details
-
AbstractAggregateFactory
Initialize anAggregateFactoryfor the givenaggregateBaseType.If a first event is an instance of this
aggregateBaseType, it is recognised as a snapshot event. Otherwise, the subclass is asked to instantiate a new aggregate root instance based on the first event.- Parameters:
aggregateBaseType- the base type of the aggregate roots created by this instance
-
AbstractAggregateFactory
protected AbstractAggregateFactory(Class<T> aggregateBaseType, Set<Class<? extends T>> aggregateSubTypes) Initialize anAggregateFactoryfor the given polymorphicaggregateBaseTypeand it'saggregateSubTypes.If a first event is an instance of this
aggregateBaseType, it is recognised as a snapshot event. Otherwise, the subclass is asked to instantiate a new aggregate root instance based on the first event.- Parameters:
aggregateBaseType- the base type of the aggregate roots created by this instanceaggregateSubTypes- aSetof sub types of the givenaggregateBaseType
-
AbstractAggregateFactory
Initializes anAggregateFactoryfor the givenaggregateModel.If a first event is an instance of any aggregate root within this
aggregateModel, it is recognised as a snapshot event. Otherwise, the subclass is asked to instantiate a new aggregate root instance based on the first event.- Parameters:
aggregateModel- the model of aggregate to be created by this factory
-
-
Method Details
-
aggregateModel
Gets the aggregate model.- Returns:
- the aggregate model
-
createAggregateRoot
Description copied from interface:AggregateFactoryInstantiate the aggregate root using the given aggregate identifier and first event. The first event of the event stream is passed to allow the factory to identify the actual implementation type of the aggregate to create. The first event can be either the event that created the aggregate or, when using event sourcing, a snapshot event. In either case, the event should be designed, such that these events contain enough information to deduct the actual aggregate type.- Specified by:
createAggregateRootin interfaceAggregateFactory<T>- Parameters:
aggregateIdentifier- the aggregate identifier of the aggregate to instantiatefirstEvent- The first event in the event stream. This is either the event generated during creation of the aggregate, or a snapshot event- Returns:
- an aggregate root ready for initialization using a DomainEventStream.
-
postProcessInstance
Perform any processing that must be done on an aggregate instance that was reconstructed from a Snapshot Event. Implementations may choose to modify the existing instance, or return a new instance. This method can be safely overridden. This implementation does nothing.- Parameters:
aggregate- The aggregate to post-process.- Returns:
- The aggregate to initialize with the Event Stream
-
doCreateAggregate
Create an uninitialized Aggregate instance with the givenaggregateIdentifier. The givenfirstEventcan be used to define the requirements of the aggregate to create. The givenfirstEventis never a snapshot event.- Parameters:
aggregateIdentifier- The identifier of the aggregate to createfirstEvent- The first event in the Event Stream of the Aggregate- Returns:
- The aggregate instance to initialize with the Event Stream
-
getAggregateType
Description copied from interface:AggregateFactoryReturns the type of aggregate this factory creates. All instances created by this factory must be aninstanceOfthis type.- Specified by:
getAggregateTypein interfaceAggregateFactory<T>- Returns:
- The type of aggregate created by this factory
-