T
- The type of aggregate this repository storespublic class EventSourcingRepository<T extends EventSourcedAggregateRoot> extends LockingRepository<T>
EventBus
and delegate event
storage to the provided EventStore
.EventSourcedAggregateRoot
,
AbstractEventSourcedAggregateRoot
,
AbstractAnnotatedAggregateRoot
,
EventStore
Constructor and Description |
---|
EventSourcingRepository(AggregateFactory<T> aggregateFactory,
EventStore eventStore)
Initializes a repository with the default locking strategy, using the given
aggregateFactory to
create new aggregate instances. |
EventSourcingRepository(AggregateFactory<T> aggregateFactory,
EventStore eventStore,
LockManager lockManager)
Initialize a repository with the given locking strategy.
|
EventSourcingRepository(Class<T> aggregateType,
EventStore eventStore)
Initializes a repository with the default locking strategy, using a GenericAggregateFactory to create new
aggregate instances of given
aggregateType . |
EventSourcingRepository(Class<T> aggregateType,
EventStore eventStore,
LockManager lockManager)
Initialize a repository with the given locking strategy, using a GenericAggregateFactory to create new aggregate
instances.
|
Modifier and Type | Method and Description |
---|---|
protected void |
doDeleteWithLock(T aggregate)
Delegates to
doSaveWithLock(EventSourcedAggregateRoot) , as Event Sourcing generally doesn't delete
aggregates (not their events). |
protected T |
doLoad(Object aggregateIdentifier,
Long expectedVersion)
Perform the actual loading of an aggregate.
|
protected void |
doSaveWithLock(T aggregate)
Perform the actual saving of the aggregate.
|
AggregateFactory<T> |
getAggregateFactory()
Returns the factory used by this repository.
|
String |
getTypeIdentifier()
Return the type identifier belonging to the AggregateFactory of this repository.
|
protected void |
resolveConflicts(T aggregate,
DomainEventStream unseenEvents)
Resolve (potential) conflicts for the given
aggregate , where given unseenEvents may
have been concurrently applied. |
void |
setConflictResolver(ConflictResolver conflictResolver)
Sets the conflict resolver to use for this repository.
|
void |
setEventStreamDecorators(List<? extends EventStreamDecorator> eventProcessors)
Sets the Event Stream Decorators that will process the event in the DomainEventStream when read, or written to
the event store.
|
void |
setSnapshotterTrigger(SnapshotterTrigger snapshotterTrigger)
Sets the snapshotter trigger for this repository.
|
protected void |
validateOnLoad(T aggregate,
Long expectedVersion)
Checks the aggregate for concurrent changes.
|
add, doDelete, doSave, load
getAggregateType, load, postDelete, postSave, setEventBus
public EventSourcingRepository(Class<T> aggregateType, EventStore eventStore)
aggregateType
.aggregateType
- The type of aggregate stored in this repositoryeventStore
- The event store that holds the event streams for this repositoryLockingRepository.LockingRepository(Class)
public EventSourcingRepository(AggregateFactory<T> aggregateFactory, EventStore eventStore)
aggregateFactory
to
create new aggregate instances.aggregateFactory
- The factory for new aggregate instanceseventStore
- The event store that holds the event streams for this repositoryLockingRepository.LockingRepository(Class)
public EventSourcingRepository(AggregateFactory<T> aggregateFactory, EventStore eventStore, LockManager lockManager)
aggregateFactory
- The factory for new aggregate instanceseventStore
- The event store that holds the event streams for this repositorylockManager
- the locking strategy to apply to this repositorypublic EventSourcingRepository(Class<T> aggregateType, EventStore eventStore, LockManager lockManager)
aggregateType
- The type of aggregate to store in this repositoryeventStore
- The event store that holds the event streams for this repositorylockManager
- the locking strategy to apply to thisprotected void doSaveWithLock(T aggregate)
doSaveWithLock
in class LockingRepository<T extends EventSourcedAggregateRoot>
aggregate
- the aggregate to storeprotected void doDeleteWithLock(T aggregate)
doSaveWithLock(EventSourcedAggregateRoot)
, as Event Sourcing generally doesn't delete
aggregates (not their events).
This method may be safely overridden for special cases that do require deleting an Aggregate's Events.doDeleteWithLock
in class LockingRepository<T extends EventSourcedAggregateRoot>
aggregate
- the aggregate to deleteprotected T doLoad(Object aggregateIdentifier, Long expectedVersion)
doLoad
in class LockingRepository<T extends EventSourcedAggregateRoot>
aggregateIdentifier
- the identifier of the aggregate to loadexpectedVersion
- The expected version of the loaded aggregateAggregateDeletedException
- in case an aggregate existed in the past, but has been deletedAggregateNotFoundException
- when an aggregate with the given identifier does not existpublic AggregateFactory<T> getAggregateFactory()
protected void resolveConflicts(T aggregate, DomainEventStream unseenEvents)
aggregate
, where given unseenEvents
may
have been concurrently applied.aggregate
- The aggregate containing the potential conflictsunseenEvents
- The events that have been concurrently appliedpublic String getTypeIdentifier()
protected void validateOnLoad(T aggregate, Long expectedVersion)
ConflictingModificationException
when conflicting changes have been
detected.
This implementation throws a ConflictingAggregateVersionException
if the expected version is not null
and the version number of the aggregate does not match the expected version
This implementation will do nothing if a conflict resolver (See setConflictResolver(ConflictResolver)
is
set. Otherwise, it will call super.validateOnLoad(...)
.validateOnLoad
in class AbstractRepository<T extends EventSourcedAggregateRoot>
aggregate
- The loaded aggregateexpectedVersion
- The expected version of the aggregatepublic void setEventStreamDecorators(List<? extends EventStreamDecorator> eventProcessors)
eventProcessors
- The processors to that will process events in the DomainEventStreampublic void setSnapshotterTrigger(SnapshotterTrigger snapshotterTrigger)
snapshotterTrigger
- the snapshotter trigger for this repository.public void setConflictResolver(ConflictResolver conflictResolver)
null
), the repository will
throw an exception if any unexpected changes appear in loaded aggregates.conflictResolver
- The conflict resolver to use for this repositoryCopyright © 2010-2014. All Rights Reserved.