org.babyfish.jimmer.sql.ast.mutation.BatchSaveResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jimmer-sql Show documentation
Show all versions of jimmer-sql Show documentation
A revolutionary ORM framework for both java and kotlin
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;
}
}