Class DefaultEventStoreTransaction
- All Implemented Interfaces:
EventStoreTransaction
EventStoreTransaction.
While sourcing it will map the SourcingCondition into an
AppendCondition for appending, taking into account several sourcing
invocation might have occurred in the same ProcessingContext. During
appending it will pass along a collection of events to an
EventStorageEngine is part of the prepare commit phase of the ProcessingContext.
- Since:
- 5.0.0
- Author:
- Steven van Beelen
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultEventStoreTransaction(EventStorageEngine eventStorageEngine, ProcessingContext processingContext, Function<EventMessage, TaggedEventMessage<?>> eventTagger) Constructs aDefaultEventStoreTransactionusing the giveneventStorageEnginetoappend eventsoriginating from the givencontext. -
Method Summary
Modifier and TypeMethodDescriptionvoidappendEvent(EventMessage eventMessage) Appends aneventMessageto be appended to anEventStorein this transaction with the givencondition.Returns the position in the event store of the lastappendedevent by this transaction.voidonAppend(Consumer<EventMessage> callback) Registers acallbackto invoke when an event isappendedto this transaction.MessageStream<? extends EventMessage> source(SourcingCondition condition) Sources aMessageStreamof typeEventMessagebased on the givenconditionthat can be used to rehydrate a model.
-
Constructor Details
-
DefaultEventStoreTransaction
public DefaultEventStoreTransaction(@Nonnull EventStorageEngine eventStorageEngine, @Nonnull ProcessingContext processingContext, @Nonnull Function<EventMessage, TaggedEventMessage<?>> eventTagger) Constructs aDefaultEventStoreTransactionusing the giveneventStorageEnginetoappend eventsoriginating from the givencontext.- Parameters:
eventStorageEngine- TheEventStorageEngineused toappend eventswith.processingContext- TheProcessingContextfrom which toappend eventsand attach resources to.eventTagger- A function that will process eachEventMessageto attachTags, before it is added to the transaction.
-
-
Method Details
-
source
Description copied from interface:EventStoreTransactionSources aMessageStreamof typeEventMessagebased on the givenconditionthat can be used to rehydrate a model.Note that the usage of
criteriadoes not make sense for sourcing, as it is not recommended to source the entire event store.Any
EventStoreTransactionusing theEventStorageEngine.source(SourcingCondition)is expected tofiltertheTerminalEventMessagewith theConsistencyMarker.- Specified by:
sourcein interfaceEventStoreTransaction- Parameters:
condition- TheSourcingConditionused to retrieve theMessageStreamcontaining the sequence of events that can rehydrate a model.- Returns:
- The
MessageStreamof typeEventMessagecontaining to the event sequence complying to the givencondition.
-
appendEvent
Description copied from interface:EventStoreTransactionAppends aneventMessageto be appended to anEventStorein this transaction with the givencondition.Use the
EventCriteria.havingAnyTag()when there are no consistency boundaries to validate during appending.- Specified by:
appendEventin interfaceEventStoreTransaction- Parameters:
eventMessage- TheEventMessageto append.
-
onAppend
Description copied from interface:EventStoreTransactionRegisters acallbackto invoke when an event isappendedto this transaction.Each
callbackregistration adds a new callback that is invoked on theappendEvent(EventMessage, AppendCondition)operation.- Specified by:
onAppendin interfaceEventStoreTransaction- Parameters:
callback- AConsumerto invoke when an event is appended in this transaction.
-
appendPosition
Description copied from interface:EventStoreTransactionReturns the position in the event store of the lastappendedevent by this transaction.Will return
ConsistencyMarker.ORIGINif nothing has been appended yet.- Specified by:
appendPositionin interfaceEventStoreTransaction- Returns:
- The position in the event store of the last
appendedevent by this transaction.
-