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

org.babyfish.jimmer.sql.ast.mutation.BatchSaveResult Maven / Gradle / Ivy

There is a newer version: 0.9.19
Show newest version
package org.babyfish.jimmer.sql.ast.mutation;

import java.util.*;

public class BatchSaveResult extends AbstractMutationResult {

    private List> simpleResults;

    public BatchSaveResult(
            List> simpleResults
    ) {
        this(mergedAffectedRowCount(simpleResults), simpleResults);
    }

    public BatchSaveResult(
            Map affectedRowMap,
            List> simpleResults
    ) {
        super(affectedRowMap);
        this.simpleResults = Collections.unmodifiableList(simpleResults);
    }

    public List> getSimpleResults() {
        return simpleResults;
    }

    @Override
    public int hashCode() {
        return Objects.hash(affectedRowCountMap, simpleResults);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        BatchSaveResult that = (BatchSaveResult) o;
        return affectedRowCountMap.equals(that.affectedRowCountMap) &&
                simpleResults.equals(that.simpleResults);
    }

    @Override
    public String toString() {
        return "BatchSaveResult{" +
                "totalAffectedRowCount=" + totalAffectedRowCount +
                ", affectedRowCountMap=" + affectedRowCountMap +
                ", simpleResults=" + simpleResults +
                '}';
    }

    private static  Map mergedAffectedRowCount(
            List> simpleResults
    ) {
        if (simpleResults.isEmpty()) {
            return Collections.emptyMap();
        }
        if (simpleResults.size() == 1) {
            return simpleResults.get(0).getAffectedRowCountMap();
        }
        Map mergedMap = new HashMap<>();
        for (SimpleSaveResult result : simpleResults) {
            for (Map.Entry e : result.getAffectedRowCountMap().entrySet()) {
                mergedMap.merge(e.getKey(), e.getValue(), Integer::sum);
            }
        }
        return mergedMap;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy