/** * * * <pre> * The mutations to be executed when this transaction commits. All * mutations are applied atomically, in the order they appear in * this list. * </pre> * * <code>repeated .google.spanner.v1.Mutation mutations = 4;</code> */ public Builder addMutations(com.google.spanner.v1.Mutation.Builder builderForValue) { if (mutationsBuilder_ == null) { ensureMutationsIsMutable(); mutations_.add(builderForValue.build()); onChanged(); } else { mutationsBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * * * <pre> * Delete rows from a table. Succeeds whether or not the named * rows were present. * </pre> * * <code>.google.spanner.v1.Mutation.Delete delete = 5;</code> */ public com.google.spanner.v1.Mutation.Delete.Builder getDeleteBuilder() { return getDeleteFieldBuilder().getBuilder(); } /**
/** * * * <pre> * Insert new rows in a table. If any of the rows already exist, * the write or transaction fails with error `ALREADY_EXISTS`. * </pre> * * <code>.google.spanner.v1.Mutation.Write insert = 1;</code> */ public com.google.spanner.v1.Mutation.Write.Builder getInsertBuilder() { return getInsertFieldBuilder().getBuilder(); } /**
} else { if (proto != null) { out.add(proto.build()); proto.getDeleteBuilder().setTable(mutation.table); keySet = delete.getKeySetBuilder(); mutation.keySet.appendToProto(keySet); } else { if (proto != null) { out.add(proto.build()); write = proto.getInsertBuilder(); break; case UPDATE: write = proto.getUpdateBuilder(); break; case INSERT_OR_UPDATE: write = proto.getInsertOrUpdateBuilder(); break; case REPLACE: write = proto.getReplaceBuilder(); break; default: out.add(proto.build());
} else { if (proto != null) { out.add(proto.build()); proto.getDeleteBuilder().setTable(mutation.table); keySet = delete.getKeySetBuilder(); mutation.keySet.appendToProto(keySet); } else { if (proto != null) { out.add(proto.build()); write = proto.getInsertBuilder(); break; case UPDATE: write = proto.getUpdateBuilder(); break; case INSERT_OR_UPDATE: write = proto.getInsertOrUpdateBuilder(); break; case REPLACE: write = proto.getReplaceBuilder(); break; default: out.add(proto.build());
@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); }
/** * * * <pre> * The mutations to be executed when this transaction commits. All * mutations are applied atomically, in the order they appear in * this list. * </pre> * * <code>repeated .google.spanner.v1.Mutation mutations = 4;</code> */ public Builder setMutations(int index, com.google.spanner.v1.Mutation.Builder builderForValue) { if (mutationsBuilder_ == null) { ensureMutationsIsMutable(); mutations_.set(index, builderForValue.build()); onChanged(); } else { mutationsBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
/** * * * <pre> * The mutations to be executed when this transaction commits. All * mutations are applied atomically, in the order they appear in * this list. * </pre> * * <code>repeated .google.spanner.v1.Mutation mutations = 4;</code> */ public Builder addMutations(int index, com.google.spanner.v1.Mutation.Builder builderForValue) { if (mutationsBuilder_ == null) { ensureMutationsIsMutable(); mutations_.add(index, builderForValue.build()); onChanged(); } else { mutationsBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * * * <pre> * Like [insert][google.spanner.v1.Mutation.insert], except that if the row already exists, then * its column values are overwritten with the ones provided. Any * column values not explicitly written are preserved. * </pre> * * <code>.google.spanner.v1.Mutation.Write insert_or_update = 3;</code> */ public com.google.spanner.v1.Mutation.Write.Builder getInsertOrUpdateBuilder() { return getInsertOrUpdateFieldBuilder().getBuilder(); } /**
@java.lang.Override protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } /**
@java.lang.Override public com.google.spanner.v1.Mutation build() { com.google.spanner.v1.Mutation result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }