public Builder mergeFrom(com.google.spanner.v1.RollbackRequest other) { if (other == com.google.spanner.v1.RollbackRequest.getDefaultInstance()) return this; if (!other.getSession().isEmpty()) { session_ = other.session_; onChanged(); } if (other.getTransactionId() != com.google.protobuf.ByteString.EMPTY) { setTransactionId(other.getTransactionId()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
@java.lang.Override public Builder newBuilderForType() { return newBuilder(); }
@java.lang.Override public com.google.spanner.v1.RollbackRequest buildPartial() { com.google.spanner.v1.RollbackRequest result = new com.google.spanner.v1.RollbackRequest(this); result.session_ = session_; result.transactionId_ = transactionId_; onBuilt(); return result; }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.spanner.v1.RollbackRequest)) { return super.equals(obj); } com.google.spanner.v1.RollbackRequest other = (com.google.spanner.v1.RollbackRequest) obj; boolean result = true; result = result && getSession().equals(other.getSession()); result = result && getTransactionId().equals(other.getTransactionId()); result = result && unknownFields.equals(other.unknownFields); return result; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + SESSION_FIELD_NUMBER; hash = (53 * hash) + getSession().hashCode(); hash = (37 * hash) + TRANSACTION_ID_FIELD_NUMBER; hash = (53 * hash) + getTransactionId().hashCode(); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
/** * * * <pre> * Required. The transaction to roll back. * </pre> * * <code>bytes transaction_id = 2;</code> */ public Builder clearTransactionId() { transactionId_ = getDefaultInstance().getTransactionId(); onChanged(); return this; }
/** * * * <pre> * Required. The session in which the transaction to roll back is running. * </pre> * * <code>string session = 1;</code> */ public Builder clearSession() { session_ = getDefaultInstance().getSession(); onChanged(); return this; } /**
@Override public void rollback(RollbackRequest request, @Nullable Map<Option, ?> options) throws SpannerException { GrpcCallContext context = newCallContext(options, request.getSession()); get(spannerStub.rollbackCallable().futureCall(request, context)); }
@java.lang.Override public com.google.spanner.v1.RollbackRequest getDefaultInstanceForType() { return com.google.spanner.v1.RollbackRequest.getDefaultInstance(); }
if (!parseUnknownFieldProto3(input, unknownFields, extensionRegistry, tag)) { done = true; } finally { this.unknownFields = unknownFields.build(); makeExtensionsImmutable();
@java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (!getSessionBytes().isEmpty()) { com.google.protobuf.GeneratedMessageV3.writeString(output, 1, session_); } if (!transactionId_.isEmpty()) { output.writeBytes(2, transactionId_); } unknownFields.writeTo(output); }
@java.lang.Override public com.google.spanner.v1.RollbackRequest build() { com.google.spanner.v1.RollbackRequest result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
@Test @SuppressWarnings("all") public void rollbackTest() { Empty expectedResponse = Empty.newBuilder().build(); mockSpanner.addResponse(expectedResponse); SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); ByteString transactionId = ByteString.copyFromUtf8("28"); client.rollback(session, transactionId); List<GeneratedMessageV3> actualRequests = mockSpanner.getRequests(); Assert.assertEquals(1, actualRequests.size()); RollbackRequest actualRequest = (RollbackRequest) actualRequests.get(0); Assert.assertEquals(session, SessionName.parse(actualRequest.getSession())); Assert.assertEquals(transactionId, actualRequest.getTransactionId()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Override public void rollback(RollbackRequest request, @Nullable Map<Option, ?> options) throws SpannerException { GrpcCallContext context = newCallContext(options, request.getSession()); get(spannerStub.rollbackCallable().futureCall(request, context)); }
private static io.grpc.MethodDescriptor< com.google.spanner.v1.RollbackRequest, com.google.protobuf.Empty> getRollbackMethodHelper() { io.grpc.MethodDescriptor<com.google.spanner.v1.RollbackRequest, com.google.protobuf.Empty> getRollbackMethod; if ((getRollbackMethod = SpannerGrpc.getRollbackMethod) == null) { synchronized (SpannerGrpc.class) { if ((getRollbackMethod = SpannerGrpc.getRollbackMethod) == null) { SpannerGrpc.getRollbackMethod = getRollbackMethod = io.grpc.MethodDescriptor .<com.google.spanner.v1.RollbackRequest, com.google.protobuf.Empty> newBuilder() .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName( generateFullMethodName("google.spanner.v1.Spanner", "Rollback")) .setSampledToLocalTracing(true) .setRequestMarshaller( io.grpc.protobuf.ProtoUtils.marshaller( com.google.spanner.v1.RollbackRequest.getDefaultInstance())) .setResponseMarshaller( io.grpc.protobuf.ProtoUtils.marshaller( com.google.protobuf.Empty.getDefaultInstance())) .setSchemaDescriptor(new SpannerMethodDescriptorSupplier("Rollback")) .build(); } } } return getRollbackMethod; }
@java.lang.Override public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (!getSessionBytes().isEmpty()) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, session_); } if (!transactionId_.isEmpty()) { size += com.google.protobuf.CodedOutputStream.computeBytesSize(2, transactionId_); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
/** * Rolls back a transaction, releasing any locks it holds. It is a good idea to call this for any * transaction that includes one or more [Read][google.spanner.v1.Spanner.Read] or * [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] requests and ultimately decides not to * commit. * * <p>`Rollback` returns `OK` if it successfully aborts the transaction, the transaction was * already aborted, or the transaction is not found. `Rollback` never returns `ABORTED`. * * <p>Sample code: * * <pre><code> * try (SpannerClient spannerClient = SpannerClient.create()) { * SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); * ByteString transactionId = ByteString.copyFromUtf8(""); * spannerClient.rollback(session.toString(), transactionId); * } * </code></pre> * * @param session Required. The session in which the transaction to roll back is running. * @param transactionId Required. The transaction to roll back. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final void rollback(String session, ByteString transactionId) { RollbackRequest request = RollbackRequest.newBuilder().setSession(session).setTransactionId(transactionId).build(); rollback(request); }
private static io.grpc.MethodDescriptor< com.google.spanner.v1.RollbackRequest, com.google.protobuf.Empty> getRollbackMethodHelper() { io.grpc.MethodDescriptor<com.google.spanner.v1.RollbackRequest, com.google.protobuf.Empty> getRollbackMethod; if ((getRollbackMethod = SpannerGrpc.getRollbackMethod) == null) { synchronized (SpannerGrpc.class) { if ((getRollbackMethod = SpannerGrpc.getRollbackMethod) == null) { SpannerGrpc.getRollbackMethod = getRollbackMethod = io.grpc.MethodDescriptor .<com.google.spanner.v1.RollbackRequest, com.google.protobuf.Empty> newBuilder() .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName( generateFullMethodName("google.spanner.v1.Spanner", "Rollback")) .setSampledToLocalTracing(true) .setRequestMarshaller( io.grpc.protobuf.ProtoUtils.marshaller( com.google.spanner.v1.RollbackRequest.getDefaultInstance())) .setResponseMarshaller( io.grpc.protobuf.ProtoUtils.marshaller( com.google.protobuf.Empty.getDefaultInstance())) .setSchemaDescriptor(new SpannerMethodDescriptorSupplier("Rollback")) .build(); } } } return getRollbackMethod; }
RollbackRequest.newBuilder() .setSession(session == null ? null : session.toString()) .setTransactionId(transactionId)
void rollback() { // We're exiting early due to a user exception, but the transaction is still active. // Send a rollback for the transaction to release any locks held. // TODO(user): Make this an async fire-and-forget request. try { // Note that we're not retrying this request since we don't particularly care about the // response. Normally, the next thing that will happen is that we will make a fresh // transaction attempt, which should implicitly abort this one. span.addAnnotation("Starting Rollback"); rpc.rollback( RollbackRequest.newBuilder() .setSession(session.getName()) .setTransactionId(transactionId) .build(), session.options); span.addAnnotation("Rollback Done"); } catch (SpannerException e) { txnLogger.log(Level.FINE, "Exception during rollback", e); span.addAnnotation("Rollback Failed", TraceUtil.getExceptionAnnotations(e)); } }