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

java.lang.Object
  extended by org.axonframework.repository.AbstractRepository<T>
      extended by org.axonframework.repository.LockingRepository<T>
          extended by org.axonframework.eventsourcing.EventSourcingRepository<T>
              extended by org.axonframework.eventsourcing.CachingEventSourcingRepository<T>
                  extended by org.axonframework.eventsourcing.CachingGenericEventSourcingRepository<T>
Type Parameters:
T - The aggregate type this repository serves
All Implemented Interfaces:
AggregateFactory<T>, Repository<T>

public class CachingGenericEventSourcingRepository<T extends EventSourcedAggregateRoot>
extends CachingEventSourcingRepository<T>

The CachingGenericEventSourcingRepository is a special EventSourcingRepository implementation that can act as a repository for any type of EventSourcedAggregateRoot. In contrast to the GenericEventSourcingRepository, it also supports caching.

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.7
Author:
Allard Buijze

Constructor Summary
CachingGenericEventSourcingRepository(Class<T> aggregateType)
          Creates a GenericEventSourcingRepository for aggregates of the given aggregateType, using the default locking strategy (optimistic locking).
 
Method Summary
 String getTypeIdentifier()
          Returns the simple name of the aggregate class.
 T instantiateAggregate(AggregateIdentifier aggregateIdentifier, DomainEvent firstEvent)
          Instantiate the aggregate using the given aggregate identifier and first event.
 
Methods inherited from class org.axonframework.eventsourcing.CachingEventSourcingRepository
doLoad, doSaveWithLock, setCache
 
Methods inherited from class org.axonframework.eventsourcing.EventSourcingRepository
createAggregate, setConflictResolver, setEventStore, setEventStreamDecorators, setSnapshotterTrigger, validateOnLoad
 
Methods inherited from class org.axonframework.repository.LockingRepository
doSave, load
 
Methods inherited from class org.axonframework.repository.AbstractRepository
add, load, setEventBus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingGenericEventSourcingRepository

public CachingGenericEventSourcingRepository(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
Method Detail

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 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.
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.