T
- The type of aggregate this repository storespublic class CachingEventSourcingRepository<T> extends EventSourcingRepository<T>
Note that an entry of a cached aggregate is immediately invalidated when an error occurs while saving that aggregate. This is done to prevent the cache from returning aggregates that may not have fully persisted to disk.
EventSourcingRepository.Builder<T>
Modifier | Constructor and Description |
---|---|
protected |
CachingEventSourcingRepository(EventSourcingRepository.Builder<T> builder)
Instantiate a
CachingEventSourcingRepository based on the fields contained in the
EventSourcingRepository.Builder . |
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.
|
protected void |
validateOnLoad(Aggregate<T> aggregate,
Long expectedVersion)
Checks the aggregate for concurrent changes.
|
builder, getAggregateFactory, readEvents, reportIllegalState
doCreateNew, doDelete, doLoad, doLoadOrCreate, doSave, prepareForCommit
aggregateModel, canResolve, getAggregateType, load, load, loadOrCreate, managedAggregates, newInstance, postDelete, postSave, send
protected CachingEventSourcingRepository(EventSourcingRepository.Builder<T> builder)
CachingEventSourcingRepository
based on the fields contained in the
EventSourcingRepository.Builder
.
A goal of the provided Builder is to create an AggregateModel
specifying generic T
as the
aggregate type to be stored. All aggregates in this repository must be instanceOf
this aggregate type.
To instantiate this AggregateModel, either an AggregateModel
can be provided directly or an
aggregateType
of type Class
can be used. The latter will internally resolve to an
AggregateModel. Thus, either the AggregateModel or the aggregateType
should be provided. An
AxonConfigurationException
is thrown if this criteria is not met.
The same criteria holds for the AggregateFactory
. Either the AggregateFactory can be set directly or it
will be instantiated internally based on the aggregateType
. Hence, one of both is a hard requirement, and
will also result in an AxonConfigurationException if both are missing.
Additionally will assert that the LockFactory
, EventStore
, SnapshotTriggerDefinition
and
Cache
are not null
, resulting in an AxonConfigurationException if for any of these this is the
case.
builder
- the EventSourcingRepository.Builder
used to instantiate a
CachingEventSourcingRepository
instanceprotected 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 EventSourcingRepository<T>
aggregate
- The loaded aggregateexpectedVersion
- The expected version of the aggregateprotected 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 EventSourcingRepository<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 EventSourcingRepository<T>
aggregate
- the aggregate to storeprotected void doDeleteWithLock(EventSourcedAggregate<T> aggregate)
LockingRepository
doDeleteWithLock
in class EventSourcingRepository<T>
aggregate
- the aggregate to deleteprotected EventSourcedAggregate<T> doLoadWithLock(String aggregateIdentifier, Long expectedVersion)
doLoadWithLock
in class EventSourcingRepository<T>
aggregateIdentifier
- the identifier of the aggregate to loadexpectedVersion
- The expected version of the aggregateCopyright © 2010–2020. All rights reserved.