Module org.fuin.ddd4j
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
Modifier and TypeMethodDescriptionvoidAdds a new aggregate to the repository without any meta data.voidAdds a new aggregate to the repository with some meta data.create()Factory method to create a new aggregate.voidDeletes an aggregate from the repository.Returns the class of the aggregate in the repository.@NotNull EntityTypeReturns a unique name for the aggregate root type.Reads the latest version of an aggregate.Reads a given version of an aggregate.voidSaves the changes on an aggregate in the repository without any meta data.voidSaves the changes on an aggregate in the repository including some meta data.
-
Method Details
-
getAggregateClass
Returns the class of the aggregate in the repository.- Returns:
- Aggregate class.
-
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
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
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, AggregateDeletedException Saves 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
Adds 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, AggregateDeletedException Adds 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, AggregateDeletedException Saves 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
Deletes 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.
-