tech.ydb.query.impl.QueryServiceRpc Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ydb-sdk-query Show documentation
Show all versions of ydb-sdk-query Show documentation
YDB QueryService client implementation
package tech.ydb.query.impl;
import java.util.concurrent.CompletableFuture;
import tech.ydb.core.Result;
import tech.ydb.core.grpc.GrpcReadStream;
import tech.ydb.core.grpc.GrpcRequestSettings;
import tech.ydb.core.grpc.GrpcTransport;
import tech.ydb.core.operation.StatusExtractor;
import tech.ydb.proto.OperationProtos;
import tech.ydb.proto.query.YdbQuery;
import tech.ydb.proto.query.v1.QueryServiceGrpc;
/**
*
* @author Aleksandr Gorshenin
*/
class QueryServiceRpc {
private static final StatusExtractor CREATE_SESSION = StatusExtractor.of(
YdbQuery.CreateSessionResponse::getStatus,
YdbQuery.CreateSessionResponse::getIssuesList
);
private static final StatusExtractor DELETE_SESSION = StatusExtractor.of(
YdbQuery.DeleteSessionResponse::getStatus,
YdbQuery.DeleteSessionResponse::getIssuesList
);
private static final StatusExtractor BEGIN_TX = StatusExtractor.of(
YdbQuery.BeginTransactionResponse::getStatus,
YdbQuery.BeginTransactionResponse::getIssuesList
);
private static final StatusExtractor COMMIT_TX = StatusExtractor.of(
YdbQuery.CommitTransactionResponse::getStatus,
YdbQuery.CommitTransactionResponse::getIssuesList
);
private static final StatusExtractor ROLLBACK_TX = StatusExtractor.of(
YdbQuery.RollbackTransactionResponse::getStatus,
YdbQuery.RollbackTransactionResponse::getIssuesList
);
private static final StatusExtractor FETCH_SCRIPT = StatusExtractor.of(
YdbQuery.FetchScriptResultsResponse::getStatus,
YdbQuery.FetchScriptResultsResponse::getIssuesList
);
private final GrpcTransport transport;
QueryServiceRpc(GrpcTransport transport) {
this.transport = transport;
}
public CompletableFuture> createSession(
YdbQuery.CreateSessionRequest request, GrpcRequestSettings settings) {
return transport
.unaryCall(QueryServiceGrpc.getCreateSessionMethod(), settings, request)
.thenApply(CREATE_SESSION);
}
public CompletableFuture> deleteSession(
YdbQuery.DeleteSessionRequest request, GrpcRequestSettings settings) {
return transport
.unaryCall(QueryServiceGrpc.getDeleteSessionMethod(), settings, request)
.thenApply(DELETE_SESSION);
}
public GrpcReadStream attachSession(
YdbQuery.AttachSessionRequest request, GrpcRequestSettings settings) {
return transport.readStreamCall(QueryServiceGrpc.getAttachSessionMethod(), settings, request);
}
public CompletableFuture> beginTransaction(
YdbQuery.BeginTransactionRequest request, GrpcRequestSettings settings) {
return transport
.unaryCall(QueryServiceGrpc.getBeginTransactionMethod(), settings, request)
.thenApply(BEGIN_TX);
}
public CompletableFuture> commitTransaction(
YdbQuery.CommitTransactionRequest request, GrpcRequestSettings settings) {
return transport
.unaryCall(QueryServiceGrpc.getCommitTransactionMethod(), settings, request)
.thenApply(COMMIT_TX);
}
public CompletableFuture> rollbackTransaction(
YdbQuery.RollbackTransactionRequest request, GrpcRequestSettings settings) {
return transport
.unaryCall(QueryServiceGrpc.getRollbackTransactionMethod(), settings, request)
.thenApply(ROLLBACK_TX);
}
public GrpcReadStream executeQuery(
YdbQuery.ExecuteQueryRequest request, GrpcRequestSettings settings) {
return transport.readStreamCall(QueryServiceGrpc.getExecuteQueryMethod(), settings, request);
}
public CompletableFuture> executeScript(
YdbQuery.ExecuteScriptRequest request, GrpcRequestSettings settings) {
return transport.unaryCall(QueryServiceGrpc.getExecuteScriptMethod(), settings, request);
}
public CompletableFuture> fetchScriptResults(
YdbQuery.FetchScriptResultsRequest request, GrpcRequestSettings settings) {
return transport
.unaryCall(QueryServiceGrpc.getFetchScriptResultsMethod(), settings, request)
.thenApply(FETCH_SCRIPT);
}
}