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

java.lang.Object
  extended by org.axonframework.eventsourcing.AbstractAggregateFactory<T>
      extended by org.axonframework.eventsourcing.SpringPrototypeAggregateFactory<T>
Type Parameters:
T - The type of aggregate generated by this aggregate factory
All Implemented Interfaces:
AggregateFactory<T>, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware

public class SpringPrototypeAggregateFactory<T extends EventSourcedAggregateRoot>
extends AbstractAggregateFactory<T>
implements org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.BeanNameAware

AggregateFactory implementation that uses Spring prototype beans to create new uninitialized instances of Aggregates.

Since:
1.2
Author:
Allard Buijze

Constructor Summary
SpringPrototypeAggregateFactory()
           
 
Method Summary
 void afterPropertiesSet()
           
 T doCreateAggregate(Object aggregateIdentifier, DomainEventMessage firstEvent)
          Create an uninitialized Aggregate instance with the given aggregateIdentifier.
 Class<T> getAggregateType()
          Returns the type of aggregate this factory creates.
 String getTypeIdentifier()
          Returns the type identifier for this aggregate factory.
protected  T postProcessInstance(T aggregate)
          Perform any processing that must be done on an aggregate instance that was reconstructed from a Snapshot Event.
 void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
           
 void setBeanName(String beanName)
           
 void setParameterResolverFactory(ParameterResolverFactory parameterResolverFactory)
          Sets the parameter resolver with which parameters of annotated event handlers in the aggregae are resolved.
 void setPrototypeBeanName(String prototypeBeanName)
          Sets the name of the prototype bean this repository serves.
 void setTypeIdentifier(String typeIdentifier)
          Sets the type identifier of the aggregate served by this repository.
 
Methods inherited from class org.axonframework.eventsourcing.AbstractAggregateFactory
createAggregate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpringPrototypeAggregateFactory

public SpringPrototypeAggregateFactory()
Method Detail

doCreateAggregate

public T doCreateAggregate(Object aggregateIdentifier,
                           DomainEventMessage firstEvent)
Description copied from class: AbstractAggregateFactory
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.

Specified by:
doCreateAggregate in class AbstractAggregateFactory<T extends EventSourcedAggregateRoot>
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

postProcessInstance

protected T postProcessInstance(T aggregate)
Description copied from class: AbstractAggregateFactory
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.

Overrides:
postProcessInstance in class AbstractAggregateFactory<T extends EventSourcedAggregateRoot>
Parameters:
aggregate - The aggregate to post-process.
Returns:
The aggregate to initialize with the Event Stream

getTypeIdentifier

public String getTypeIdentifier()
Description copied from interface: AggregateFactory
Returns the type identifier for this aggregate factory. The type identifier is used by the EventStore to organize data related to the same type of aggregate.

Tip: in most cases, the simple class name would be a good start.

Specified by:
getTypeIdentifier in interface AggregateFactory<T extends EventSourcedAggregateRoot>
Returns:
the type identifier of the aggregates this repository stores

getAggregateType

public Class<T> getAggregateType()
Description copied from interface: AggregateFactory
Returns the type of aggregate this factory creates. All instances created by this factory must be an instanceOf this type.

Specified by:
getAggregateType in interface AggregateFactory<T extends EventSourcedAggregateRoot>
Returns:
The type of aggregate created by this factory

setPrototypeBeanName

public void setPrototypeBeanName(String prototypeBeanName)
Sets the name of the prototype bean this repository serves. Note that the the bean should have the prototype scope and have a constructor that takes a single UUID argument.

Parameters:
prototypeBeanName - the name of the prototype bean this repository serves.

setTypeIdentifier

public void setTypeIdentifier(String typeIdentifier)
Sets the type identifier of the aggregate served by this repository. The type identifier is used to identify events in the event store as belonging to an aggregate served by this repository.

Defaults to the bean name of the prototype bean.

Parameters:
typeIdentifier - the type identifier of the aggregate served by this repository.

setParameterResolverFactory

public void setParameterResolverFactory(ParameterResolverFactory parameterResolverFactory)
Sets the parameter resolver with which parameters of annotated event handlers in the aggregae are resolved.

Parameters:
parameterResolverFactory - the factory that provides resolver for parameters.

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware

setBeanName

public void setBeanName(String beanName)
Specified by:
setBeanName in interface org.springframework.beans.factory.BeanNameAware

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
Exception


Copyright © 2010-2016. All Rights Reserved.