@Override protected <R> Aggregate<R> doCreateNew(Class<R> aggregateType, Callable<R> factoryMethod) throws Exception { if (repositoryProvider == null) { throw new AxonConfigurationException(format( "Since repository provider is not provided, we cannot spawn a new aggregate for %s", aggregateType.getName())); } Repository<R> repository = repositoryProvider.repositoryFor(aggregateType); if (repository == null) { throw new IllegalStateException(format("There is no configured repository for %s", aggregateType.getName())); } return repository.newInstance(factoryMethod); }
@Override public Aggregate<T> newInstance(Callable<T> factoryMethod) throws Exception { CurrentUnitOfWork.get().onRollback(u -> this.rolledBack = true); aggregate = delegate.newInstance(factoryMethod); return aggregate; }
@CommandHandler public void handleIncomingMessage(String message) throws Exception { messageRepository.newInstance(() -> new Message(message)); }
@CommandHandler public void handleStubAggregateCreated(CreateStubAggregateCommand command) throws Exception { repository.newInstance(() -> new StubAggregate(command.getAggregateId())); }
@CommandHandler public MyAggregate handle(MyCommand command) throws Exception { Aggregate<MyAggregate> aggregate; try { aggregate = repository.load(command.getAggregateIdentifier()); } catch (AggregateNotFoundException e) { aggregate = repository.newInstance(() -> new MyAggregate(command.getAggregateIdentifier())); } aggregate.execute(a -> a.handle(command, commandGateway)); return aggregate.invoke(Function.identity()); } }
@Override protected <R> Aggregate<R> doCreateNew(Class<R> aggregateType, Callable<R> factoryMethod) throws Exception { if (repositoryProvider == null) { throw new AxonConfigurationException(format( "Since repository provider is not provided, we cannot spawn a new aggregate for %s", aggregateType.getName())); } Repository<R> repository = repositoryProvider.repositoryFor(aggregateType); if (repository == null) { throw new IllegalStateException(format("There is no configured repository for %s", aggregateType.getName())); } return repository.newInstance(factoryMethod); }