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

com.yandex.ydb.core.Operations Maven / Gradle / Ivy

The newest version!
package com.yandex.ydb.core;

import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Message;
import com.yandex.ydb.OperationProtos.Operation;
import com.yandex.ydb.StatusCodesProtos.StatusIds;


/**
 * @author Sergey Polovko
 */
public final class Operations {
    private Operations() {}

    public static Status status(Operation operation) {
        if (operation.getStatus() == StatusIds.StatusCode.SUCCESS && operation.getIssuesCount() == 0) {
            return Status.SUCCESS;
        }
        StatusCode code = StatusCode.fromProto(operation.getStatus());
        return Status.of(code, Issue.fromPb(operation.getIssuesList()));
    }

    public static  M unpackResult(Operation operation, Class clazz) {
        try {
            return operation.getResult().unpack(clazz);
        } catch (InvalidProtocolBufferException e) {
            throw new RuntimeException("cannot unpack result of operation: " + operation.getId(), e);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy