@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(); if (getMutationsCount() > 0) { hash = (37 * hash) + MUTATIONS_FIELD_NUMBER; hash = (53 * hash) + getMutationsList().hashCode(); } switch (transactionCase_) { case 2: hash = (37 * hash) + TRANSACTION_ID_FIELD_NUMBER; hash = (53 * hash) + getTransactionId().hashCode(); break; case 3: hash = (37 * hash) + SINGLE_USE_TRANSACTION_FIELD_NUMBER; hash = (53 * hash) + getSingleUseTransaction().hashCode(); break; case 0: default: } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
public Builder mergeFrom(com.google.spanner.v1.CommitRequest other) { if (other == com.google.spanner.v1.CommitRequest.getDefaultInstance()) return this; if (!other.getSession().isEmpty()) { session_ = other.session_; onChanged(); switch (other.getTransactionCase()) { case TRANSACTION_ID: setTransactionId(other.getTransactionId()); break; mergeSingleUseTransaction(other.getSingleUseTransaction()); break;
@java.lang.Override public Builder newBuilderForType() { return newBuilder(); }
/** * * * <pre> * Required. The session in which the transaction to be committed is running. * </pre> * * <code>string session = 1;</code> */ public Builder clearSession() { session_ = getDefaultInstance().getSession(); onChanged(); return this; } /**
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.spanner.v1.CommitRequest)) { return super.equals(obj); } com.google.spanner.v1.CommitRequest other = (com.google.spanner.v1.CommitRequest) obj; boolean result = true; result = result && getSession().equals(other.getSession()); result = result && getMutationsList().equals(other.getMutationsList()); result = result && getTransactionCase().equals(other.getTransactionCase()); if (!result) return false; switch (transactionCase_) { case 2: result = result && getTransactionId().equals(other.getTransactionId()); break; case 3: result = result && getSingleUseTransaction().equals(other.getSingleUseTransaction()); break; case 0: default: } result = result && unknownFields.equals(other.unknownFields); return result; }
@Test @SuppressWarnings("all") public void commitTest() { CommitResponse expectedResponse = CommitResponse.newBuilder().build(); mockSpanner.addResponse(expectedResponse); SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); ByteString transactionId = ByteString.copyFromUtf8("28"); List<Mutation> mutations = new ArrayList<>(); CommitResponse actualResponse = client.commit(session, transactionId, mutations); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockSpanner.getRequests(); Assert.assertEquals(1, actualRequests.size()); CommitRequest actualRequest = (CommitRequest) actualRequests.get(0); Assert.assertEquals(session, SessionName.parse(actualRequest.getSession())); Assert.assertEquals(transactionId, actualRequest.getTransactionId()); Assert.assertEquals(mutations, actualRequest.getMutationsList()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void commitTest2() { CommitResponse expectedResponse = CommitResponse.newBuilder().build(); mockSpanner.addResponse(expectedResponse); SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); TransactionOptions singleUseTransaction = TransactionOptions.newBuilder().build(); List<Mutation> mutations = new ArrayList<>(); CommitResponse actualResponse = client.commit(session, singleUseTransaction, mutations); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockSpanner.getRequests(); Assert.assertEquals(1, actualRequests.size()); CommitRequest actualRequest = (CommitRequest) actualRequests.get(0); Assert.assertEquals(session, SessionName.parse(actualRequest.getSession())); Assert.assertEquals(singleUseTransaction, actualRequest.getSingleUseTransaction()); Assert.assertEquals(mutations, actualRequest.getMutationsList()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Override public CommitResponse commit(CommitRequest commitRequest, @Nullable Map<Option, ?> options) throws SpannerException { GrpcCallContext context = newCallContext(options, commitRequest.getSession()); return get(spannerStub.commitCallable().futureCall(commitRequest, context)); }
@Test public void writeAtLeastOnce() throws ParseException { String timestampString = "2015-10-01T10:54:20.021Z"; ArgumentCaptor<CommitRequest> commit = ArgumentCaptor.forClass(CommitRequest.class); CommitResponse response = CommitResponse.newBuilder().setCommitTimestamp(Timestamps.parse(timestampString)).build(); Mockito.when(rpc.commit(commit.capture(), Mockito.eq(options))).thenReturn(response); Timestamp timestamp = session.writeAtLeastOnce( Arrays.asList(Mutation.newInsertBuilder("T").set("C").to("x").build())); assertThat(timestamp.getSeconds()) .isEqualTo(utcTimeSeconds(2015, Calendar.OCTOBER, 1, 10, 54, 20)); assertThat(timestamp.getNanos()).isEqualTo(TimeUnit.MILLISECONDS.toNanos(21)); CommitRequest request = commit.getValue(); assertThat(request.getSingleUseTransaction()).isNotNull(); assertThat(request.getSingleUseTransaction().getReadWrite()).isNotNull(); com.google.spanner.v1.Mutation mutation = com.google.spanner.v1.Mutation.newBuilder() .setInsert( Write.newBuilder() .setTable("T") .addColumns("C") .addValues( ListValue.newBuilder() .addValues(com.google.protobuf.Value.newBuilder().setStringValue("x")))) .build(); assertThat(request.getMutationsList()).containsExactly(mutation); }
@java.lang.Override public com.google.spanner.v1.CommitRequest getDefaultInstanceForType() { return com.google.spanner.v1.CommitRequest.getDefaultInstance(); }
@java.lang.Override public com.google.spanner.v1.CommitRequest buildPartial() { com.google.spanner.v1.CommitRequest result = new com.google.spanner.v1.CommitRequest(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0; result.session_ = session_; if (transactionCase_ == 2) { result.transaction_ = transaction_; } if (transactionCase_ == 3) { if (singleUseTransactionBuilder_ == null) { result.transaction_ = transaction_; } else { result.transaction_ = singleUseTransactionBuilder_.build(); } } if (mutationsBuilder_ == null) { if (((bitField0_ & 0x00000008) == 0x00000008)) { mutations_ = java.util.Collections.unmodifiableList(mutations_); bitField0_ = (bitField0_ & ~0x00000008); } result.mutations_ = mutations_; } else { result.mutations_ = mutationsBuilder_.build(); } result.bitField0_ = to_bitField0_; result.transactionCase_ = transactionCase_; onBuilt(); return result; }
@Override public CommitResponse commit(CommitRequest commitRequest, @Nullable Map<Option, ?> options) throws SpannerException { GrpcCallContext context = newCallContext(options, commitRequest.getSession()); return get(spannerStub.commitCallable().futureCall(commitRequest, context)); }
.setRequestMarshaller( io.grpc.protobuf.ProtoUtils.marshaller( com.google.spanner.v1.CommitRequest.getDefaultInstance())) .setResponseMarshaller( io.grpc.protobuf.ProtoUtils.marshaller(
CommitRequest.newBuilder() .setSession(session) .setTransactionId(transactionId)
.setRequestMarshaller( io.grpc.protobuf.ProtoUtils.marshaller( com.google.spanner.v1.CommitRequest.getDefaultInstance())) .setResponseMarshaller( io.grpc.protobuf.ProtoUtils.marshaller(
CommitRequest.newBuilder() .setSession(session) .setSingleUseTransaction(singleUseTransaction)
CommitRequest.newBuilder() .setSession(session == null ? null : session.toString()) .setTransactionId(transactionId)
CommitRequest.newBuilder() .setSession(session == null ? null : session.toString()) .setSingleUseTransaction(singleUseTransaction)
Mutation.toProto(mutations, mutationsProto); final CommitRequest request = CommitRequest.newBuilder() .setSession(name) .addAllMutations(mutationsProto)
void commit() { span.addAnnotation("Starting Commit"); CommitRequest.Builder builder = CommitRequest.newBuilder().setSession(session.getName()).setTransactionId(transactionId); synchronized (lock) { if (!mutations.isEmpty()) {