@Override public T createAggregateRoot(String aggregateIdentifier, DomainEventMessage<?> firstEvent) { return delegate.createAggregateRoot(aggregateIdentifier, firstEvent); }
@SuppressWarnings("unchecked") @Override protected DomainEventMessage createSnapshot(Class<?> aggregateType, String aggregateIdentifier, DomainEventStream eventStream) { DomainEventMessage firstEvent = eventStream.peek(); AggregateFactory<?> aggregateFactory = getAggregateFactory(aggregateType); if (aggregateFactory == null) { throw new IllegalArgumentException( "Aggregate Type is unknown in this snapshotter: " + aggregateType.getName() ); } aggregateModels.computeIfAbsent(aggregateType, k -> AnnotatedAggregateMetaModelFactory .inspectAggregate(k, parameterResolverFactory, handlerDefinition)); Object aggregateRoot = aggregateFactory.createAggregateRoot(aggregateIdentifier, firstEvent); SnapshotAggregate<Object> aggregate = new SnapshotAggregate(aggregateRoot, aggregateModels.get(aggregateType), repositoryProvider); aggregate.initializeState(eventStream); if (aggregate.isDeleted()) { return null; } return new GenericDomainEventMessage<>(aggregate.type(), aggregate.identifierAsString(), aggregate.version(), aggregate.getAggregateRoot()); }
"The aggregate was not found in the event store"); aggregateRoot = EventSourcedAggregate.initialize(aggregateFactory.createAggregateRoot( aggregateIdentifier, eventStream.peek()), model, eventStore, repositoryProvider, trigger );
/** * 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; }
@SuppressWarnings("unchecked") @Override protected DomainEventMessage createSnapshot(Class<?> aggregateType, String aggregateIdentifier, DomainEventStream eventStream) { DomainEventMessage firstEvent = eventStream.peek(); AggregateFactory<?> aggregateFactory = getAggregateFactory(aggregateType); if (aggregateFactory == null) { throw new IllegalArgumentException("Aggregate Type is unknown in this snapshotter: " + aggregateType.getName()); } aggregateModels.computeIfAbsent(aggregateType, k -> AnnotatedAggregateMetaModelFactory .inspectAggregate(k, parameterResolverFactory, handlerDefinition)); Object aggregateRoot = aggregateFactory.createAggregateRoot(aggregateIdentifier, firstEvent); SnapshotAggregate<Object> aggregate = new SnapshotAggregate(aggregateRoot, aggregateModels.get(aggregateType), repositoryProvider); aggregate.initializeState(eventStream); if (aggregate.isDeleted()) { return null; } return new GenericDomainEventMessage<>(aggregate.type(), aggregate.identifierAsString(), aggregate.version(), aggregate.getAggregateRoot()); }
@SuppressWarnings("unchecked") @Override protected DomainEventMessage createSnapshot(Class<?> aggregateType, String aggregateIdentifier, DomainEventStream eventStream) { DomainEventMessage firstEvent = eventStream.peek(); AggregateFactory<?> aggregateFactory = getAggregateFactory(aggregateType); if (aggregateFactory == null) { throw new IllegalArgumentException( "Aggregate Type is unknown in this snapshotter: " + aggregateType.getName() ); } aggregateModels.computeIfAbsent(aggregateType, k -> AnnotatedAggregateMetaModelFactory .inspectAggregate(k, parameterResolverFactory, handlerDefinition)); Object aggregateRoot = aggregateFactory.createAggregateRoot(aggregateIdentifier, firstEvent); SnapshotAggregate<Object> aggregate = new SnapshotAggregate(aggregateRoot, aggregateModels.get(aggregateType), repositoryProvider); aggregate.initializeState(eventStream); if (aggregate.isDeleted()) { return null; } return new GenericDomainEventMessage<>(aggregate.type(), aggregate.identifierAsString(), aggregate.version(), aggregate.getAggregateRoot()); }
"The aggregate was not found in the event store"); aggregateRoot = EventSourcedAggregate.initialize(aggregateFactory.createAggregateRoot( aggregateIdentifier, eventStream.peek()), model, eventStore, repositoryProvider, trigger );
"The aggregate was not found in the event store"); aggregateRoot = EventSourcedAggregate.initialize(aggregateFactory.createAggregateRoot( aggregateIdentifier, eventStream.peek()), model, eventStore, repositoryProvider, trigger );
/** * 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; }
/** * 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; }