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

org.fluentjdbc.DatabaseSaveResult Maven / Gradle / Ivy

There is a newer version: 0.5.3
Show newest version
package org.fluentjdbc;

import javax.annotation.Nonnull;
import java.util.Objects;

public class DatabaseSaveResult {
    private final T idValue;
    private final SaveStatus saveStatus;

    private DatabaseSaveResult(T idValue, SaveStatus saveStatus) {
        this.idValue = idValue;
        this.saveStatus = saveStatus;
    }

    public static  DatabaseSaveResult updated(@Nonnull T idValue) {
        return new DatabaseSaveResult<>(idValue, SaveStatus.UPDATED);
    }

    public static  DatabaseSaveResult inserted(@Nonnull T idValue) {
        return new DatabaseSaveResult<>(idValue, SaveStatus.INSERTED);
    }

    public static  DatabaseSaveResult deleted(@Nonnull T idValue) {
        return new DatabaseSaveResult<>(idValue, SaveStatus.DELETED);
    }

    public static  DatabaseSaveResult unchanged(@Nonnull T idValue) {
        return new DatabaseSaveResult<>(idValue, SaveStatus.UNCHANGED);
    }

    public T getId() {
        return idValue;
    }

    public SaveStatus getSaveStatus() {
        return saveStatus;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        DatabaseSaveResult that = (DatabaseSaveResult) o;
        return Objects.equals(idValue, that.idValue) &&
                saveStatus == that.saveStatus;
    }

    @Override
    public int hashCode() {
        return Objects.hash(idValue, saveStatus);
    }

    @Override
    public String toString() {
        return getClass().getSimpleName() + "{idValue=" + idValue + ", saveStatus=" + saveStatus + '}';
    }

    public enum SaveStatus {
        INSERTED, UNCHANGED, DELETED, UPDATED
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy