use of com.google.cloud.bigtable.data.v2.models.RowMutation in project java-bigtable by googleapis.
the class HelloWorld method writeToTable.
/**
* Demonstrates how to write some rows to a table.
*/
public void writeToTable() {
// [START bigtable_hw_write_rows]
try {
System.out.println("\nWriting some greetings to the table");
String[] names = { "World", "Bigtable", "Java" };
for (int i = 0; i < names.length; i++) {
String greeting = "Hello " + names[i] + "!";
RowMutation rowMutation = RowMutation.create(tableId, ROW_KEY_PREFIX + i).setCell(COLUMN_FAMILY, COLUMN_QUALIFIER_NAME, names[i]).setCell(COLUMN_FAMILY, COLUMN_QUALIFIER_GREETING, greeting);
dataClient.mutateRow(rowMutation);
System.out.println(greeting);
}
} catch (NotFoundException e) {
System.err.println("Failed to write to non-existent table: " + e.getMessage());
}
// [END bigtable_hw_write_rows]
}
use of com.google.cloud.bigtable.data.v2.models.RowMutation in project java-bigtable by googleapis.
the class WriteSimple method writeSimple.
public static void writeSimple(String projectId, String instanceId, String tableId) {
try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
long timestamp = System.currentTimeMillis() * 1000;
String rowkey = "phone#4c410523#20190501";
RowMutation rowMutation = RowMutation.create(tableId, rowkey).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_cell".getBytes()), timestamp, 1).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_wifi".getBytes()), timestamp, 1).setCell(COLUMN_FAMILY_NAME, "os_build", timestamp, "PQ2A.190405.003");
dataClient.mutateRow(rowMutation);
System.out.printf("Successfully wrote row %s", rowkey);
} catch (Exception e) {
System.out.println("Error during WriteSimple: \n" + e.toString());
}
}
use of com.google.cloud.bigtable.data.v2.models.RowMutation in project java-docs-samples by GoogleCloudPlatform.
the class CassandraMigrationCodelab method update2.
public void update2() {
try {
// Timestamp of June 1, 2019 12:30
long timestamp = (long) 1556713800 * 1000;
String rowKey = "phone#4c410523#20190501";
ByteString zero = ByteString.copyFrom(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 });
RowMutation rowMutation = RowMutation.create(tableId, rowKey).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_cell".getBytes()), timestamp, zero);
dataClient.mutateRow(rowMutation);
} catch (Exception e) {
System.out.println("Error during update2: \n" + e.toString());
}
}
use of com.google.cloud.bigtable.data.v2.models.RowMutation in project java-bigtable-hbase by googleapis.
the class HBaseRequestAdapter method adaptEntry.
/**
* adaptEntry.
*
* @param put a {@link Put} object.
* @return a {@link RowMutationEntry} object.
*/
public RowMutationEntry adaptEntry(Put put) {
RowMutationEntry rowMutation = buildRowMutationEntry(put.getRow());
adapt(put, rowMutation);
return rowMutation;
}
use of com.google.cloud.bigtable.data.v2.models.RowMutation in project java-bigtable-hbase by googleapis.
the class HBaseRequestAdapter method adapt.
/**
* adapt.
*
* @param put a {@link org.apache.hadoop.hbase.client.Put} object.
* @return a {@link RowMutation} object.
*/
public RowMutation adapt(Put put) {
RowMutation rowMutation = newRowMutationModel(put.getRow());
adapt(put, rowMutation);
return rowMutation;
}
Aggregations