com.github.rahulsom.grooves.queries.internal.BaseQuery Maven / Gradle / Ivy
package com.github.rahulsom.grooves.queries.internal;
import com.github.rahulsom.grooves.api.AggregateType;
import com.github.rahulsom.grooves.api.EventApplyOutcome;
import com.github.rahulsom.grooves.api.events.BaseEvent;
import com.github.rahulsom.grooves.api.snapshots.internal.BaseSnapshot;
import org.jetbrains.annotations.NotNull;
import org.reactivestreams.Publisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
/**
* Aggregate trait that simplifies computing snapshots from events.
*
* @param The type of {@link AggregateT}'s id
* @param The aggregate over which the query executes
* @param The type of the {@link EventT}'s id field
* @param The type of the Event
* @param The type of the {@link SnapshotT}'s id field
* @param The type of the Snapshot
*
* @author Rahul Somasunderam
*/
public interface BaseQuery<
AggregateIdT,
AggregateT extends AggregateType,
EventIdT,
EventT extends BaseEvent,
SnapshotIdT,
SnapshotT extends BaseSnapshot
> {
default Logger getLog() {
return LoggerFactory.getLogger(getClass());
}
/**
* When no snapshot is found in the database, the query has to create the zero of the snapshot.
* This is the implementation of such a snapshot.
*
* @return The empty snapshot
*/
@NotNull SnapshotT createEmptySnapshot();
/**
* Decides whether applying more events is permitted on a snapshot.
*
* @param snapshot The snapshot
*
* @return whether more events can be applied
*/
boolean shouldEventsBeApplied(@NotNull SnapshotT snapshot);
/**
* Finds all events older than a given event.
*
* @param event The event before which events are eligible
*
* @return The list of events
*/
@NotNull Publisher findEventsBefore(@NotNull EventT event);
/**
* Adds an aggregate to the list of aggregates that are deprecated by the aggregate of a
* snapshot.
*
* @param snapshot The snapshot that points to the winning aggregate
* @param deprecatedAggregate The aggregate that is deprecated
*/
void addToDeprecates(@NotNull SnapshotT snapshot, @NotNull AggregateT deprecatedAggregate);
/**
* Exception handler when applying events.
*
* @param e The exception
* @param snapshot The snapshot
* @param event The event that resulted in an exception
*
* @return The outcome of handling the exception
*/
@NotNull Publisher onException(
@NotNull Exception e, @NotNull SnapshotT snapshot, @NotNull EventT event);
/**
* Provide an executor to execute the query
*
* @return An executor that applies events.
*/
@NotNull Executor getExecutor();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy