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

com.google.cloud.spanner.v1.stub.GrpcSpannerStub Maven / Gradle / Ivy

There is a newer version: 6.81.1
Show newest version
/*
 * Copyright 2024 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.cloud.spanner.v1.stub;

import static com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse;

import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.core.BackgroundResourceAggregation;
import com.google.api.gax.grpc.GrpcCallSettings;
import com.google.api.gax.grpc.GrpcStubCallableFactory;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.RequestParamsBuilder;
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.longrunning.stub.GrpcOperationsStub;
import com.google.protobuf.Empty;
import com.google.spanner.v1.BatchCreateSessionsRequest;
import com.google.spanner.v1.BatchCreateSessionsResponse;
import com.google.spanner.v1.BatchWriteRequest;
import com.google.spanner.v1.BatchWriteResponse;
import com.google.spanner.v1.BeginTransactionRequest;
import com.google.spanner.v1.CommitRequest;
import com.google.spanner.v1.CommitResponse;
import com.google.spanner.v1.CreateSessionRequest;
import com.google.spanner.v1.DeleteSessionRequest;
import com.google.spanner.v1.ExecuteBatchDmlRequest;
import com.google.spanner.v1.ExecuteBatchDmlResponse;
import com.google.spanner.v1.ExecuteSqlRequest;
import com.google.spanner.v1.GetSessionRequest;
import com.google.spanner.v1.ListSessionsRequest;
import com.google.spanner.v1.ListSessionsResponse;
import com.google.spanner.v1.PartialResultSet;
import com.google.spanner.v1.PartitionQueryRequest;
import com.google.spanner.v1.PartitionReadRequest;
import com.google.spanner.v1.PartitionResponse;
import com.google.spanner.v1.ReadRequest;
import com.google.spanner.v1.ResultSet;
import com.google.spanner.v1.RollbackRequest;
import com.google.spanner.v1.Session;
import com.google.spanner.v1.Transaction;
import io.grpc.MethodDescriptor;
import io.grpc.protobuf.ProtoUtils;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;

// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
 * gRPC stub implementation for the Spanner service API.
 *
 * 

This class is for advanced usage and reflects the underlying API directly. */ @Generated("by gapic-generator-java") public class GrpcSpannerStub extends SpannerStub { private static final MethodDescriptor createSessionMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.spanner.v1.Spanner/CreateSession") .setRequestMarshaller( ProtoUtils.marshaller(CreateSessionRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Session.getDefaultInstance())) .build(); private static final MethodDescriptor batchCreateSessionsMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.spanner.v1.Spanner/BatchCreateSessions") .setRequestMarshaller( ProtoUtils.marshaller(BatchCreateSessionsRequest.getDefaultInstance())) .setResponseMarshaller( ProtoUtils.marshaller(BatchCreateSessionsResponse.getDefaultInstance())) .build(); private static final MethodDescriptor getSessionMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.spanner.v1.Spanner/GetSession") .setRequestMarshaller(ProtoUtils.marshaller(GetSessionRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Session.getDefaultInstance())) .build(); private static final MethodDescriptor listSessionsMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.spanner.v1.Spanner/ListSessions") .setRequestMarshaller(ProtoUtils.marshaller(ListSessionsRequest.getDefaultInstance())) .setResponseMarshaller( ProtoUtils.marshaller(ListSessionsResponse.getDefaultInstance())) .build(); private static final MethodDescriptor deleteSessionMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.spanner.v1.Spanner/DeleteSession") .setRequestMarshaller(ProtoUtils.marshaller(DeleteSessionRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) .build(); private static final MethodDescriptor executeSqlMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.spanner.v1.Spanner/ExecuteSql") .setRequestMarshaller(ProtoUtils.marshaller(ExecuteSqlRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(ResultSet.getDefaultInstance())) .build(); private static final MethodDescriptor executeStreamingSqlMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.SERVER_STREAMING) .setFullMethodName("google.spanner.v1.Spanner/ExecuteStreamingSql") .setRequestMarshaller(ProtoUtils.marshaller(ExecuteSqlRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(PartialResultSet.getDefaultInstance())) .build(); private static final MethodDescriptor executeBatchDmlMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.spanner.v1.Spanner/ExecuteBatchDml") .setRequestMarshaller( ProtoUtils.marshaller(ExecuteBatchDmlRequest.getDefaultInstance())) .setResponseMarshaller( ProtoUtils.marshaller(ExecuteBatchDmlResponse.getDefaultInstance())) .build(); private static final MethodDescriptor readMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.spanner.v1.Spanner/Read") .setRequestMarshaller(ProtoUtils.marshaller(ReadRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(ResultSet.getDefaultInstance())) .build(); private static final MethodDescriptor streamingReadMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.SERVER_STREAMING) .setFullMethodName("google.spanner.v1.Spanner/StreamingRead") .setRequestMarshaller(ProtoUtils.marshaller(ReadRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(PartialResultSet.getDefaultInstance())) .build(); private static final MethodDescriptor beginTransactionMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.spanner.v1.Spanner/BeginTransaction") .setRequestMarshaller( ProtoUtils.marshaller(BeginTransactionRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Transaction.getDefaultInstance())) .build(); private static final MethodDescriptor commitMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.spanner.v1.Spanner/Commit") .setRequestMarshaller(ProtoUtils.marshaller(CommitRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(CommitResponse.getDefaultInstance())) .build(); private static final MethodDescriptor rollbackMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.spanner.v1.Spanner/Rollback") .setRequestMarshaller(ProtoUtils.marshaller(RollbackRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) .build(); private static final MethodDescriptor partitionQueryMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.spanner.v1.Spanner/PartitionQuery") .setRequestMarshaller( ProtoUtils.marshaller(PartitionQueryRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(PartitionResponse.getDefaultInstance())) .build(); private static final MethodDescriptor partitionReadMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) .setFullMethodName("google.spanner.v1.Spanner/PartitionRead") .setRequestMarshaller( ProtoUtils.marshaller(PartitionReadRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(PartitionResponse.getDefaultInstance())) .build(); private static final MethodDescriptor batchWriteMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.SERVER_STREAMING) .setFullMethodName("google.spanner.v1.Spanner/BatchWrite") .setRequestMarshaller(ProtoUtils.marshaller(BatchWriteRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(BatchWriteResponse.getDefaultInstance())) .build(); private final UnaryCallable createSessionCallable; private final UnaryCallable batchCreateSessionsCallable; private final UnaryCallable getSessionCallable; private final UnaryCallable listSessionsCallable; private final UnaryCallable listSessionsPagedCallable; private final UnaryCallable deleteSessionCallable; private final UnaryCallable executeSqlCallable; private final ServerStreamingCallable executeStreamingSqlCallable; private final UnaryCallable executeBatchDmlCallable; private final UnaryCallable readCallable; private final ServerStreamingCallable streamingReadCallable; private final UnaryCallable beginTransactionCallable; private final UnaryCallable commitCallable; private final UnaryCallable rollbackCallable; private final UnaryCallable partitionQueryCallable; private final UnaryCallable partitionReadCallable; private final ServerStreamingCallable batchWriteCallable; private final BackgroundResource backgroundResources; private final GrpcOperationsStub operationsStub; private final GrpcStubCallableFactory callableFactory; public static final GrpcSpannerStub create(SpannerStubSettings settings) throws IOException { return new GrpcSpannerStub(settings, ClientContext.create(settings)); } public static final GrpcSpannerStub create(ClientContext clientContext) throws IOException { return new GrpcSpannerStub(SpannerStubSettings.newBuilder().build(), clientContext); } public static final GrpcSpannerStub create( ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { return new GrpcSpannerStub( SpannerStubSettings.newBuilder().build(), clientContext, callableFactory); } /** * Constructs an instance of GrpcSpannerStub, using the given settings. This is protected so that * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. */ protected GrpcSpannerStub(SpannerStubSettings settings, ClientContext clientContext) throws IOException { this(settings, clientContext, new GrpcSpannerCallableFactory()); } /** * Constructs an instance of GrpcSpannerStub, using the given settings. This is protected so that * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. */ protected GrpcSpannerStub( SpannerStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { this.callableFactory = callableFactory; this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); GrpcCallSettings createSessionTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(createSessionMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("database", String.valueOf(request.getDatabase())); return builder.build(); }) .build(); GrpcCallSettings batchCreateSessionsTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(batchCreateSessionsMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("database", String.valueOf(request.getDatabase())); return builder.build(); }) .build(); GrpcCallSettings getSessionTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(getSessionMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("name", String.valueOf(request.getName())); return builder.build(); }) .build(); GrpcCallSettings listSessionsTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(listSessionsMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("database", String.valueOf(request.getDatabase())); return builder.build(); }) .build(); GrpcCallSettings deleteSessionTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(deleteSessionMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("name", String.valueOf(request.getName())); return builder.build(); }) .build(); GrpcCallSettings executeSqlTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(executeSqlMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("session", String.valueOf(request.getSession())); return builder.build(); }) .build(); GrpcCallSettings executeStreamingSqlTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(executeStreamingSqlMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("session", String.valueOf(request.getSession())); return builder.build(); }) .build(); GrpcCallSettings executeBatchDmlTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(executeBatchDmlMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("session", String.valueOf(request.getSession())); return builder.build(); }) .build(); GrpcCallSettings readTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(readMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("session", String.valueOf(request.getSession())); return builder.build(); }) .build(); GrpcCallSettings streamingReadTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(streamingReadMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("session", String.valueOf(request.getSession())); return builder.build(); }) .build(); GrpcCallSettings beginTransactionTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(beginTransactionMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("session", String.valueOf(request.getSession())); return builder.build(); }) .build(); GrpcCallSettings commitTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(commitMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("session", String.valueOf(request.getSession())); return builder.build(); }) .build(); GrpcCallSettings rollbackTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(rollbackMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("session", String.valueOf(request.getSession())); return builder.build(); }) .build(); GrpcCallSettings partitionQueryTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(partitionQueryMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("session", String.valueOf(request.getSession())); return builder.build(); }) .build(); GrpcCallSettings partitionReadTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(partitionReadMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("session", String.valueOf(request.getSession())); return builder.build(); }) .build(); GrpcCallSettings batchWriteTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(batchWriteMethodDescriptor) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("session", String.valueOf(request.getSession())); return builder.build(); }) .build(); this.createSessionCallable = callableFactory.createUnaryCallable( createSessionTransportSettings, settings.createSessionSettings(), clientContext); this.batchCreateSessionsCallable = callableFactory.createUnaryCallable( batchCreateSessionsTransportSettings, settings.batchCreateSessionsSettings(), clientContext); this.getSessionCallable = callableFactory.createUnaryCallable( getSessionTransportSettings, settings.getSessionSettings(), clientContext); this.listSessionsCallable = callableFactory.createUnaryCallable( listSessionsTransportSettings, settings.listSessionsSettings(), clientContext); this.listSessionsPagedCallable = callableFactory.createPagedCallable( listSessionsTransportSettings, settings.listSessionsSettings(), clientContext); this.deleteSessionCallable = callableFactory.createUnaryCallable( deleteSessionTransportSettings, settings.deleteSessionSettings(), clientContext); this.executeSqlCallable = callableFactory.createUnaryCallable( executeSqlTransportSettings, settings.executeSqlSettings(), clientContext); this.executeStreamingSqlCallable = callableFactory.createServerStreamingCallable( executeStreamingSqlTransportSettings, settings.executeStreamingSqlSettings(), clientContext); this.executeBatchDmlCallable = callableFactory.createUnaryCallable( executeBatchDmlTransportSettings, settings.executeBatchDmlSettings(), clientContext); this.readCallable = callableFactory.createUnaryCallable( readTransportSettings, settings.readSettings(), clientContext); this.streamingReadCallable = callableFactory.createServerStreamingCallable( streamingReadTransportSettings, settings.streamingReadSettings(), clientContext); this.beginTransactionCallable = callableFactory.createUnaryCallable( beginTransactionTransportSettings, settings.beginTransactionSettings(), clientContext); this.commitCallable = callableFactory.createUnaryCallable( commitTransportSettings, settings.commitSettings(), clientContext); this.rollbackCallable = callableFactory.createUnaryCallable( rollbackTransportSettings, settings.rollbackSettings(), clientContext); this.partitionQueryCallable = callableFactory.createUnaryCallable( partitionQueryTransportSettings, settings.partitionQuerySettings(), clientContext); this.partitionReadCallable = callableFactory.createUnaryCallable( partitionReadTransportSettings, settings.partitionReadSettings(), clientContext); this.batchWriteCallable = callableFactory.createServerStreamingCallable( batchWriteTransportSettings, settings.batchWriteSettings(), clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); } public GrpcOperationsStub getOperationsStub() { return operationsStub; } @Override public UnaryCallable createSessionCallable() { return createSessionCallable; } @Override public UnaryCallable batchCreateSessionsCallable() { return batchCreateSessionsCallable; } @Override public UnaryCallable getSessionCallable() { return getSessionCallable; } @Override public UnaryCallable listSessionsCallable() { return listSessionsCallable; } @Override public UnaryCallable listSessionsPagedCallable() { return listSessionsPagedCallable; } @Override public UnaryCallable deleteSessionCallable() { return deleteSessionCallable; } @Override public UnaryCallable executeSqlCallable() { return executeSqlCallable; } @Override public ServerStreamingCallable executeStreamingSqlCallable() { return executeStreamingSqlCallable; } @Override public UnaryCallable executeBatchDmlCallable() { return executeBatchDmlCallable; } @Override public UnaryCallable readCallable() { return readCallable; } @Override public ServerStreamingCallable streamingReadCallable() { return streamingReadCallable; } @Override public UnaryCallable beginTransactionCallable() { return beginTransactionCallable; } @Override public UnaryCallable commitCallable() { return commitCallable; } @Override public UnaryCallable rollbackCallable() { return rollbackCallable; } @Override public UnaryCallable partitionQueryCallable() { return partitionQueryCallable; } @Override public UnaryCallable partitionReadCallable() { return partitionReadCallable; } @Override public ServerStreamingCallable batchWriteCallable() { return batchWriteCallable; } @Override public final void close() { try { backgroundResources.close(); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalStateException("Failed to close resource", e); } } @Override public void shutdown() { backgroundResources.shutdown(); } @Override public boolean isShutdown() { return backgroundResources.isShutdown(); } @Override public boolean isTerminated() { return backgroundResources.isTerminated(); } @Override public void shutdownNow() { backgroundResources.shutdownNow(); } @Override public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { return backgroundResources.awaitTermination(duration, unit); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy