Module org.fuin.ddd4j
Package org.fuin.ddd4j.esrepo
Class EventStoreRepository<ID extends AggregateRootId,AGGREGATE extends AggregateRoot<ID>>
java.lang.Object
org.fuin.ddd4j.esrepo.EventStoreRepository<ID,AGGREGATE>
- Type Parameters:
ID- Type of the aggregate root identifier.AGGREGATE- Type of the aggregate root.
- All Implemented Interfaces:
Repository<ID,AGGREGATE>
public abstract class EventStoreRepository<ID extends AggregateRootId,AGGREGATE extends AggregateRoot<ID>>
extends Object
implements Repository<ID,AGGREGATE>
Event store based repository.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedEventStoreRepository(@NotNull org.fuin.esc.api.EventStore eventStore) Constructor with all mandatory data. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new aggregate to the repository without any meta data.voidAdds a new aggregate to the repository with some meta data.protected booleanconflictsResolved(List<DomainEvent<?>> uncommittedChanges, List<DomainEvent<?>> unseenEvents) Checks if the uncommitted changes conflicts with unseen changes from the event store and tries to solve the problem.final voidDeletes an aggregate from the repository.protected @NotNull AggregateCache<AGGREGATE>Returns the aggregate cache.protected final @NotNull org.fuin.esc.api.EventStoreReturns the underlying event store.protected abstract @NotNull StringReturns the parameter name for the unique identifier.protected intReturns the number of tries that should be done to resolve a version conflict.intReturns the number of events to read in a slice.final AGGREGATEReads the latest version of an aggregate.final AGGREGATEReads a given version of an aggregate.final voidSaves the changes on an aggregate in the repository without any meta data.final voidSaves the changes on an aggregate in the repository including some meta data.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.fuin.ddd4j.ddd.Repository
create, getAggregateClass, getAggregateType
-
Constructor Details
-
EventStoreRepository
protected EventStoreRepository(@NotNull @NotNull org.fuin.esc.api.EventStore eventStore) Constructor with all mandatory data.- Parameters:
eventStore- Event store.
-
-
Method Details
-
read
public final AGGREGATE read(ID aggregateId) throws AggregateNotFoundException, AggregateDeletedException Description copied from interface:RepositoryReads the latest version of an aggregate.- Specified by:
readin interfaceRepository<ID extends AggregateRootId,AGGREGATE extends AggregateRoot<ID>> - Parameters:
aggregateId- Unique aggregate identifier.- Returns:
- Aggregate.
- Throws:
AggregateNotFoundException- An aggregate with the given identifier was not found.AggregateDeletedException- The aggregate with the given identifier was already deleted.
-
read
public final AGGREGATE read(ID aggregateId, int version) throws AggregateNotFoundException, AggregateDeletedException, AggregateVersionNotFoundException Description copied from interface:RepositoryReads a given version of an aggregate.- Specified by:
readin interfaceRepository<ID extends AggregateRootId,AGGREGATE extends AggregateRoot<ID>> - Parameters:
aggregateId- Unique aggregate identifier.version- Version to read.- Returns:
- Aggregate.
- Throws:
AggregateNotFoundException- An aggregate with the given identifier was not found.AggregateDeletedException- The aggregate with the given identifier was already deleted.AggregateVersionNotFoundException- An aggregate with the requested version does not exist.
-
update
public final void update(AGGREGATE aggregate) throws AggregateVersionConflictException, AggregateNotFoundException, AggregateDeletedException Description copied from interface:RepositorySaves the changes on an aggregate in the repository without any meta data.- Specified by:
updatein interfaceRepository<ID extends AggregateRootId,AGGREGATE extends AggregateRoot<ID>> - Parameters:
aggregate- Aggregate to store.- Throws:
AggregateVersionConflictException- The expected version didn't match the actual version.AggregateNotFoundException- An aggregate with the given identifier was not found.AggregateDeletedException- The aggregate with the given identifier was already deleted.
-
update
public final void update(AGGREGATE aggregate, String metaType, Object metaData) throws AggregateVersionConflictException, AggregateNotFoundException, AggregateDeletedException Description copied from interface:RepositorySaves the changes on an aggregate in the repository including some meta data.- Specified by:
updatein interfaceRepository<ID extends AggregateRootId,AGGREGATE extends AggregateRoot<ID>> - Parameters:
aggregate- Aggregate to store.metaType- Optional unique name that identifies the type of meta data.metaData- Optional information that is not directly available in the event.- Throws:
AggregateVersionConflictException- The expected version didn't match the actual version.AggregateNotFoundException- An aggregate with the given identifier was not found.AggregateDeletedException- The aggregate with the given identifier was already deleted.
-
add
public void add(AGGREGATE aggregate) throws AggregateAlreadyExistsException, AggregateDeletedException Description copied from interface:RepositoryAdds a new aggregate to the repository without any meta data. The method will fail if an aggregate with the same ID already exists.- Specified by:
addin interfaceRepository<ID extends AggregateRootId,AGGREGATE extends AggregateRoot<ID>> - Parameters:
aggregate- Aggregate to add.- Throws:
AggregateAlreadyExistsException- The aggregate with the given version could not be created because it already exists.AggregateDeletedException- The aggregate with the given identifier was already deleted.
-
add
public void add(AGGREGATE aggregate, String metaType, Object metaData) throws AggregateAlreadyExistsException, AggregateDeletedException Description copied from interface:RepositoryAdds a new aggregate to the repository with some meta data. The method will fail if an aggregate with the same ID already exists.- Specified by:
addin interfaceRepository<ID extends AggregateRootId,AGGREGATE extends AggregateRoot<ID>> - Parameters:
aggregate- Aggregate to add.metaType- Optional unique name that identifies the type of meta data.metaData- Optional information that is not directly available in the event.- Throws:
AggregateAlreadyExistsException- The aggregate with the given version could not be created because it already exists.AggregateDeletedException- The aggregate with the given identifier was already deleted.
-
delete
public final void delete(ID aggregateId, int expectedVersion) throws AggregateVersionConflictException Description copied from interface:RepositoryDeletes an aggregate from the repository. If the aggregate was already deleted, the method will do nothing.- Specified by:
deletein interfaceRepository<ID extends AggregateRootId,AGGREGATE extends AggregateRoot<ID>> - Parameters:
aggregateId- Identifier of the aggregate to delete.expectedVersion- Expected (current) version of the aggregate.- Throws:
AggregateVersionConflictException- The expected version didn't match the actual version.
-
conflictsResolved
protected boolean conflictsResolved(List<DomainEvent<?>> uncommittedChanges, List<DomainEvent<?>> unseenEvents) Checks if the uncommitted changes conflicts with unseen changes from the event store and tries to solve the problem. This method may be overwritten by concrete implementation. Returns FALSE as default if not overwritten in subclasses.- Parameters:
uncommittedChanges- Uncommitted changes.unseenEvents- Unseen changes from the event store.- Returns:
- TRUE if there are no conflicting changes, else FALSE (conflict couldn't be resolved).
-
getMaxTryCount
protected int getMaxTryCount()Returns the number of tries that should be done to resolve a version conflict. This method may be overwritten by concrete implementation. Returns3as default if not overwritten in subclasses.- Returns:
- Number of tries.
-
getAggregateCache
Returns the aggregate cache. This method may be overwritten by concrete implementation. Returns no cache as default if not overwritten in subclasses.- Returns:
- Cache.
-
getReadPageSize
public int getReadPageSize()Returns the number of events to read in a slice. This method may be overwritten by concrete implementation. Returns100as default if not overwritten in subclasses.- Returns:
- Page size.
-
getEventStore
@NotNull protected final @NotNull org.fuin.esc.api.EventStore getEventStore()Returns the underlying event store.- Returns:
- Event store implementation.
-
getIdParamName
Returns the parameter name for the unique identifier.- Returns:
- Name to be used as parameter.
-