T - the aggregate class, which is a subtype of CommandProcessingAggregateCT - the aggregate's command class, a subtype of command
For example:
public class AccountService {
private final AggregateRepository>Account, AccountCommand> accountRepository;
public AccountService(AggregateRepository>Account, AccountCommand> accountRepository) {
this.accountRepository = accountRepository;
}
public CompletableFuture>EntityWithIdAndVersion>Account>> openAccount(BigDecimal initialBalance) {
return accountRepository.save(new CreateAccountCommand(initialBalance));
}
}
public class AggregateRepository<T extends CommandProcessingAggregate<T,CT>,CT extends Command> extends Object
CommandProcessingAggregate,
Command| Constructor and Description |
|---|
AggregateRepository(Class<T> clasz,
EventuateAggregateStore aggregateStore)
Constructs a new AggregateRepository for the specified aggregate class and aggregate store
|
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<EntityWithMetadata<T>> |
find(String entityId)
Find an aggregate
|
CompletableFuture<EntityWithMetadata<T>> |
find(String entityId,
FindOptions findOptions)
Find an aggregate
|
CompletableFuture<EntityWithMetadata<T>> |
find(String entityId,
Optional<FindOptions> findOptions)
Find an aggregate
|
CompletableFuture<EntityWithIdAndVersion<T>> |
save(CT cmd)
Create a new Aggregate by processing a command and persisting the events
|
CompletableFuture<EntityWithIdAndVersion<T>> |
save(CT cmd,
Optional<SaveOptions> saveOptions)
Create a new Aggregate by processing a command and persisting the events
|
void |
setInterceptor(AggregateRepositoryInterceptor<T,CT> interceptor) |
void |
setMissingApplyEventMethodStrategy(MissingApplyEventMethodStrategy missingApplyEventMethodStrategy) |
CompletableFuture<EntityWithIdAndVersion<T>> |
update(String entityId,
CT cmd)
Update the specified aggregate by processing a command and saving events
|
CompletableFuture<EntityWithIdAndVersion<T>> |
update(String entityId,
CT cmd,
Optional<UpdateOptions> updateOptions)
Update the specified aggregate by processing a command and saving events
|
CompletableFuture<EntityWithIdAndVersion<T>> |
updateWithProvidedCommand(String entityId,
Function<T,Optional<CT>> commandProvider,
Optional<UpdateOptions> updateOptions)
Update the specified aggregate by processing a command and saving events
|
public AggregateRepository(Class<T> clasz, EventuateAggregateStore aggregateStore)
clasz - the class of the aggregateaggregateStore - the aggregate storepublic void setMissingApplyEventMethodStrategy(MissingApplyEventMethodStrategy missingApplyEventMethodStrategy)
public void setInterceptor(AggregateRepositoryInterceptor<T,CT> interceptor)
public CompletableFuture<EntityWithIdAndVersion<T>> save(CT cmd)
cmd - the command to processpublic CompletableFuture<EntityWithIdAndVersion<T>> save(CT cmd, Optional<SaveOptions> saveOptions)
cmd - the command to processsaveOptions - creation optionspublic CompletableFuture<EntityWithIdAndVersion<T>> update(String entityId, CT cmd)
entityId - the id of the aggregate to updatecmd - the command to processpublic CompletableFuture<EntityWithIdAndVersion<T>> update(String entityId, CT cmd, Optional<UpdateOptions> updateOptions)
entityId - the id of the aggregate to updatecmd - the command to processupdateOptions - options for updatingpublic CompletableFuture<EntityWithIdAndVersion<T>> updateWithProvidedCommand(String entityId, Function<T,Optional<CT>> commandProvider, Optional<UpdateOptions> updateOptions)
entityId - the id of the aggregate to updatecommandProvider - the provider of the command to processupdateOptions - options for updatingpublic CompletableFuture<EntityWithMetadata<T>> find(String entityId)
entityId - the id of the aggregate to findpublic CompletableFuture<EntityWithMetadata<T>> find(String entityId, FindOptions findOptions)
entityId - the id of the aggregate to findfindOptions - options for findingpublic CompletableFuture<EntityWithMetadata<T>> find(String entityId, Optional<FindOptions> findOptions)
entityId - the id of the aggregate to findfindOptions - options for findingCopyright © 2021. All rights reserved.