All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.fluxcapacitor.javaclient.eventsourcing.DefaultEventSourcingRepository Maven / Gradle / Ivy

There is a newer version: 0.1015.0
Show newest version
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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy