Skip to content

Commit 4143bb9

Browse files
chore(deps): Update gapic-generator-java to 2.26.0 (#2638)
* feat: add BatchWrite API PiperOrigin-RevId: 567412157 Source-Link: googleapis/googleapis@64fd42c Source-Link: https://github.com/googleapis/googleapis-gen/commit/9e53103ff3c06af94e583af7baa3c7fcafe78322 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiOWU1MzEwM2ZmM2MwNmFmOTRlNTgzYWY3YmFhM2M3ZmNhZmU3ODMyMiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore(deps): Update gapic-generator-java to 2.26.0 PiperOrigin-RevId: 567624307 Source-Link: googleapis/googleapis@2ecf4de Source-Link: https://github.com/googleapis/googleapis-gen/commit/a5cfbd9a05b3a134e92886114db776fb33cec9f2 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYTVjZmJkOWEwNWIzYTEzNGU5Mjg4NjExNGRiNzc2ZmIzM2NlYzlmMiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 2addb19 commit 4143bb9

File tree

20 files changed

+4670
-87
lines changed

20 files changed

+4670
-87
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/SpannerClient.java

+45
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import com.google.protobuf.Empty;
3333
import com.google.spanner.v1.BatchCreateSessionsRequest;
3434
import com.google.spanner.v1.BatchCreateSessionsResponse;
35+
import com.google.spanner.v1.BatchWriteRequest;
36+
import com.google.spanner.v1.BatchWriteResponse;
3537
import com.google.spanner.v1.BeginTransactionRequest;
3638
import com.google.spanner.v1.CommitRequest;
3739
import com.google.spanner.v1.CommitResponse;
@@ -2011,6 +2013,49 @@ public final UnaryCallable<PartitionReadRequest, PartitionResponse> partitionRea
20112013
return stub.partitionReadCallable();
20122014
}
20132015

2016+
// AUTO-GENERATED DOCUMENTATION AND METHOD.
2017+
/**
2018+
* Batches the supplied mutation groups in a collection of efficient transactions. All mutations
2019+
* in a group are committed atomically. However, mutations across groups can be committed
2020+
* non-atomically in an unspecified order and thus, they must be independent of each other.
2021+
* Partial failure is possible, i.e., some groups may have been committed successfully, while some
2022+
* may have failed. The results of individual batches are streamed into the response as the
2023+
* batches are applied.
2024+
*
2025+
* <p>BatchWrite requests are not replay protected, meaning that each mutation group may be
2026+
* applied more than once. Replays of non-idempotent mutations may have undesirable effects. For
2027+
* example, replays of an insert mutation may produce an already exists error or if you use
2028+
* generated or commit timestamp-based keys, it may result in additional rows being added to the
2029+
* mutation's table. We recommend structuring your mutation groups to be idempotent to avoid this
2030+
* issue.
2031+
*
2032+
* <p>Sample code:
2033+
*
2034+
* <pre>{@code
2035+
* // This snippet has been automatically generated and should be regarded as a code template only.
2036+
* // It will require modifications to work:
2037+
* // - It may require correct/in-range values for request initialization.
2038+
* // - It may require specifying regional endpoints when creating the service client as shown in
2039+
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
2040+
* try (SpannerClient spannerClient = SpannerClient.create()) {
2041+
* BatchWriteRequest request =
2042+
* BatchWriteRequest.newBuilder()
2043+
* .setSession(
2044+
* SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString())
2045+
* .setRequestOptions(RequestOptions.newBuilder().build())
2046+
* .addAllMutationGroups(new ArrayList<BatchWriteRequest.MutationGroup>())
2047+
* .build();
2048+
* ServerStream<BatchWriteResponse> stream = spannerClient.batchWriteCallable().call(request);
2049+
* for (BatchWriteResponse response : stream) {
2050+
* // Do something when a response is received.
2051+
* }
2052+
* }
2053+
* }</pre>
2054+
*/
2055+
public final ServerStreamingCallable<BatchWriteRequest, BatchWriteResponse> batchWriteCallable() {
2056+
return stub.batchWriteCallable();
2057+
}
2058+
20142059
@Override
20152060
public final void close() {
20162061
stub.close();

google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/SpannerSettings.java

+13
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import com.google.protobuf.Empty;
3636
import com.google.spanner.v1.BatchCreateSessionsRequest;
3737
import com.google.spanner.v1.BatchCreateSessionsResponse;
38+
import com.google.spanner.v1.BatchWriteRequest;
39+
import com.google.spanner.v1.BatchWriteResponse;
3840
import com.google.spanner.v1.BeginTransactionRequest;
3941
import com.google.spanner.v1.CommitRequest;
4042
import com.google.spanner.v1.CommitResponse;
@@ -177,6 +179,11 @@ public UnaryCallSettings<PartitionReadRequest, PartitionResponse> partitionReadS
177179
return ((SpannerStubSettings) getStubSettings()).partitionReadSettings();
178180
}
179181

182+
/** Returns the object with the settings used for calls to batchWrite. */
183+
public ServerStreamingCallSettings<BatchWriteRequest, BatchWriteResponse> batchWriteSettings() {
184+
return ((SpannerStubSettings) getStubSettings()).batchWriteSettings();
185+
}
186+
180187
public static final SpannerSettings create(SpannerStubSettings stub) throws IOException {
181188
return new SpannerSettings.Builder(stub.toBuilder()).build();
182189
}
@@ -375,6 +382,12 @@ public UnaryCallSettings.Builder<RollbackRequest, Empty> rollbackSettings() {
375382
return getStubSettingsBuilder().partitionReadSettings();
376383
}
377384

385+
/** Returns the builder for the settings used for calls to batchWrite. */
386+
public ServerStreamingCallSettings.Builder<BatchWriteRequest, BatchWriteResponse>
387+
batchWriteSettings() {
388+
return getStubSettingsBuilder().batchWriteSettings();
389+
}
390+
378391
@Override
379392
public SpannerSettings build() throws IOException {
380393
return new SpannerSettings(this);

google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/gapic_metadata.json

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"BatchCreateSessions": {
1414
"methods": ["batchCreateSessions", "batchCreateSessions", "batchCreateSessions", "batchCreateSessionsCallable"]
1515
},
16+
"BatchWrite": {
17+
"methods": ["batchWriteCallable"]
18+
},
1619
"BeginTransaction": {
1720
"methods": ["beginTransaction", "beginTransaction", "beginTransaction", "beginTransactionCallable"]
1821
},

google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/GrpcSpannerStub.java

+30
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import com.google.protobuf.Empty;
3131
import com.google.spanner.v1.BatchCreateSessionsRequest;
3232
import com.google.spanner.v1.BatchCreateSessionsResponse;
33+
import com.google.spanner.v1.BatchWriteRequest;
34+
import com.google.spanner.v1.BatchWriteResponse;
3335
import com.google.spanner.v1.BeginTransactionRequest;
3436
import com.google.spanner.v1.CommitRequest;
3537
import com.google.spanner.v1.CommitResponse;
@@ -202,6 +204,15 @@ public class GrpcSpannerStub extends SpannerStub {
202204
.setResponseMarshaller(ProtoUtils.marshaller(PartitionResponse.getDefaultInstance()))
203205
.build();
204206

207+
private static final MethodDescriptor<BatchWriteRequest, BatchWriteResponse>
208+
batchWriteMethodDescriptor =
209+
MethodDescriptor.<BatchWriteRequest, BatchWriteResponse>newBuilder()
210+
.setType(MethodDescriptor.MethodType.SERVER_STREAMING)
211+
.setFullMethodName("google.spanner.v1.Spanner/BatchWrite")
212+
.setRequestMarshaller(ProtoUtils.marshaller(BatchWriteRequest.getDefaultInstance()))
213+
.setResponseMarshaller(ProtoUtils.marshaller(BatchWriteResponse.getDefaultInstance()))
214+
.build();
215+
205216
private final UnaryCallable<CreateSessionRequest, Session> createSessionCallable;
206217
private final UnaryCallable<BatchCreateSessionsRequest, BatchCreateSessionsResponse>
207218
batchCreateSessionsCallable;
@@ -222,6 +233,7 @@ public class GrpcSpannerStub extends SpannerStub {
222233
private final UnaryCallable<RollbackRequest, Empty> rollbackCallable;
223234
private final UnaryCallable<PartitionQueryRequest, PartitionResponse> partitionQueryCallable;
224235
private final UnaryCallable<PartitionReadRequest, PartitionResponse> partitionReadCallable;
236+
private final ServerStreamingCallable<BatchWriteRequest, BatchWriteResponse> batchWriteCallable;
225237

226238
private final BackgroundResource backgroundResources;
227239
private final GrpcOperationsStub operationsStub;
@@ -414,6 +426,16 @@ protected GrpcSpannerStub(
414426
return builder.build();
415427
})
416428
.build();
429+
GrpcCallSettings<BatchWriteRequest, BatchWriteResponse> batchWriteTransportSettings =
430+
GrpcCallSettings.<BatchWriteRequest, BatchWriteResponse>newBuilder()
431+
.setMethodDescriptor(batchWriteMethodDescriptor)
432+
.setParamsExtractor(
433+
request -> {
434+
RequestParamsBuilder builder = RequestParamsBuilder.create();
435+
builder.add("session", String.valueOf(request.getSession()));
436+
return builder.build();
437+
})
438+
.build();
417439

418440
this.createSessionCallable =
419441
callableFactory.createUnaryCallable(
@@ -467,6 +489,9 @@ protected GrpcSpannerStub(
467489
this.partitionReadCallable =
468490
callableFactory.createUnaryCallable(
469491
partitionReadTransportSettings, settings.partitionReadSettings(), clientContext);
492+
this.batchWriteCallable =
493+
callableFactory.createServerStreamingCallable(
494+
batchWriteTransportSettings, settings.batchWriteSettings(), clientContext);
470495

471496
this.backgroundResources =
472497
new BackgroundResourceAggregation(clientContext.getBackgroundResources());
@@ -558,6 +583,11 @@ public UnaryCallable<PartitionReadRequest, PartitionResponse> partitionReadCalla
558583
return partitionReadCallable;
559584
}
560585

586+
@Override
587+
public ServerStreamingCallable<BatchWriteRequest, BatchWriteResponse> batchWriteCallable() {
588+
return batchWriteCallable;
589+
}
590+
561591
@Override
562592
public final void close() {
563593
try {

google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/HttpJsonSpannerStub.java

+60
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import com.google.protobuf.TypeRegistry;
3737
import com.google.spanner.v1.BatchCreateSessionsRequest;
3838
import com.google.spanner.v1.BatchCreateSessionsResponse;
39+
import com.google.spanner.v1.BatchWriteRequest;
40+
import com.google.spanner.v1.BatchWriteResponse;
3941
import com.google.spanner.v1.BeginTransactionRequest;
4042
import com.google.spanner.v1.CommitRequest;
4143
import com.google.spanner.v1.CommitResponse;
@@ -618,6 +620,43 @@ public class HttpJsonSpannerStub extends SpannerStub {
618620
.build())
619621
.build();
620622

623+
private static final ApiMethodDescriptor<BatchWriteRequest, BatchWriteResponse>
624+
batchWriteMethodDescriptor =
625+
ApiMethodDescriptor.<BatchWriteRequest, BatchWriteResponse>newBuilder()
626+
.setFullMethodName("google.spanner.v1.Spanner/BatchWrite")
627+
.setHttpMethod("POST")
628+
.setType(ApiMethodDescriptor.MethodType.SERVER_STREAMING)
629+
.setRequestFormatter(
630+
ProtoMessageRequestFormatter.<BatchWriteRequest>newBuilder()
631+
.setPath(
632+
"/v1/{session=projects/*/instances/*/databases/*/sessions/*}:batchWrite",
633+
request -> {
634+
Map<String, String> fields = new HashMap<>();
635+
ProtoRestSerializer<BatchWriteRequest> serializer =
636+
ProtoRestSerializer.create();
637+
serializer.putPathParam(fields, "session", request.getSession());
638+
return fields;
639+
})
640+
.setQueryParamsExtractor(
641+
request -> {
642+
Map<String, List<String>> fields = new HashMap<>();
643+
ProtoRestSerializer<BatchWriteRequest> serializer =
644+
ProtoRestSerializer.create();
645+
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
646+
return fields;
647+
})
648+
.setRequestBodyExtractor(
649+
request ->
650+
ProtoRestSerializer.create()
651+
.toBody("*", request.toBuilder().clearSession().build(), true))
652+
.build())
653+
.setResponseParser(
654+
ProtoMessageResponseParser.<BatchWriteResponse>newBuilder()
655+
.setDefaultInstance(BatchWriteResponse.getDefaultInstance())
656+
.setDefaultTypeRegistry(typeRegistry)
657+
.build())
658+
.build();
659+
621660
private final UnaryCallable<CreateSessionRequest, Session> createSessionCallable;
622661
private final UnaryCallable<BatchCreateSessionsRequest, BatchCreateSessionsResponse>
623662
batchCreateSessionsCallable;
@@ -638,6 +677,7 @@ public class HttpJsonSpannerStub extends SpannerStub {
638677
private final UnaryCallable<RollbackRequest, Empty> rollbackCallable;
639678
private final UnaryCallable<PartitionQueryRequest, PartitionResponse> partitionQueryCallable;
640679
private final UnaryCallable<PartitionReadRequest, PartitionResponse> partitionReadCallable;
680+
private final ServerStreamingCallable<BatchWriteRequest, BatchWriteResponse> batchWriteCallable;
641681

642682
private final BackgroundResource backgroundResources;
643683
private final HttpJsonStubCallableFactory callableFactory;
@@ -846,6 +886,17 @@ protected HttpJsonSpannerStub(
846886
return builder.build();
847887
})
848888
.build();
889+
HttpJsonCallSettings<BatchWriteRequest, BatchWriteResponse> batchWriteTransportSettings =
890+
HttpJsonCallSettings.<BatchWriteRequest, BatchWriteResponse>newBuilder()
891+
.setMethodDescriptor(batchWriteMethodDescriptor)
892+
.setTypeRegistry(typeRegistry)
893+
.setParamsExtractor(
894+
request -> {
895+
RequestParamsBuilder builder = RequestParamsBuilder.create();
896+
builder.add("session", String.valueOf(request.getSession()));
897+
return builder.build();
898+
})
899+
.build();
849900

850901
this.createSessionCallable =
851902
callableFactory.createUnaryCallable(
@@ -899,6 +950,9 @@ protected HttpJsonSpannerStub(
899950
this.partitionReadCallable =
900951
callableFactory.createUnaryCallable(
901952
partitionReadTransportSettings, settings.partitionReadSettings(), clientContext);
953+
this.batchWriteCallable =
954+
callableFactory.createServerStreamingCallable(
955+
batchWriteTransportSettings, settings.batchWriteSettings(), clientContext);
902956

903957
this.backgroundResources =
904958
new BackgroundResourceAggregation(clientContext.getBackgroundResources());
@@ -922,6 +976,7 @@ public static List<ApiMethodDescriptor> getMethodDescriptors() {
922976
methodDescriptors.add(rollbackMethodDescriptor);
923977
methodDescriptors.add(partitionQueryMethodDescriptor);
924978
methodDescriptors.add(partitionReadMethodDescriptor);
979+
methodDescriptors.add(batchWriteMethodDescriptor);
925980
return methodDescriptors;
926981
}
927982

@@ -1007,6 +1062,11 @@ public UnaryCallable<PartitionReadRequest, PartitionResponse> partitionReadCalla
10071062
return partitionReadCallable;
10081063
}
10091064

1065+
@Override
1066+
public ServerStreamingCallable<BatchWriteRequest, BatchWriteResponse> batchWriteCallable() {
1067+
return batchWriteCallable;
1068+
}
1069+
10101070
@Override
10111071
public final void close() {
10121072
try {

google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/SpannerStub.java

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import com.google.protobuf.Empty;
2525
import com.google.spanner.v1.BatchCreateSessionsRequest;
2626
import com.google.spanner.v1.BatchCreateSessionsResponse;
27+
import com.google.spanner.v1.BatchWriteRequest;
28+
import com.google.spanner.v1.BatchWriteResponse;
2729
import com.google.spanner.v1.BeginTransactionRequest;
2830
import com.google.spanner.v1.CommitRequest;
2931
import com.google.spanner.v1.CommitResponse;
@@ -121,6 +123,10 @@ public UnaryCallable<PartitionReadRequest, PartitionResponse> partitionReadCalla
121123
throw new UnsupportedOperationException("Not implemented: partitionReadCallable()");
122124
}
123125

126+
public ServerStreamingCallable<BatchWriteRequest, BatchWriteResponse> batchWriteCallable() {
127+
throw new UnsupportedOperationException("Not implemented: batchWriteCallable()");
128+
}
129+
124130
@Override
125131
public abstract void close();
126132
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/v1/stub/SpannerStubSettings.java

+25
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
import com.google.protobuf.Empty;
5252
import com.google.spanner.v1.BatchCreateSessionsRequest;
5353
import com.google.spanner.v1.BatchCreateSessionsResponse;
54+
import com.google.spanner.v1.BatchWriteRequest;
55+
import com.google.spanner.v1.BatchWriteResponse;
5456
import com.google.spanner.v1.BeginTransactionRequest;
5557
import com.google.spanner.v1.CommitRequest;
5658
import com.google.spanner.v1.CommitResponse;
@@ -141,6 +143,8 @@ public class SpannerStubSettings extends StubSettings<SpannerStubSettings> {
141143
private final UnaryCallSettings<RollbackRequest, Empty> rollbackSettings;
142144
private final UnaryCallSettings<PartitionQueryRequest, PartitionResponse> partitionQuerySettings;
143145
private final UnaryCallSettings<PartitionReadRequest, PartitionResponse> partitionReadSettings;
146+
private final ServerStreamingCallSettings<BatchWriteRequest, BatchWriteResponse>
147+
batchWriteSettings;
144148

145149
private static final PagedListDescriptor<ListSessionsRequest, ListSessionsResponse, Session>
146150
LIST_SESSIONS_PAGE_STR_DESC =
@@ -274,6 +278,11 @@ public UnaryCallSettings<PartitionReadRequest, PartitionResponse> partitionReadS
274278
return partitionReadSettings;
275279
}
276280

281+
/** Returns the object with the settings used for calls to batchWrite. */
282+
public ServerStreamingCallSettings<BatchWriteRequest, BatchWriteResponse> batchWriteSettings() {
283+
return batchWriteSettings;
284+
}
285+
277286
public SpannerStub createStub() throws IOException {
278287
if (getTransportChannelProvider()
279288
.getTransportName()
@@ -393,6 +402,7 @@ protected SpannerStubSettings(Builder settingsBuilder) throws IOException {
393402
rollbackSettings = settingsBuilder.rollbackSettings().build();
394403
partitionQuerySettings = settingsBuilder.partitionQuerySettings().build();
395404
partitionReadSettings = settingsBuilder.partitionReadSettings().build();
405+
batchWriteSettings = settingsBuilder.batchWriteSettings().build();
396406
}
397407

398408
/** Builder for SpannerStubSettings. */
@@ -422,6 +432,8 @@ public static class Builder extends StubSettings.Builder<SpannerStubSettings, Bu
422432
partitionQuerySettings;
423433
private final UnaryCallSettings.Builder<PartitionReadRequest, PartitionResponse>
424434
partitionReadSettings;
435+
private final ServerStreamingCallSettings.Builder<BatchWriteRequest, BatchWriteResponse>
436+
batchWriteSettings;
425437
private static final ImmutableMap<String, ImmutableSet<StatusCode.Code>>
426438
RETRYABLE_CODE_DEFINITIONS;
427439

@@ -513,6 +525,7 @@ protected Builder(ClientContext clientContext) {
513525
rollbackSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
514526
partitionQuerySettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
515527
partitionReadSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
528+
batchWriteSettings = ServerStreamingCallSettings.newBuilder();
516529

517530
unaryMethodSettingsBuilders =
518531
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
@@ -550,6 +563,7 @@ protected Builder(SpannerStubSettings settings) {
550563
rollbackSettings = settings.rollbackSettings.toBuilder();
551564
partitionQuerySettings = settings.partitionQuerySettings.toBuilder();
552565
partitionReadSettings = settings.partitionReadSettings.toBuilder();
566+
batchWriteSettings = settings.batchWriteSettings.toBuilder();
553567

554568
unaryMethodSettingsBuilders =
555569
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
@@ -670,6 +684,11 @@ private static Builder initDefaults(Builder builder) {
670684
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_3_codes"))
671685
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_3_params"));
672686

687+
builder
688+
.batchWriteSettings()
689+
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
690+
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
691+
673692
return builder;
674693
}
675694

@@ -772,6 +791,12 @@ public UnaryCallSettings.Builder<RollbackRequest, Empty> rollbackSettings() {
772791
return partitionReadSettings;
773792
}
774793

794+
/** Returns the builder for the settings used for calls to batchWrite. */
795+
public ServerStreamingCallSettings.Builder<BatchWriteRequest, BatchWriteResponse>
796+
batchWriteSettings() {
797+
return batchWriteSettings;
798+
}
799+
775800
@Override
776801
public SpannerStubSettings build() throws IOException {
777802
return new SpannerStubSettings(this);

0 commit comments

Comments
 (0)