org.axonframework.eventsourcing
Class GenericEventSourcingRepository<T extends EventSourcedAggregateRoot>
java.lang.Object
org.axonframework.repository.AbstractRepository<T>
org.axonframework.repository.LockingRepository<T>
org.axonframework.eventsourcing.EventSourcingRepository<T>
org.axonframework.eventsourcing.GenericEventSourcingRepository<T>
- Type Parameters:
T - The aggregate type this repository serves
- All Implemented Interfaces:
- AggregateFactory<T>, Repository<T>
public class GenericEventSourcingRepository<T extends EventSourcedAggregateRoot>
- extends EventSourcingRepository<T>
The GenericEventSourcingRepository is a special EventSourcingRepository implementation that can act as a repository
for any type of EventSourcedAggregateRoot.
There is however, a convention that these EventSourcedAggregateRoot classes must adhere to. The type must declare an
accessible constructor accepting a AggregateIdentifier as single parameter. This
constructor may not perform any initialization on the aggregate, other than setting the identifier.
If the constructor is not accessible (not public), and the JVM's security setting allow it, the
GenericEventSourcingRepository will try to make it accessible.
- Since:
- 0.5
- Author:
- Allard Buijze
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
GenericEventSourcingRepository
public GenericEventSourcingRepository(Class<T> aggregateType)
- Creates a GenericEventSourcingRepository for aggregates of the given
aggregateType, using the
default locking strategy (optimistic locking). The given type must at least provide an accessible constructor
taking a UUID as single parameter.
If the constructor is not accessible, the GenericEventSourcingRepository will attempt to make it so. If JVM
security restrictions don't allow that, an exception is thrown.
- Parameters:
aggregateType - The type of aggregate this repository holds
- Throws:
IncompatibleAggregateException - If there is no accessible constructor accepting a UUID as single
parameter
GenericEventSourcingRepository
public GenericEventSourcingRepository(Class<T> aggregateType,
LockingStrategy lockingStrategy)
- Creates a GenericEventSourcingRepository for aggregates of the given
aggregateType, using the given
lockingStrategy. The given aggregate type must at least provide an accessible constructor taking a
UUID as single parameter.
If the constructor is not accessible, the GenericEventSourcingRepository will attempt to make it so. If JVM
security restrictions don't allow that, an exception is thrown.
- Parameters:
aggregateType - The type of aggregate this repository holdslockingStrategy - The locking strategy to use for this repository
- Throws:
IncompatibleAggregateException - If there is no accessible constructor accepting a UUID as single
parameter
getTypeIdentifier
public String getTypeIdentifier()
- Returns the simple name of the aggregate class.
- Returns:
- the simple name of the aggregate class.
instantiateAggregate
public T instantiateAggregate(AggregateIdentifier aggregateIdentifier,
DomainEvent firstEvent)
- Instantiate the aggregate using the given aggregate identifier and first event. The first event of the event
stream is passed to allow the repository 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.
Note that aggregate state should *not* be initialized by this method. That means, no events
should be applied by a call to this method. The first event is passed to allow the implementation to base the
exact type of aggregate to instantiate on that event.
- Specified by:
instantiateAggregate in class EventSourcingRepository<T extends EventSourcedAggregateRoot>
- 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 ready for initialization using a DomainEventStream.
- Throws:
IncompatibleAggregateException - if the aggregate constructor throws an exception, or if the JVM security
settings prevent the GenericEventSourcingRepository from calling the
constructor.
Copyright © 2011. All Rights Reserved.