org.axonframework.eventsourcing
Class CachingEventSourcingRepository<T extends EventSourcedAggregateRoot>
java.lang.Object
org.axonframework.repository.AbstractRepository<T>
org.axonframework.repository.LockingRepository<T>
org.axonframework.eventsourcing.EventSourcingRepository<T>
org.axonframework.eventsourcing.CachingEventSourcingRepository<T>
- Type Parameters:
T - The type of aggregate this repository stores
- All Implemented Interfaces:
- AggregateFactory<T>, Repository<T>
- Direct Known Subclasses:
- CachingGenericEventSourcingRepository
public abstract class CachingEventSourcingRepository<T extends EventSourcedAggregateRoot>
- extends EventSourcingRepository<T>
Implementation of the event sourcing repository that uses a cache to improve loading performance. The cache removes
the need to read all events from disk, at the cost of memory usage. Since caching is not compatible with the
optimistic locking strategy, only pessimistic locking is available for this type of repository.
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
|
Method Summary |
T |
doLoad(AggregateIdentifier aggregateIdentifier,
Long expectedVersion)
Perform the actual loading of an aggregate. |
void |
doSaveWithLock(T aggregate)
Saves the aggregate and stores it in the cache (if configured) for fast retrieval. |
void |
setCache(net.sf.jsr107cache.Cache cache)
Set the cache to use for this repository. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CachingEventSourcingRepository
protected CachingEventSourcingRepository()
- Initializes a repository with a pessimistic locking strategy. Optimistic locking is not compatible with caching.
doSaveWithLock
public void doSaveWithLock(T aggregate)
- Saves the aggregate and stores it in the cache (if configured) for fast retrieval. If an exception occurs while
saving the aggregate, the related cache entry is invalidated immediately.
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.
- Overrides:
doSaveWithLock in class EventSourcingRepository<T extends EventSourcedAggregateRoot>
- Parameters:
aggregate - the aggregate to save
doLoad
public T doLoad(AggregateIdentifier aggregateIdentifier,
Long expectedVersion)
- 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:
doLoad in class EventSourcingRepository<T extends EventSourcedAggregateRoot>
- Parameters:
aggregateIdentifier - the identifier of the aggregate to loadexpectedVersion - The expected version of the aggregate
- Returns:
- the fully initialized aggregate
setCache
public void setCache(net.sf.jsr107cache.Cache cache)
- Set the cache to use for this repository. If a cache is not set, caching is disabled for this implementation.
- Parameters:
cache - the cache to use
Copyright © 2011. All Rights Reserved.