org.axonframework.eventsourcing
Class AbstractAggregateFactory<T extends EventSourcedAggregateRoot>

java.lang.Object
  extended by 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, SpringPrototypeAggregateFactory

public abstract class AbstractAggregateFactory<T extends EventSourcedAggregateRoot>
extends Object
implements AggregateFactory<T>

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
protected AbstractAggregateFactory()
           
protected AbstractAggregateFactory(ParameterResolverFactory parameterResolverFactory)
           
 
Method Summary
 T createAggregate(Object aggregateIdentifier, DomainEventMessage<?> firstEvent)
          Instantiate the aggregate using the given aggregate identifier and first event.
protected abstract  T doCreateAggregate(Object aggregateIdentifier, DomainEventMessage firstEvent)
          Create an uninitialized Aggregate instance with the given aggregateIdentifier.
protected  T postProcessInstance(T aggregate)
          Perform any processing that must be done on an aggregate instance that was reconstructed from a Snapshot Event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.axonframework.eventsourcing.AggregateFactory
getAggregateType, getTypeIdentifier
 

Constructor Detail

AbstractAggregateFactory

protected AbstractAggregateFactory()

AbstractAggregateFactory

protected AbstractAggregateFactory(ParameterResolverFactory parameterResolverFactory)
Method Detail

createAggregate

public final T createAggregate(Object aggregateIdentifier,
                               DomainEventMessage<?> firstEvent)
Description copied from interface: AggregateFactory
Instantiate the aggregate 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:
createAggregate in interface AggregateFactory<T extends EventSourcedAggregateRoot>
Parameters:
aggregateIdentifier - the aggregate identifier of the aggregate to instantiate
firstEvent - 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 ready for initialization using a DomainEventStream.

postProcessInstance

protected T postProcessInstance(T aggregate)
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

protected abstract T doCreateAggregate(Object aggregateIdentifier,
                                       DomainEventMessage firstEvent)
Create an uninitialized Aggregate instance with the given aggregateIdentifier. The given firstEvent can be used to define the requirements of the aggregate to create.

The given firstEvent is never a snapshot event.

Parameters:
aggregateIdentifier - The identifier of the aggregate to create
firstEvent - The first event in the Event Stream of the Aggregate
Returns:
The aggregate instance to initialize with the Event Stream


Copyright © 2010-2016. All Rights Reserved.