Class CachingEventSourcingRepository<T>
- Type Parameters:
T- The type of aggregate this repository stores
- All Implemented Interfaces:
ScopeAware,Repository<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.
- Since:
- 0.3
- Author:
- Allard Buijze
-
Nested Class Summary
Nested classes/interfaces inherited from class org.axonframework.eventsourcing.EventSourcingRepository
EventSourcingRepository.Builder<T> -
Field Summary
Fields inherited from class org.axonframework.modelling.command.AbstractRepository
spanFactory -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate aCachingEventSourcingRepositorybased on the fields contained in theEventSourcingRepository.Builder. -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoDeleteWithLock(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 voiddoSaveWithLock(EventSourcedAggregate<T> aggregate) Perform the actual saving of the aggregate.protected voidvalidateOnLoad(Aggregate<T> aggregate, Long expectedVersion) Checks the aggregate for concurrent changes.Methods inherited from class org.axonframework.eventsourcing.EventSourcingRepository
builder, doCreateNewForLock, getAggregateFactory, readEvents, reportIllegalStateMethods inherited from class org.axonframework.modelling.command.LockingRepository
doCreateNew, doDelete, doLoad, doLoadOrCreate, doSave, prepareForCommitMethods inherited from class org.axonframework.modelling.command.AbstractRepository
aggregateModel, canResolve, getAggregateType, load, load, loadOrCreate, managedAggregates, newInstance, newInstance, postDelete, postSave, send
-
Constructor Details
-
CachingEventSourcingRepository
Instantiate aCachingEventSourcingRepositorybased on the fields contained in theEventSourcingRepository.Builder.A goal of the provided Builder is to create an
AggregateModelspecifying genericTas the aggregate type to be stored. All aggregates in this repository must beinstanceOfthis aggregate type. To instantiate this AggregateModel, either anAggregateModelcan be provided directly or anaggregateTypeof typeClasscan be used. The latter will internally resolve to an AggregateModel. Thus, either the AggregateModel or theaggregateTypeshould be provided. AnAxonConfigurationExceptionis thrown if this criteria is not met. The same criteria holds for theAggregateFactory. Either the AggregateFactory can be set directly or it will be instantiated internally based on theaggregateType. 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,SnapshotTriggerDefinitionandCacheare notnull, resulting in an AxonConfigurationException if for any of these this is the case.- Parameters:
builder- theEventSourcingRepository.Builderused to instantiate aCachingEventSourcingRepositoryinstance
-
-
Method Details
-
validateOnLoad
Description copied from class:AbstractRepositoryChecks the aggregate for concurrent changes. Throws aConflictingModificationExceptionwhen conflicting changes have been detected.This implementation throws a
ConflictingAggregateVersionExceptionif the expected version is not null and the version number of the aggregate does not match the expected version- Overrides:
validateOnLoadin classEventSourcingRepository<T>- Parameters:
aggregate- The loaded aggregateexpectedVersion- The expected version of the aggregate
-
doSaveWithLock
Description copied from class:LockingRepositoryPerform the actual saving of the aggregate. All necessary locks have been verified.- Overrides:
doSaveWithLockin classEventSourcingRepository<T>- Parameters:
aggregate- the aggregate to store
-
doDeleteWithLock
Description copied from class:LockingRepositoryPerform the actual deleting of the aggregate. All necessary locks have been verified.- Overrides:
doDeleteWithLockin classEventSourcingRepository<T>- Parameters:
aggregate- the aggregate to delete
-
doLoadWithLock
Perform the actual loading of an aggregate. The necessary locks have been obtained. If the aggregate is available in the cache, it is returned from there. Otherwise the underlying persistence logic is called to retrieve the aggregate.- Overrides:
doLoadWithLockin classEventSourcingRepository<T>- Parameters:
aggregateIdentifier- the identifier of the aggregate to loadexpectedVersion- The expected version of the aggregate- Returns:
- the fully initialized aggregate
-