/** * Initializes an EventSourcedAggregate instance for the given {@code aggregateRoot}, based on the given {@code * inspector}, which publishes events to the given {@code eventBus}. * * @param aggregateRoot The aggregate root instance * @param inspector The inspector describing the aggregate structure * @param eventBus The event bus to send generated events to * @param snapshotTrigger The trigger to notify of events and initialization * @param <T> the aggregate root type * @return the initialized EventSourcedAggregate instance */ public static <T> EventSourcedAggregate<T> initialize(T aggregateRoot, AggregateModel<T> inspector, EventBus eventBus, SnapshotTrigger snapshotTrigger) { return initialize(aggregateRoot, inspector, eventBus, null, snapshotTrigger); }
/** * Perform the actual loading of an aggregate. The necessary locks have been obtained. * * @param aggregateIdentifier the identifier of the aggregate to load * @param expectedVersion The expected version of the loaded aggregate * @return the fully initialized aggregate * * @throws AggregateDeletedException in case an aggregate existed in the past, but has been deleted * @throws AggregateNotFoundException when an aggregate with the given identifier does not exist */ @Override protected EventSourcedAggregate<T> doLoadWithLock(String aggregateIdentifier, Long expectedVersion) { DomainEventStream eventStream = readEvents(aggregateIdentifier); SnapshotTrigger trigger = snapshotTriggerDefinition.prepareTrigger(aggregateFactory.getAggregateType()); if (!eventStream.hasNext()) { throw new AggregateNotFoundException(aggregateIdentifier, "The aggregate was not found in the event store"); } EventSourcedAggregate<T> aggregate = EventSourcedAggregate .initialize(aggregateFactory.createAggregateRoot(aggregateIdentifier, eventStream.peek()), aggregateModel(), eventStore, repositoryProvider, trigger); aggregate.initializeState(eventStream); if (aggregate.isDeleted()) { throw new AggregateDeletedException(aggregateIdentifier); } return aggregate; }
"The aggregate was not found in the event store"); aggregateRoot = EventSourcedAggregate.initialize(aggregateFactory.createAggregateRoot( aggregateIdentifier, eventStream.peek()), model, eventStore, repositoryProvider, trigger );
/** * Initializes an EventSourcedAggregate instance using the given {@code aggregateFactory}, based on the given {@code * inspector}, which publishes events to the given {@code eventBus} and stores events in the given {@code * eventStore}. * * @param aggregateFactory The aggregate root factory * @param inspector The inspector describing the aggregate structure * @param eventBus The event bus to send generated events to * @param snapshotTrigger The trigger to notify of events and initialization * @param <T> the aggregate root type * @return the initialized EventSourcedAggregate instance * * @throws Exception if the aggregate cannot be initialized */ public static <T> EventSourcedAggregate<T> initialize(Callable<T> aggregateFactory, AggregateModel<T> inspector, EventBus eventBus, SnapshotTrigger snapshotTrigger) throws Exception { return initialize(aggregateFactory, inspector, eventBus, null, snapshotTrigger); }
/** * Perform the actual loading of an aggregate. The necessary locks have been obtained. * * @param aggregateIdentifier the identifier of the aggregate to load * @param expectedVersion The expected version of the loaded aggregate * @return the fully initialized aggregate * * @throws AggregateDeletedException in case an aggregate existed in the past, but has been deleted * @throws AggregateNotFoundException when an aggregate with the given identifier does not exist */ @Override protected EventSourcedAggregate<T> doLoadWithLock(String aggregateIdentifier, Long expectedVersion) { DomainEventStream eventStream = readEvents(aggregateIdentifier); SnapshotTrigger trigger = snapshotTriggerDefinition.prepareTrigger(aggregateFactory.getAggregateType()); if (!eventStream.hasNext()) { throw new AggregateNotFoundException(aggregateIdentifier, "The aggregate was not found in the event store"); } EventSourcedAggregate<T> aggregate = EventSourcedAggregate .initialize(aggregateFactory.createAggregateRoot(aggregateIdentifier, eventStream.peek()), aggregateModel(), eventStore, repositoryProvider, trigger); aggregate.initializeState(eventStream); if (aggregate.isDeleted()) { throw new AggregateDeletedException(aggregateIdentifier); } return aggregate; }
@Override protected EventSourcedAggregate<T> doCreateNewForLock(Callable<T> factoryMethod) throws Exception { return EventSourcedAggregate.initialize(factoryMethod, aggregateModel(), eventStore, repositoryProvider, snapshotTriggerDefinition.prepareTrigger(getAggregateType())); }
/** * Perform the actual loading of an aggregate. The necessary locks have been obtained. * * @param aggregateIdentifier the identifier of the aggregate to load * @param expectedVersion The expected version of the loaded aggregate * @return the fully initialized aggregate * @throws AggregateDeletedException in case an aggregate existed in the past, but has been deleted * @throws AggregateNotFoundException when an aggregate with the given identifier does not exist */ @Override protected EventSourcedAggregate<T> doLoadWithLock(String aggregateIdentifier, Long expectedVersion) { DomainEventStream eventStream = readEvents(aggregateIdentifier); SnapshotTrigger trigger = snapshotTriggerDefinition.prepareTrigger(aggregateFactory.getAggregateType()); if (!eventStream.hasNext()) { throw new AggregateNotFoundException(aggregateIdentifier, "The aggregate was not found in the event store"); } EventSourcedAggregate<T> aggregate = EventSourcedAggregate .initialize(aggregateFactory.createAggregateRoot(aggregateIdentifier, eventStream.peek()), aggregateModel(), eventStore, repositoryProvider, trigger); aggregate.initializeState(eventStream); if (aggregate.isDeleted()) { throw new AggregateDeletedException(aggregateIdentifier); } return aggregate; }
RepositoryProvider repositoryProvider, SnapshotTrigger snapshotTrigger) { EventSourcedAggregate<T> aggregate = initialize(aggregateRoot, model, eventBus,
"The aggregate was not found in the event store"); aggregateRoot = EventSourcedAggregate.initialize(aggregateFactory.createAggregateRoot( aggregateIdentifier, eventStream.peek()), model, eventStore, repositoryProvider, trigger );
@Override public Aggregate<T> newInstance(Callable<T> factoryMethod) throws Exception { SnapshotTrigger trigger = snapshotTriggerDefinition.prepareTrigger(aggregateFactory.getAggregateType()); EventSourcedAggregate<T> aggregate = EventSourcedAggregate.initialize(factoryMethod, model, eventStore, repositoryProvider, trigger); firstLevelCache.put(aggregate.identifierAsString(), aggregate); cache.put(aggregate.identifierAsString(), new AggregateCacheEntry<>(aggregate)); return aggregate; }
/** * Initializes an EventSourcedAggregate instance for the given {@code aggregateRoot}, based on the given {@code * inspector}, which publishes events to the given {@code eventBus}. * * @param aggregateRoot The aggregate root instance * @param inspector The inspector describing the aggregate structure * @param eventBus The event bus to send generated events to * @param snapshotTrigger The trigger to notify of events and initialization * @param <T> the aggregate root type * @return the initialized EventSourcedAggregate instance */ public static <T> EventSourcedAggregate<T> initialize(T aggregateRoot, AggregateModel<T> inspector, EventBus eventBus, SnapshotTrigger snapshotTrigger) { return initialize(aggregateRoot, inspector, eventBus, null, snapshotTrigger); }
/** * Initializes an EventSourcedAggregate instance for the given {@code aggregateRoot}, based on the given {@code * inspector}, which publishes events to the given {@code eventBus}. * * @param aggregateRoot The aggregate root instance * @param inspector The inspector describing the aggregate structure * @param eventBus The event bus to send generated events to * @param snapshotTrigger The trigger to notify of events and initialization * @param <T> the aggregate root type * @return the initialized EventSourcedAggregate instance */ public static <T> EventSourcedAggregate<T> initialize(T aggregateRoot, AggregateModel<T> inspector, EventBus eventBus, SnapshotTrigger snapshotTrigger) { return initialize(aggregateRoot, inspector, eventBus, null, snapshotTrigger); }
/** * Initializes an EventSourcedAggregate instance using the given {@code aggregateFactory}, based on the given {@code * inspector}, which publishes events to the given {@code eventBus} and stores events in the given {@code * eventStore}. * * @param aggregateFactory The aggregate root factory * @param inspector The inspector describing the aggregate structure * @param eventBus The event bus to send generated events to * @param snapshotTrigger The trigger to notify of events and initialization * @param <T> the aggregate root type * @return the initialized EventSourcedAggregate instance * * @throws Exception if the aggregate cannot be initialized */ public static <T> EventSourcedAggregate<T> initialize(Callable<T> aggregateFactory, AggregateModel<T> inspector, EventBus eventBus, SnapshotTrigger snapshotTrigger) throws Exception { return initialize(aggregateFactory, inspector, eventBus, null, snapshotTrigger); }
/** * Initializes an EventSourcedAggregate instance using the given {@code aggregateFactory}, based on the given {@code * inspector}, which publishes events to the given {@code eventBus} and stores events in the given {@code * eventStore}. * * @param aggregateFactory The aggregate root factory * @param inspector The inspector describing the aggregate structure * @param eventBus The event bus to send generated events to * @param snapshotTrigger The trigger to notify of events and initialization * @param <T> the aggregate root type * @return the initialized EventSourcedAggregate instance * * @throws Exception if the aggregate cannot be initialized */ public static <T> EventSourcedAggregate<T> initialize(Callable<T> aggregateFactory, AggregateModel<T> inspector, EventBus eventBus, SnapshotTrigger snapshotTrigger) throws Exception { return initialize(aggregateFactory, inspector, eventBus, null, snapshotTrigger); }
@Override protected EventSourcedAggregate<T> doCreateNewForLock(Callable<T> factoryMethod) throws Exception { return EventSourcedAggregate.initialize(factoryMethod, aggregateModel(), eventStore, repositoryProvider, snapshotTriggerDefinition.prepareTrigger(getAggregateType())); }
@Override protected EventSourcedAggregate<T> doCreateNewForLock(Callable<T> factoryMethod) throws Exception { return EventSourcedAggregate.initialize(factoryMethod, aggregateModel(), eventStore, repositoryProvider, snapshotTriggerDefinition.prepareTrigger(getAggregateType())); }
RepositoryProvider repositoryProvider, SnapshotTrigger snapshotTrigger) { EventSourcedAggregate<T> aggregate = initialize(aggregateRoot, model, eventBus,
RepositoryProvider repositoryProvider, SnapshotTrigger snapshotTrigger) { EventSourcedAggregate<T> aggregate = initialize(aggregateRoot, model, eventBus,
@Override public Aggregate<T> newInstance(Callable<T> factoryMethod) throws Exception { SnapshotTrigger trigger = snapshotTriggerDefinition.prepareTrigger(aggregateFactory.getAggregateType()); EventSourcedAggregate<T> aggregate = EventSourcedAggregate.initialize(factoryMethod, model, eventStore, repositoryProvider, trigger); firstLevelCache.put(aggregate.identifierAsString(), aggregate); cache.put(aggregate.identifierAsString(), new AggregateCacheEntry<>(aggregate)); return aggregate; }
@Override public Aggregate<T> newInstance(Callable<T> factoryMethod) throws Exception { SnapshotTrigger trigger = snapshotTriggerDefinition.prepareTrigger(aggregateFactory.getAggregateType()); EventSourcedAggregate<T> aggregate = EventSourcedAggregate.initialize(factoryMethod, model, eventStore, repositoryProvider, trigger); firstLevelCache.put(aggregate.identifierAsString(), aggregate); cache.put(aggregate.identifierAsString(), new AggregateCacheEntry<>(aggregate)); return aggregate; }