com.opencredo.concourse.domain.storing.ComposedEventStore Maven / Gradle / Ivy
package com.opencredo.concourse.domain.storing;
import com.opencredo.concourse.domain.common.AggregateId;
import com.opencredo.concourse.domain.events.Event;
import com.opencredo.concourse.domain.events.sourcing.EventRetriever;
import com.opencredo.concourse.domain.events.matching.EventTypeMatcher;
import com.opencredo.concourse.domain.persisting.EventPersister;
import com.opencredo.concourse.domain.time.TimeRange;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* An {@link EventStore} composed of an {@link EventPersister} and an {@link EventRetriever}.
*/
public final class ComposedEventStore implements EventStore {
/**
* Create a new {@link EventStore} composing the supplied {@link EventPersister} and {@link EventRetriever}.
* @param eventPersister The {@link EventPersister} to persist events with.
* @param eventRetriever The {@link EventRetriever} to retrieve events with.
* @return The composed {@link EventStore}.
*/
public static EventStore create(EventPersister eventPersister, EventRetriever eventRetriever) {
return new ComposedEventStore(eventPersister, eventRetriever);
}
private final EventPersister eventPersister;
private final EventRetriever eventRetriever;
private ComposedEventStore(EventPersister eventPersister, EventRetriever eventRetriever) {
this.eventPersister = eventPersister;
this.eventRetriever = eventRetriever;
}
@Override
public List getEvents(EventTypeMatcher matcher, AggregateId aggregateId, TimeRange timeRange) {
return eventRetriever.getEvents(matcher, aggregateId, timeRange);
}
@Override
public Map> getEvents(EventTypeMatcher matcher, String aggregateType, Collection aggregateIds, TimeRange timeRange) {
return eventRetriever.getEvents(matcher, aggregateType, aggregateIds, timeRange);
}
@Override
public void accept(Collection events) {
eventPersister.accept(events);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy