.aggregateModel(metaModel.get()) .aggregateFactory(aggregateFactory.get()) .eventStore(c.eventStore()) .snapshotTriggerDefinition(snapshotTriggerDefinition.get()) .repositoryProvider(c::repository) .build(); }); commandHandler = new Component<>(() -> parent, "aggregateCommandHandler<" + aggregate.getSimpleName() + ">",
.aggregateModel(metaModel.get()) .aggregateFactory(aggregateFactory.get()) .eventStore(c.eventStore()) .snapshotTriggerDefinition(snapshotTriggerDefinition.get()) .repositoryProvider(c::repository) .build(); }); commandHandler = new Component<>(() -> parent, "aggregateCommandHandler<" + aggregate.getSimpleName() + ">",
/** * Instantiate a Builder to be able to create a {@link EventSourcingRepository} for aggregate type {@code T}. * Can also be used to instantiate a {@link CachingEventSourcingRepository} for aggregate type {@code T}. This * Builder will check whether a {@link Cache} is provided. If this holds, the {@link Builder#build()} function * returns a CachingEventSourcingRepository instead of an EventSourcingRepository. * <p> * The {@link LockFactory} is defaulted to an {@link org.axonframework.common.lock.PessimisticLockFactory} and the * {@link SnapshotTriggerDefinition} to a {@link NoSnapshotTriggerDefinition} implementation. * A goal of this Builder goal is to create an {@link AggregateModel} specifying generic {@code T} as the aggregate * type to be stored. All aggregates in this repository must be {@code instanceOf} this aggregate type. To * instantiate this AggregateModel, either an {@link AggregateModel} can be provided directly or an * {@code aggregateType} of type {@link Class} can be used. The latter will internally resolve to an AggregateModel. * Thus, either the AggregateModel <b>or</b> the {@code aggregateType} should be provided. * The same criteria holds for the {@link AggregateFactory}. Either the AggregateFactory can be set directly or it * will be instantiated internally based on the {@code aggregateType}. Hence, one of both is a hard requirement. * <p> * Additionally, the {@link EventStore} is a <b>hard requirement</b> and as such should be provided. * * @return a Builder to be able to create a {@link EventSourcingRepository} */ public static <T> Builder<T> builder(Class<T> aggregateType) { return new Builder<>(aggregateType); }
@Bean public Repository<GiftCard> giftCardRepository(EventStore eventStore, Cache cache) { return EventSourcingRepository.builder(GiftCard.class) .cache(cache).eventStore(eventStore) .build(); }
/** * Instantiate a Builder to be able to create a {@link EventSourcingRepository} for aggregate type {@code T}. * Can also be used to instantiate a {@link CachingEventSourcingRepository} for aggregate type {@code T}. This * Builder will check whether a {@link Cache} is provided. If this holds, the {@link Builder#build()} function * returns a CachingEventSourcingRepository instead of an EventSourcingRepository. * <p> * The {@link LockFactory} is defaulted to an {@link org.axonframework.common.lock.PessimisticLockFactory} and the * {@link SnapshotTriggerDefinition} to a {@link NoSnapshotTriggerDefinition} implementation. * A goal of this Builder goal is to create an {@link AggregateModel} specifying generic {@code T} as the aggregate * type to be stored. All aggregates in this repository must be {@code instanceOf} this aggregate type. To * instantiate this AggregateModel, either an {@link AggregateModel} can be provided directly or an * {@code aggregateType} of type {@link Class} can be used. The latter will internally resolve to an AggregateModel. * Thus, either the AggregateModel <b>or</b> the {@code aggregateType} should be provided. * The same criteria holds for the {@link AggregateFactory}. Either the AggregateFactory can be set directly or it * will be instantiated internally based on the {@code aggregateType}. Hence, one of both is a hard requirement. * <p> * Additionally, the {@link EventStore} is a <b>hard requirement</b> and as such should be provided. * * @return a Builder to be able to create a {@link EventSourcingRepository} */ public static <T> Builder<T> builder(Class<T> aggregateType) { return new Builder<>(aggregateType); }
@SuppressWarnings("unchecked") @Before public void setUp() { eventStore = spy(EmbeddedEventStore.builder().storageEngine(new InMemoryEventStorageEngine()).build()); Repository<MyAggregate> myAggregateRepository = EventSourcingRepository.builder(MyAggregate.class) .eventStore(eventStore) .build(); CommandBus commandBus = SimpleCommandBus.builder().build(); commandGateway = DefaultCommandGateway.builder().commandBus(commandBus).build(); AggregateAnnotationCommandHandler<MyAggregate> myAggregateCommandHandler = AggregateAnnotationCommandHandler.<MyAggregate>builder() .aggregateType(MyAggregate.class) .repository(myAggregateRepository) .build(); myAggregateCommandHandler.subscribe(commandBus); }
@Override public FixtureConfiguration<T> registerAggregateFactory(AggregateFactory<T> aggregateFactory) { MultiParameterResolverFactory parameterResolverFactory = MultiParameterResolverFactory.ordered( new SimpleResourceParameterResolverFactory(resources), ClasspathParameterResolverFactory.forClass(aggregateType) ); return registerRepository(EventSourcingRepository.builder(aggregateFactory.getAggregateType()) .aggregateFactory(aggregateFactory) .eventStore(eventStore) .parameterResolverFactory(parameterResolverFactory) .handlerDefinition(handlerDefinition) .repositoryProvider(getRepositoryProvider()) .build()); }
@Test public void testInterceptorWithDeclaredChainAllowedToDeclareNonVoidReturnType() { EventSourcingRepository.builder(MyAggregateWithDeclaredInterceptorChainInterceptorReturningNonVoid.class) .eventStore(eventStore) .build(); }
@Before public void setUp() { this.commandBus = SimpleCommandBus.builder().build(); eventStore = spy(EmbeddedEventStore.builder().storageEngine(new InMemoryEventStorageEngine()).build()); EventSourcingRepository<StubAggregate> repository = EventSourcingRepository.builder(StubAggregate.class) .eventStore(eventStore) .build(); StubAggregateCommandHandler target = new StubAggregateCommandHandler(); target.setRepository(repository); target.setEventBus(eventStore); new AnnotationCommandHandlerAdapter<>(target).subscribe(commandBus); }
protected void initializeRepository(LockFactory lockingStrategy) { EventSourcingRepository<CountingAggregate> repository = EventSourcingRepository.builder(CountingAggregate.class) .lockFactory(lockingStrategy) .aggregateFactory(new GenericAggregateFactory<>(CountingAggregate.class)) .eventStore(eventStore) .build(); new AnnotationCommandHandlerAdapter<>(new CounterCommandHandler(repository)).subscribe(commandBus); }
@Test(expected = AxonConfigurationException.class) public void testInterceptorWithNonVoidReturnType() { EventSourcingRepository.builder(MyAggregateWithInterceptorReturningNonVoid.class) .eventStore(eventStore) .build(); }
@Before public void setUp() { stubEventStore = StubEventStore.builder().build(); repository = EventSourcingRepository.builder(StubAggregate.class) .eventStore(stubEventStore) .build(); aggregateIdentifier = "testAggregateIdentifier"; }
private void ensureRepositoryConfiguration() { if (repository == null) { registerRepository(EventSourcingRepository.builder(aggregateType) .aggregateFactory(new GenericAggregateFactory<>(aggregateType)) .eventStore(eventStore) .parameterResolverFactory(parameterResolverFactory) .handlerDefinition(handlerDefinition) .repositoryProvider(getRepositoryProvider()) .build()); } }