io.fluxcapacitor.javaclient.eventsourcing.DefaultEventSourcingRepository Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-client Show documentation
Show all versions of java-client Show documentation
Default Java client library for interfacing with Flux Capacitor.
package io.fluxcapacitor.javaclient.eventsourcing;
import io.fluxcapacitor.javaclient.common.model.Model;
import lombok.AllArgsConstructor;
import static java.lang.String.format;
@AllArgsConstructor
public class DefaultEventSourcingRepository implements EventSourcingRepository {
private final EventSourcing eventSourcing;
private final Class modelClass;
@Override
public Model load(String modelId, Long expectedSequenceNumber) {
Model result = eventSourcing.load(modelId, modelClass);
if (expectedSequenceNumber != null && expectedSequenceNumber != result.getSequenceNumber()) {
throw new EventSourcingException(format(
"Failed to load %s of id %s. Expected sequence number %d but model had sequence number %d",
modelClass.getSimpleName(), modelId, expectedSequenceNumber, result.getSequenceNumber()));
}
return result;
}
}