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

tech.ydb.core.operation.StatusMapper Maven / Gradle / Ivy

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy