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 EntityWithIdAndVersion>Account> openAccount(BigDecimal initialBalance) { return accountRepository.save(new CreateAccountCommand(initialBalance)); } }
public class AggregateRepository<T extends CommandProcessingAggregate<T,CT>,CT extends Command> extends CommonAggregateRepository<T,CT>
CommandProcessingAggregate
,
Command
clasz, interceptor, missingApplyEventMethodStrategy
Constructor and Description |
---|
AggregateRepository(java.lang.Class<T> clasz,
EventuateAggregateStore aggregateStore)
Constructs a new AggregateRepository for the specified aggregate class and aggregate store
|
Modifier and Type | Method and Description |
---|---|
EntityWithMetadata<T> |
find(java.lang.String entityId)
Find an aggregate
|
EntityWithMetadata<T> |
find(java.lang.String entityId,
FindOptions findOptions)
Find an aggregate
|
EntityWithMetadata<T> |
find(java.lang.String entityId,
java.util.Optional<FindOptions> findOptions)
Find an aggregate
|
EntityWithIdAndVersion<T> |
save(CT cmd)
Create a new Aggregate by processing a command and persisting the events
|
EntityWithIdAndVersion<T> |
save(CT cmd,
java.util.Optional<SaveOptions> saveOptions)
Create a new Aggregate by processing a command and persisting the events
|
EntityWithIdAndVersion<T> |
update(java.lang.String entityId,
CT cmd)
Update the specified aggregate by processing a command and saving events
|
EntityWithIdAndVersion<T> |
update(java.lang.String entityId,
CT cmd,
java.util.Optional<UpdateOptions> updateOptions)
Update the specified aggregate by processing a command and saving events
|
EntityWithIdAndVersion<T> |
updateWithProvidedCommand(java.lang.String entityId,
java.util.function.Function<T,java.util.Optional<CT>> commandProvider,
java.util.Optional<UpdateOptions> updateOptions)
Update the specified aggregate by processing a command and saving events
|
setInterceptor, setMissingApplyEventMethodStrategy, transformUpdateEventsAndOptions
public AggregateRepository(java.lang.Class<T> clasz, EventuateAggregateStore aggregateStore)
clasz
- the class of the aggregateaggregateStore
- the aggregate storepublic EntityWithIdAndVersion<T> save(CT cmd)
cmd
- the command to processpublic EntityWithIdAndVersion<T> save(CT cmd, java.util.Optional<SaveOptions> saveOptions)
cmd
- the command to processsaveOptions
- creation optionspublic EntityWithIdAndVersion<T> update(java.lang.String entityId, CT cmd)
entityId
- the id of the aggregate to updatecmd
- the command to processpublic EntityWithIdAndVersion<T> update(java.lang.String entityId, CT cmd, java.util.Optional<UpdateOptions> updateOptions)
entityId
- the id of the aggregate to updatecmd
- the command to processupdateOptions
- options for updatingpublic EntityWithIdAndVersion<T> updateWithProvidedCommand(java.lang.String entityId, java.util.function.Function<T,java.util.Optional<CT>> commandProvider, java.util.Optional<UpdateOptions> updateOptions)
entityId
- the id of the aggregate to updatecommandProvider
- the provider of the command to processupdateOptions
- options for updatingpublic EntityWithMetadata<T> find(java.lang.String entityId)
entityId
- the id of the aggregate to findpublic EntityWithMetadata<T> find(java.lang.String entityId, FindOptions findOptions)
entityId
- the id of the aggregate to findfindOptions
- options for findingpublic EntityWithMetadata<T> find(java.lang.String entityId, java.util.Optional<FindOptions> findOptions)
entityId
- the id of the aggregate to findfindOptions
- options for finding