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.
Constructor and Description |
---|
CachingEventSourcingRepository(AggregateFactory<T> aggregateFactory,
EventStore eventStore,
Cache cache)
Initializes a repository with a the given
aggregateFactory and a pessimistic locking strategy. |
CachingEventSourcingRepository(AggregateFactory<T> aggregateFactory,
EventStore eventStore,
Cache cache,
SnapshotTriggerDefinition snapshotTriggerDefinition)
Initializes a repository with a the given
aggregateFactory and a pessimistic locking strategy. |
CachingEventSourcingRepository(AggregateFactory<T> aggregateFactory,
EventStore eventStore,
LockFactory lockFactory,
Cache cache,
ParameterResolverFactory parameterResolverFactory,
SnapshotTriggerDefinition snapshotTriggerDefinition)
Initializes a repository with a the given
aggregateFactory and a pessimistic locking strategy. |
CachingEventSourcingRepository(AggregateFactory<T> aggregateFactory,
EventStore eventStore,
LockFactory lockFactory,
Cache cache,
SnapshotTriggerDefinition snapshotTriggerDefinition)
Initializes a repository with a the given
aggregateFactory and a pessimistic locking strategy. |
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 |
prepareForCommit(LockAwareAggregate<T,EventSourcedAggregate<T>> aggregate)
Register handlers with the current Unit of Work that save or delete the given
aggregate when
the Unit of Work is committed. |
getAggregateFactory, reportIllegalState, validateOnLoad
doCreateNew, doDelete, doLoad, doSave
aggregateModel, getAggregateType, load, load, managedAggregates, newInstance, postDelete, postSave
public CachingEventSourcingRepository(AggregateFactory<T> aggregateFactory, EventStore eventStore, Cache cache)
aggregateFactory
and a pessimistic locking strategy. It stores
Aggregates in the given cache
.
A repository initialized using this constructor does not create snapshots for aggregates.
aggregateFactory
- The factory for new aggregate instanceseventStore
- The event store that holds the event streams for this repositorycache
- The cache in which entries will be storedLockingRepository.LockingRepository(Class)
public CachingEventSourcingRepository(AggregateFactory<T> aggregateFactory, EventStore eventStore, Cache cache, SnapshotTriggerDefinition snapshotTriggerDefinition)
aggregateFactory
and a pessimistic locking strategy.aggregateFactory
- The factory for new aggregate instanceseventStore
- The event store that holds the event streams for this repositorycache
- The cache in which entries will be storedsnapshotTriggerDefinition
- The definition describing when to trigger a snapshotLockingRepository.LockingRepository(Class)
public CachingEventSourcingRepository(AggregateFactory<T> aggregateFactory, EventStore eventStore, LockFactory lockFactory, Cache cache, SnapshotTriggerDefinition snapshotTriggerDefinition)
aggregateFactory
and a pessimistic locking strategy.
Note that an optimistic locking strategy is not compatible with caching.
aggregateFactory
- The factory for new aggregate instanceseventStore
- The event store that holds the event streams for this repositorylockFactory
- The lock factory restricting concurrent access to aggregate instancescache
- The cache in which entries will be storedsnapshotTriggerDefinition
- The definition describing when to trigger a snapshot @see
LockingRepository#LockingRepository(Class)public CachingEventSourcingRepository(AggregateFactory<T> aggregateFactory, EventStore eventStore, LockFactory lockFactory, Cache cache, ParameterResolverFactory parameterResolverFactory, SnapshotTriggerDefinition snapshotTriggerDefinition)
aggregateFactory
and a pessimistic locking strategy.
Note that an optimistic locking strategy is not compatible with caching.
aggregateFactory
- The factory for new aggregate instanceseventStore
- The event store that holds the event streams for this repositorylockFactory
- The lock factory restricting concurrent access to aggregate instancescache
- The cache in which entries will be storedparameterResolverFactory
- The parameter resolver factory used to resolve parameters of annotated handlerssnapshotTriggerDefinition
- The definition describing when to trigger a snapshot @see
LockingRepository#LockingRepository(Class)protected void prepareForCommit(LockAwareAggregate<T,EventSourcedAggregate<T>> aggregate)
AbstractRepository
aggregate
when
the Unit of Work is committed.prepareForCommit
in class LockingRepository<T,EventSourcedAggregate<T>>
aggregate
- The Aggregate to save or delete when the Unit of Work is committedprotected 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–2017. All rights reserved.