T
- The type of aggregate this repository storespublic class EventSourcingRepository<T> extends LockingRepository<T,EventSourcedAggregate<T>>
EventBus
and delegate event
storage to the provided EventStore
.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,
LockFactory lockFactory,
ParameterResolverFactory parameterResolverFactory,
SnapshotTriggerDefinition snapshotTriggerDefinition)
Initialize a repository with the given locking strategy and parameter resolver factory.
|
EventSourcingRepository(AggregateFactory<T> aggregateFactory,
EventStore eventStore,
LockFactory lockFactory,
SnapshotTriggerDefinition snapshotTriggerDefinition)
Initialize a repository with the given locking strategy.
|
EventSourcingRepository(AggregateFactory<T> aggregateFactory,
EventStore eventStore,
ParameterResolverFactory parameterResolverFactory,
SnapshotTriggerDefinition snapshotTriggerDefinition)
Initializes a repository with the default locking strategy, using the given
aggregateFactory to
create new aggregate instances. |
EventSourcingRepository(AggregateFactory<T> aggregateFactory,
EventStore eventStore,
SnapshotTriggerDefinition snapshotTriggerDefinition)
Initializes a repository with the default locking strategy, using the given
aggregateFactory to
create new aggregate instances and triggering snapshots using the given snapshotTriggerDefinition |
EventSourcingRepository(AggregateModel<T> aggregateModel,
AggregateFactory<T> aggregateFactory,
EventStore eventStore)
Initializes a repository with the default locking strategy, using the given
aggregateFactory to
create new aggregate instances. |
EventSourcingRepository(AggregateModel<T> aggregateModel,
AggregateFactory<T> aggregateFactory,
EventStore eventStore,
SnapshotTriggerDefinition snapshotTriggerDefinition)
Initializes a repository with the default locking strategy, using the given
aggregateFactory to
create new aggregate instances and triggering snapshots using the given snapshotTriggerDefinition |
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,
SnapshotTriggerDefinition snapshotTriggerDefinition)
Initializes a repository with the default locking strategy, using a GenericAggregateFactory to create new
aggregate instances of given
aggregateType . |
Modifier and Type | Method and Description |
---|---|
protected EventSourcedAggregate<T> |
doCreateNewForLock(Callable<T> factoryMethod)
Creates a new aggregate instance using the given
factoryMethod . |
protected void |
doDeleteWithLock(EventSourcedAggregate<T> aggregate)
Perform the actual deleting of the aggregate.
|
protected EventSourcedAggregate<T> |
doLoadWithLock(String aggregateIdentifier,
Long expectedVersion)
Perform the actual loading of an aggregate.
|
protected void |
doSaveWithLock(EventSourcedAggregate<T> aggregate)
Perform the actual saving of the aggregate.
|
AggregateFactory<T> |
getAggregateFactory()
Returns the factory used by this repository.
|
protected void |
reportIllegalState(LockAwareAggregate<T,EventSourcedAggregate<T>> aggregate)
Invoked when an the given
aggregate instance has been detected that has been part of a rolled back Unit
of Work. |
protected void |
validateOnLoad(Aggregate<T> aggregate,
Long expectedVersion)
Checks the aggregate for concurrent changes.
|
doCreateNew, doDelete, doLoad, doSave, prepareForCommit
aggregateModel, getAggregateType, load, load, managedAggregates, newInstance, postDelete, postSave
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(Class<T> aggregateType, EventStore eventStore, SnapshotTriggerDefinition snapshotTriggerDefinition)
aggregateType
.aggregateType
- The type of aggregate stored in this repositoryeventStore
- The event store that holds the event streams for this repositorysnapshotTriggerDefinition
- The definition describing when to trigger a snapshotLockingRepository.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(AggregateModel<T> aggregateModel, AggregateFactory<T> aggregateFactory, EventStore eventStore)
aggregateFactory
to
create new aggregate instances.aggregateModel
- The meta model describing the aggregate's structureaggregateFactory
- 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, SnapshotTriggerDefinition snapshotTriggerDefinition)
aggregateFactory
to
create new aggregate instances and triggering snapshots using the given snapshotTriggerDefinition
aggregateFactory
- The factory for new aggregate instanceseventStore
- The event store that holds the event streams for this repositorysnapshotTriggerDefinition
- The definition describing when to trigger a snapshotLockingRepository.LockingRepository(Class)
public EventSourcingRepository(AggregateModel<T> aggregateModel, AggregateFactory<T> aggregateFactory, EventStore eventStore, SnapshotTriggerDefinition snapshotTriggerDefinition)
aggregateFactory
to
create new aggregate instances and triggering snapshots using the given snapshotTriggerDefinition
aggregateModel
- The meta model describing the aggregate's structureaggregateFactory
- The factory for new aggregate instanceseventStore
- The event store that holds the event streams for this repositorysnapshotTriggerDefinition
- The definition describing when to trigger a snapshotLockingRepository.LockingRepository(Class)
public EventSourcingRepository(AggregateFactory<T> aggregateFactory, EventStore eventStore, ParameterResolverFactory parameterResolverFactory, SnapshotTriggerDefinition snapshotTriggerDefinition)
aggregateFactory
to
create new aggregate instances.aggregateFactory
- The factory for new aggregate instanceseventStore
- The event store that holds the event streams for this repositoryparameterResolverFactory
- The parameter resolver factory used to resolve parameters of annotated handlerssnapshotTriggerDefinition
- The definition describing when to trigger a snapshotLockingRepository.LockingRepository(Class)
public EventSourcingRepository(AggregateFactory<T> aggregateFactory, EventStore eventStore, LockFactory lockFactory, SnapshotTriggerDefinition snapshotTriggerDefinition)
aggregateFactory
- The factory for new aggregate instanceseventStore
- The event store that holds the event streams for this repositorylockFactory
- the locking strategy to apply to this repositorysnapshotTriggerDefinition
- The definition describing when to trigger a snapshotpublic EventSourcingRepository(AggregateFactory<T> aggregateFactory, EventStore eventStore, LockFactory lockFactory, ParameterResolverFactory parameterResolverFactory, SnapshotTriggerDefinition snapshotTriggerDefinition)
aggregateFactory
- The factory for new aggregate instanceseventStore
- The event store that holds the event streams for this repositorylockFactory
- The locking strategy to apply to this repositoryparameterResolverFactory
- The parameter resolver factory used to resolve parameters of annotated handlerssnapshotTriggerDefinition
- The definition describing when to trigger a snapshotprotected EventSourcedAggregate<T> doLoadWithLock(String aggregateIdentifier, Long expectedVersion)
doLoadWithLock
in class LockingRepository<T,EventSourcedAggregate<T>>
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 existprotected void validateOnLoad(Aggregate<T> aggregate, Long expectedVersion)
AbstractRepository
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
validateOnLoad
in class AbstractRepository<T,LockAwareAggregate<T,EventSourcedAggregate<T>>>
aggregate
- The loaded aggregateexpectedVersion
- The expected version of the aggregateprotected void reportIllegalState(LockAwareAggregate<T,EventSourcedAggregate<T>> aggregate)
AbstractRepository
aggregate
instance has been detected that has been part of a rolled back Unit
of Work. This typically means that the state of the Aggregate instance has been compromised and cannot be
guaranteed to be correct.
This implementation throws an exception, effectively causing the unit of work to be rolled back. Subclasses that can guarantee correct storage, even when specific instances are compromised, may override this method to suppress this exception.
When this method is invoked, the AbstractRepository.doSave(Aggregate)
, AbstractRepository.doDelete(Aggregate)
,
AbstractRepository.postSave(Aggregate)
and AbstractRepository.postDelete(Aggregate)
are not invoked. Implementations may choose to
invoke these methods.
reportIllegalState
in class AbstractRepository<T,LockAwareAggregate<T,EventSourcedAggregate<T>>>
aggregate
- The aggregate instance with illegal stateprotected EventSourcedAggregate<T> doCreateNewForLock(Callable<T> factoryMethod) throws Exception
LockingRepository
factoryMethod
. Implementations should assume that this
method is only called if a UnitOfWork is currently active.doCreateNewForLock
in class LockingRepository<T,EventSourcedAggregate<T>>
factoryMethod
- The method to create the aggregate's root instanceException
- when the factoryMethod throws an exceptionprotected void doSaveWithLock(EventSourcedAggregate<T> aggregate)
LockingRepository
doSaveWithLock
in class LockingRepository<T,EventSourcedAggregate<T>>
aggregate
- the aggregate to storeprotected void doDeleteWithLock(EventSourcedAggregate<T> aggregate)
LockingRepository
doDeleteWithLock
in class LockingRepository<T,EventSourcedAggregate<T>>
aggregate
- the aggregate to deletepublic AggregateFactory<T> getAggregateFactory()
Copyright © 2010–2017. All rights reserved.