/** * Instantiate the {@link AggregateFactory} of generic type {@code T} for the Aggregate this * {@link EventSourcingRepository} will instantiate based on an event stream. * * @return a {@link AggregateFactory} of generic type {@code T} for the Aggregate this * {@link EventSourcingRepository} will instantiate based on an event stream */ private AggregateFactory<T> buildAggregateFactory() { if (aggregateFactory == null) { return new GenericAggregateFactory<>(aggregateType); } else { return aggregateFactory; } }
/** * {@inheritDoc} * <p> * * @throws IncompatibleAggregateException if the aggregate constructor throws an exception, or if the JVM security * settings prevent the GenericAggregateFactory from calling the * constructor. */ @SuppressWarnings({"unchecked"}) @Override protected T doCreateAggregate(String aggregateIdentifier, DomainEventMessage firstEvent) { try { return constructor.newInstance(); } catch (InstantiationException e) { throw new IncompatibleAggregateException(format( "The aggregate [%s] does not have a suitable no-arg constructor.", getAggregateType().getSimpleName()), e); } catch (IllegalAccessException e) { throw new IncompatibleAggregateException(format( "The aggregate no-arg constructor of the aggregate [%s] is not accessible. Please ensure that " + "the constructor is public or that the Security Manager allows access through " + "reflection.", getAggregateType().getSimpleName()), e); } catch (InvocationTargetException e) { throw new IncompatibleAggregateException(format( "The no-arg constructor of [%s] threw an exception on invocation.", getAggregateType().getSimpleName()), e); } } }
private void ensureRepositoryConfiguration() { if (repository == null) { registerRepository(EventSourcingRepository.builder(aggregateType) .aggregateFactory(new GenericAggregateFactory<>(aggregateType)) .eventStore(eventStore) .parameterResolverFactory(parameterResolverFactory) .handlerDefinition(handlerDefinition) .repositoryProvider(getRepositoryProvider()) .build()); } }
/** * {@inheritDoc} * <p> * * @throws IncompatibleAggregateException if the aggregate constructor throws an exception, or if the JVM security * settings prevent the GenericAggregateFactory from calling the * constructor. */ @SuppressWarnings({"unchecked"}) @Override protected T doCreateAggregate(String aggregateIdentifier, DomainEventMessage firstEvent) { try { return constructor.newInstance(); } catch (InstantiationException e) { throw new IncompatibleAggregateException(format( "The aggregate [%s] does not have a suitable no-arg constructor.", getAggregateType().getSimpleName()), e); } catch (IllegalAccessException e) { throw new IncompatibleAggregateException(format( "The aggregate no-arg constructor of the aggregate [%s] is not accessible. Please ensure that " + "the constructor is public or that the Security Manager allows access through " + "reflection.", getAggregateType().getSimpleName()), e); } catch (InvocationTargetException e) { throw new IncompatibleAggregateException(format( "The no-arg constructor of [%s] threw an exception on invocation.", getAggregateType().getSimpleName()), e); } } }
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); }
/** * {@inheritDoc} * <p> * * @throws IncompatibleAggregateException if the aggregate constructor throws an exception, or if the JVM security * settings prevent the GenericAggregateFactory from calling the * constructor. */ @SuppressWarnings({"unchecked"}) @Override protected T doCreateAggregate(String aggregateIdentifier, DomainEventMessage firstEvent) { try { return constructor.newInstance(); } catch (InstantiationException e) { throw new IncompatibleAggregateException(format( "The aggregate [%s] does not have a suitable no-arg constructor.", getAggregateType().getSimpleName()), e); } catch (IllegalAccessException e) { throw new IncompatibleAggregateException(format( "The aggregate no-arg constructor of the aggregate [%s] is not accessible. Please ensure that " + "the constructor is public or that the Security Manager allows access through " + "reflection.", getAggregateType().getSimpleName()), e); } catch (InvocationTargetException e) { throw new IncompatibleAggregateException(format( "The no-arg constructor of [%s] threw an exception on invocation.", getAggregateType().getSimpleName()), e); } } }
c -> NoSnapshotTriggerDefinition.INSTANCE); aggregateFactory = new Component<>(() -> parent, name("aggregateFactory"), c -> new GenericAggregateFactory<>(aggregate)); repository = new Component<>( () -> parent,
/** * Initializes a repository with the default locking strategy, using a GenericAggregateFactory to create new * aggregate instances of given {@code aggregateType}. * * @param aggregateType The type of aggregate stored in this repository * @param eventStore The event store that holds the event streams for this repository * @param snapshotTriggerDefinition The definition describing when to trigger a snapshot * @see LockingRepository#LockingRepository(Class) */ public EventSourcingRepository(final Class<T> aggregateType, EventStore eventStore, SnapshotTriggerDefinition snapshotTriggerDefinition) { this(new GenericAggregateFactory<>(aggregateType), eventStore, snapshotTriggerDefinition); }
/** * Initializes a repository with the default locking strategy, using a GenericAggregateFactory to create new * aggregate instances of given {@code aggregateType}. * * @param aggregateType The type of aggregate stored in this repository * @param eventStore The event store that holds the event streams for this repository * @see LockingRepository#LockingRepository(Class) */ public EventSourcingRepository(final Class<T> aggregateType, EventStore eventStore) { this(new GenericAggregateFactory<>(aggregateType), eventStore, NoSnapshotTriggerDefinition.INSTANCE); }
/** * Initializes a repository with the default locking strategy, using a GenericAggregateFactory to create new * aggregate instances of given {@code aggregateType}. * * @param aggregateType The type of aggregate stored in this repository * @param eventStore The event store that holds the event streams for this repository * @param snapshotTriggerDefinition The definition describing when to trigger a snapshot * @param repositoryProvider Provides repositories for specific aggregate types * @see LockingRepository#LockingRepository(Class) */ public EventSourcingRepository(final Class<T> aggregateType, EventStore eventStore, SnapshotTriggerDefinition snapshotTriggerDefinition, RepositoryProvider repositoryProvider) { this(new GenericAggregateFactory<>(aggregateType), eventStore, snapshotTriggerDefinition, repositoryProvider); }
/** * Instantiate the {@link AggregateFactory} of generic type {@code T} for the Aggregate this * {@link EventSourcingRepository} will instantiate based on an event stream. * * @return a {@link AggregateFactory} of generic type {@code T} for the Aggregate this * {@link EventSourcingRepository} will instantiate based on an event stream */ private AggregateFactory<T> buildAggregateFactory() { if (aggregateFactory == null) { return new GenericAggregateFactory<>(aggregateType); } else { return aggregateFactory; } }
/** * Initializes a repository with the default locking strategy, using a GenericAggregateFactory to create new * aggregate instances of given {@code aggregateType}. * * @param aggregateType The type of aggregate stored in this repository * @param eventStore The event store that holds the event streams for this repository * @param repositoryProvider Provides repositories for specific aggregate types * @see LockingRepository#LockingRepository(Class) */ public EventSourcingRepository(final Class<T> aggregateType, EventStore eventStore, RepositoryProvider repositoryProvider) { this(new GenericAggregateFactory<>(aggregateType), eventStore, NoSnapshotTriggerDefinition.INSTANCE, repositoryProvider); }
@Inject public DefaultCommandGatewayProvider(EventStore eventStore, EventBus eventBus) { DisruptorConfiguration configuration = new DisruptorConfiguration(); configuration.setCommandTargetResolver(new AnnotationCommandTargetResolver()); commandBus = new DisruptorCommandBus(eventStore, eventBus, configuration); repository = commandBus.createRepository(new GenericAggregateFactory(Exchange.class)); registerCommandHandlers(); }
c -> NoSnapshotTriggerDefinition.INSTANCE); aggregateFactory = new Component<>(() -> parent, name("aggregateFactory"), c -> new GenericAggregateFactory<>(aggregate)); repository = new Component<>(() -> parent, "Repository<" + aggregate.getSimpleName() + ">", c -> { Assert.state(c.eventBus() instanceof EventStore,
c -> NoSnapshotTriggerDefinition.INSTANCE); aggregateFactory = new Component<>(() -> parent, name("aggregateFactory"), c -> new GenericAggregateFactory<>(aggregate)); repository = new Component<>( () -> parent,