Package org.fuin.ddd4j.ddd
Interface Repository<ID extends AggregateRootId,T extends AggregateRoot<ID>>
-
- Type Parameters:
ID- Type of the aggregate root identifier.T- Type of the aggregate.
- All Known Implementing Classes:
EventStoreRepository
public interface Repository<ID extends AggregateRootId,T extends AggregateRoot<ID>>Repository that supports CRUD operations for an aggregate.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidadd(T aggregate)Adds a new aggregate to the repository without any meta data.voidadd(T aggregate, String metaType, Object metaData)Adds a new aggregate to the repository with some meta data.Tcreate()Factory method to create a new aggregate.voiddelete(ID aggregateId, int expectedVersion)Deletes an aggregate from the repository.@NotNull Class<T>getAggregateClass()Returns the class of the aggregate in the repository.@NotNull EntityTypegetAggregateType()Returns a unique name for the aggregate root type.Tread(ID id)Reads the latest version of an aggregate.Tread(ID id, int version)Reads a given version of an aggregate.voidupdate(T aggregate)Saves the changes on an aggregate in the repository without any meta data.voidupdate(T aggregate, String metaType, Object metaData)Saves the changes on an aggregate in the repository including some meta data.
-
-
-
Method Detail
-
getAggregateClass
@NotNull @NotNull Class<T> getAggregateClass()
Returns the class of the aggregate in the repository.- Returns:
- Aggregate class.
-
getAggregateType
@NotNull @NotNull EntityType getAggregateType()
Returns a unique name for the aggregate root type. This can be used to provide a shorted name for an aggregate type. Another good choice may be the FQN of thegetAggregateClass()class.- Returns:
- Name of the type of the aggregate.
-
create
@NotNull T create()
Factory method to create a new aggregate. Just creates a new instance without doing anything else. The aggregate identifier will NOT be set.- Returns:
- New aggregate instance that is NOT persisted. Use the
update(AggregateRoot, String, Object)method to persist this new aggregate.
-
read
@NotNull T read(@NotNull ID id) throws AggregateNotFoundException, AggregateDeletedException
Reads the latest version of an aggregate.- Parameters:
id- 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
@NotNull T read(@NotNull ID id, int version) throws AggregateNotFoundException, AggregateDeletedException, AggregateVersionNotFoundException
Reads a given version of an aggregate.- Parameters:
id- 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
void update(@NotNull T aggregate, @Nullable String metaType, @Nullable Object metaData) throws AggregateVersionConflictException, AggregateNotFoundException, AggregateDeletedExceptionSaves the changes on an aggregate in the repository including some meta data.- 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.AggregateDeletedException- The aggregate with the given identifier was already deleted.AggregateNotFoundException- An aggregate with the given identifier was not found.
-
add
void add(@NotNull T aggregate) throws AggregateAlreadyExistsException, AggregateDeletedExceptionAdds a new aggregate to the repository without any meta data. The method will fail if an aggregate with the same ID already exists.- 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
void add(@NotNull T aggregate, @Nullable String metaType, @Nullable Object metaData) throws AggregateAlreadyExistsException, AggregateDeletedExceptionAdds a new aggregate to the repository with some meta data. The method will fail if an aggregate with the same ID already exists.- 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.
-
update
void update(@NotNull T aggregate) throws AggregateVersionConflictException, AggregateNotFoundException, AggregateDeletedExceptionSaves the changes on an aggregate in the repository without any meta data.- Parameters:
aggregate- Aggregate to store.- Throws:
AggregateVersionConflictException- The expected version didn't match the actual version.AggregateDeletedException- The aggregate with the given identifier was already deleted.AggregateNotFoundException- An aggregate with the given identifier was not found.
-
delete
void delete(@NotNull ID aggregateId, int expectedVersion) throws AggregateVersionConflictExceptionDeletes an aggregate from the repository. If the aggregate was already deleted, the method will do nothing.- 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.
-
-