Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,54 @@ public final class RowMutation implements MutationApi<RowMutation>, Serializable
private final ByteString key;
private final Mutation mutation;

private RowMutation(String tableId, ByteString key) {
private RowMutation(String tableId, ByteString key, Mutation mutation) {
this.tableId = tableId;
this.key = key;
this.mutation = Mutation.create();
this.mutation = mutation;
}

/** Creates a new instance of the mutation builder. */
public static RowMutation create(@Nonnull String tableId, @Nonnull String key) {
return create(tableId, ByteString.copyFromUtf8(key));
}

/** Creates a new instance of the mutation builder. */
public static RowMutation create(@Nonnull String tableId, @Nonnull ByteString key) {
return new RowMutation(tableId, key);
return new RowMutation(tableId, key, Mutation.create());
}

/**
* Creates new instance of mutation builder by wrapping existing existing set of row mutations.

This comment was marked as spam.

This comment was marked as spam.

* The builder will be owned by this RowMutation and should not be used by the caller after this call.
* This functionality is intended for advanced usage.
*
* <p>Sample code:
*
* <pre><code>
* Mutation mutation = Mutation.create()
* .setCell("[FAMILY_NAME]", "[QUALIFIER]", [TIMESTAMP], "[VALUE]");
* RowMutation rowMutation = RowMutation.create("[TABLE]", "[ROW_KEY]", mutation);
* </code></pre>
*/
public static RowMutation create(@Nonnull String tableId, @Nonnull String key, @Nonnull Mutation mutation) {
return create(tableId, ByteString.copyFromUtf8(key), mutation);
}

/**
* Creates new instance of mutation builder by wrapping existing existing set of row mutations.
* The builder will be owned by this RowMutation and should not be used by the caller after this call.
* This functionality is intended for advanced usage.
*
* <p>Sample code:
*
* <pre><code>
* Mutation mutation = Mutation.create()
* .setCell("[FAMILY_NAME]", "[QUALIFIER]", [TIMESTAMP], "[VALUE]");
* RowMutation rowMutation = RowMutation.create("[TABLE]", [BYTE_STRING_ROW_KEY], mutation);
* </code></pre>
*/
public static RowMutation create(@Nonnull String tableId, @Nonnull ByteString key, @Nonnull Mutation mutation) {
return new RowMutation(tableId, key, mutation);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ public void toBulkProtoTest() {
.isIn(timestampRange);
}

@Test
public void toProtoTestWithProvidedMutation() {
Mutation mutation = Mutation.create().setCell("fake-family", "fake-qualifier", "fake-value");
RowMutation rowMutation = RowMutation.create("fake-table", "fake-key", mutation);

MutateRowRequest actualRowMutation = rowMutation.toProto(REQUEST_CONTEXT);

assertThat(actualRowMutation.getMutationsList()).isEqualTo(mutation.getMutations());
}

@Test
public void serializationTest() throws IOException, ClassNotFoundException {
RowMutation expected =
Expand Down