com.google.cloud.spanner.v1.stub.HttpJsonSpannerStub Maven / Gradle / Ivy
Show all versions of google-cloud-spanner Show documentation
/*
* 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.core.InternalApi;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.core.BackgroundResourceAggregation;
import com.google.api.gax.httpjson.ApiMethodDescriptor;
import com.google.api.gax.httpjson.HttpJsonCallSettings;
import com.google.api.gax.httpjson.HttpJsonStubCallableFactory;
import com.google.api.gax.httpjson.ProtoMessageRequestFormatter;
import com.google.api.gax.httpjson.ProtoMessageResponseParser;
import com.google.api.gax.httpjson.ProtoRestSerializer;
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.protobuf.Empty;
import com.google.protobuf.TypeRegistry;
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 java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;
// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
* REST 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 HttpJsonSpannerStub extends SpannerStub {
private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build();
private static final ApiMethodDescriptor
createSessionMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.spanner.v1.Spanner/CreateSession")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{database=projects/*/instances/*/databases/*}/sessions",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "database", request.getDatabase());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearDatabase().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Session.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
batchCreateSessionsMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.spanner.v1.Spanner/BatchCreateSessions")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{database=projects/*/instances/*/databases/*}/sessions:batchCreate",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "database", request.getDatabase());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearDatabase().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(BatchCreateSessionsResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor getSessionMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.spanner.v1.Spanner/GetSession")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{name=projects/*/instances/*/databases/*/sessions/*}",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Session.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
listSessionsMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.spanner.v1.Spanner/ListSessions")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{database=projects/*/instances/*/databases/*}/sessions",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "database", request.getDatabase());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "filter", request.getFilter());
serializer.putQueryParam(fields, "pageSize", request.getPageSize());
serializer.putQueryParam(fields, "pageToken", request.getPageToken());
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(ListSessionsResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
deleteSessionMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.spanner.v1.Spanner/DeleteSession")
.setHttpMethod("DELETE")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{name=projects/*/instances/*/databases/*/sessions/*}",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Empty.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
executeSqlMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.spanner.v1.Spanner/ExecuteSql")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{session=projects/*/instances/*/databases/*/sessions/*}:executeSql",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "session", request.getSession());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearSession().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(ResultSet.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
executeStreamingSqlMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.spanner.v1.Spanner/ExecuteStreamingSql")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.SERVER_STREAMING)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{session=projects/*/instances/*/databases/*/sessions/*}:executeStreamingSql",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "session", request.getSession());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearSession().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(PartialResultSet.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
executeBatchDmlMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.spanner.v1.Spanner/ExecuteBatchDml")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{session=projects/*/instances/*/databases/*/sessions/*}:executeBatchDml",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "session", request.getSession());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearSession().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(ExecuteBatchDmlResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor readMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.spanner.v1.Spanner/Read")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{session=projects/*/instances/*/databases/*/sessions/*}:read",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer = ProtoRestSerializer.create();
serializer.putPathParam(fields, "session", request.getSession());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer = ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearSession().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(ResultSet.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
streamingReadMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.spanner.v1.Spanner/StreamingRead")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.SERVER_STREAMING)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{session=projects/*/instances/*/databases/*/sessions/*}:streamingRead",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "session", request.getSession());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearSession().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(PartialResultSet.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
beginTransactionMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.spanner.v1.Spanner/BeginTransaction")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{session=projects/*/instances/*/databases/*/sessions/*}:beginTransaction",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "session", request.getSession());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearSession().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Transaction.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor commitMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.spanner.v1.Spanner/Commit")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{session=projects/*/instances/*/databases/*/sessions/*}:commit",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "session", request.getSession());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearSession().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(CommitResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor rollbackMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.spanner.v1.Spanner/Rollback")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{session=projects/*/instances/*/databases/*/sessions/*}:rollback",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "session", request.getSession());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearSession().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Empty.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
partitionQueryMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.spanner.v1.Spanner/PartitionQuery")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{session=projects/*/instances/*/databases/*/sessions/*}:partitionQuery",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "session", request.getSession());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearSession().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(PartitionResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
partitionReadMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.spanner.v1.Spanner/PartitionRead")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{session=projects/*/instances/*/databases/*/sessions/*}:partitionRead",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "session", request.getSession());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearSession().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(PartitionResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
batchWriteMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.spanner.v1.Spanner/BatchWrite")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.SERVER_STREAMING)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{session=projects/*/instances/*/databases/*/sessions/*}:batchWrite",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "session", request.getSession());
return fields;
})
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearSession().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(BatchWriteResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.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 HttpJsonStubCallableFactory callableFactory;
public static final HttpJsonSpannerStub create(SpannerStubSettings settings) throws IOException {
return new HttpJsonSpannerStub(settings, ClientContext.create(settings));
}
public static final HttpJsonSpannerStub create(ClientContext clientContext) throws IOException {
return new HttpJsonSpannerStub(SpannerStubSettings.newHttpJsonBuilder().build(), clientContext);
}
public static final HttpJsonSpannerStub create(
ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException {
return new HttpJsonSpannerStub(
SpannerStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory);
}
/**
* Constructs an instance of HttpJsonSpannerStub, 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 HttpJsonSpannerStub(SpannerStubSettings settings, ClientContext clientContext)
throws IOException {
this(settings, clientContext, new HttpJsonSpannerCallableFactory());
}
/**
* Constructs an instance of HttpJsonSpannerStub, 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 HttpJsonSpannerStub(
SpannerStubSettings settings,
ClientContext clientContext,
HttpJsonStubCallableFactory callableFactory)
throws IOException {
this.callableFactory = callableFactory;
HttpJsonCallSettings createSessionTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(createSessionMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("database", String.valueOf(request.getDatabase()));
return builder.build();
})
.build();
HttpJsonCallSettings
batchCreateSessionsTransportSettings =
HttpJsonCallSettings
.newBuilder()
.setMethodDescriptor(batchCreateSessionsMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("database", String.valueOf(request.getDatabase()));
return builder.build();
})
.build();
HttpJsonCallSettings getSessionTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(getSessionMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings listSessionsTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(listSessionsMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("database", String.valueOf(request.getDatabase()));
return builder.build();
})
.build();
HttpJsonCallSettings deleteSessionTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(deleteSessionMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings executeSqlTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(executeSqlMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("session", String.valueOf(request.getSession()));
return builder.build();
})
.build();
HttpJsonCallSettings executeStreamingSqlTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(executeStreamingSqlMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("session", String.valueOf(request.getSession()));
return builder.build();
})
.build();
HttpJsonCallSettings
executeBatchDmlTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(executeBatchDmlMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("session", String.valueOf(request.getSession()));
return builder.build();
})
.build();
HttpJsonCallSettings readTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(readMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("session", String.valueOf(request.getSession()));
return builder.build();
})
.build();
HttpJsonCallSettings streamingReadTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(streamingReadMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("session", String.valueOf(request.getSession()));
return builder.build();
})
.build();
HttpJsonCallSettings beginTransactionTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(beginTransactionMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("session", String.valueOf(request.getSession()));
return builder.build();
})
.build();
HttpJsonCallSettings commitTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(commitMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("session", String.valueOf(request.getSession()));
return builder.build();
})
.build();
HttpJsonCallSettings rollbackTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(rollbackMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("session", String.valueOf(request.getSession()));
return builder.build();
})
.build();
HttpJsonCallSettings partitionQueryTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(partitionQueryMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("session", String.valueOf(request.getSession()));
return builder.build();
})
.build();
HttpJsonCallSettings partitionReadTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(partitionReadMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("session", String.valueOf(request.getSession()));
return builder.build();
})
.build();
HttpJsonCallSettings batchWriteTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(batchWriteMethodDescriptor)
.setTypeRegistry(typeRegistry)
.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());
}
@InternalApi
public static List getMethodDescriptors() {
List methodDescriptors = new ArrayList<>();
methodDescriptors.add(createSessionMethodDescriptor);
methodDescriptors.add(batchCreateSessionsMethodDescriptor);
methodDescriptors.add(getSessionMethodDescriptor);
methodDescriptors.add(listSessionsMethodDescriptor);
methodDescriptors.add(deleteSessionMethodDescriptor);
methodDescriptors.add(executeSqlMethodDescriptor);
methodDescriptors.add(executeStreamingSqlMethodDescriptor);
methodDescriptors.add(executeBatchDmlMethodDescriptor);
methodDescriptors.add(readMethodDescriptor);
methodDescriptors.add(streamingReadMethodDescriptor);
methodDescriptors.add(beginTransactionMethodDescriptor);
methodDescriptors.add(commitMethodDescriptor);
methodDescriptors.add(rollbackMethodDescriptor);
methodDescriptors.add(partitionQueryMethodDescriptor);
methodDescriptors.add(partitionReadMethodDescriptor);
methodDescriptors.add(batchWriteMethodDescriptor);
return methodDescriptors;
}
@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);
}
}