tech.ydb.core.operation.StatusMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ydb-sdk-core Show documentation
Show all versions of ydb-sdk-core Show documentation
Core module of Java SDK for YDB
package tech.ydb.core.operation;
import java.util.List;
import java.util.function.Function;
import tech.ydb.core.Issue;
import tech.ydb.core.Result;
import tech.ydb.core.Status;
import tech.ydb.core.StatusCode;
import tech.ydb.proto.StatusCodesProtos.StatusIds;
import tech.ydb.proto.YdbIssueMessage.IssueMessage;
public class StatusMapper implements Function, Status> {
private final Function statusMethod;
private final Function> issuesMethod;
private StatusMapper(Function status, Function> issues) {
this.statusMethod = status;
this.issuesMethod = issues;
}
@Override
public Status apply(Result result) {
if (!result.isSuccess()) {
return result.getStatus();
}
R resp = result.getValue();
return Status.of(
StatusCode.fromProto(statusMethod.apply(resp)),
result.getStatus().getConsumedRu(),
Issue.fromPb(issuesMethod.apply(resp))
);
}
public static StatusMapper of(
Function statusMethod,
Function> issuesMethod
) {
return new StatusMapper<>(statusMethod, issuesMethod);
}
}