Skip to content
Merged
Changes from all 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 @@ -15,6 +15,7 @@
*/
package com.google.cloud.examples.bigtable;

// [START bigtable_hw_imports_veneer]
import com.google.api.gax.rpc.NotFoundException;
import com.google.api.gax.rpc.ServerStream;
import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient;
Expand All @@ -28,6 +29,8 @@
import com.google.cloud.bigtable.data.v2.models.RowMutation;
import java.io.IOException;

// [END bigtable_hw_imports_veneer]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the empty line above intentional?


/**
* An example of using Google Cloud Bigtable.
*
Expand Down Expand Up @@ -66,7 +69,7 @@ public static void main(String[] args) throws Exception {
public HelloWorld(String projectId, String instanceId, String tableId) throws IOException {
this.tableId = tableId;

// [START connecting_to_bigtable]
// [START bigtable_hw_connect_veneer]
// Creates the settings to configure a bigtable data client.
BigtableDataSettings settings =
BigtableDataSettings.newBuilder().setProjectId(projectId).setInstanceId(instanceId).build();
Expand All @@ -83,7 +86,7 @@ public HelloWorld(String projectId, String instanceId, String tableId) throws IO

// Creates a bigtable table admin client.
adminClient = BigtableTableAdminClient.create(adminSettings);
// [END connecting_to_bigtable]
// [END bigtable_hw_connect_veneer]
}

public void run() throws Exception {
Expand All @@ -98,7 +101,7 @@ public void run() throws Exception {

/** Demonstrates how to create a table. */
public void createTable() {
// [START creating_a_table]
// [START bigtable_hw_create_table_veneer]
// Checks if table exists, creates table if does not exist.
if (!adminClient.exists(tableId)) {
System.out.println("Creating table: " + tableId);
Expand All @@ -107,12 +110,12 @@ public void createTable() {
adminClient.createTable(createTableRequest);
System.out.printf("Table %s created successfully%n", tableId);
}
// [END creating_a_table]
// [END bigtable_hw_create_table_veneer]
}

/** Demonstrates how to write some rows to a table. */
public void writeToTable() {
// [START writing_rows]
// [START bigtable_hw_write_rows_veneer]
try {
System.out.println("\nWriting some greetings to the table");
String[] greetings = {"Hello World!", "Hello Bigtable!", "Hello Java!"};
Expand All @@ -126,12 +129,12 @@ public void writeToTable() {
} catch (NotFoundException e) {
System.err.println("Failed to write to non-existent table: " + e.getMessage());
}
// [END writing_rows]
// [END bigtable_hw_write_rows_veneer]
}

/** Demonstrates how to read a single row from a table. */
public void readSingleRow() {
// [START reading_a_row]
// [START bigtable_hw_get_by_key_veneer]
try {
System.out.println("\nReading a single row by row key");
Row row = dataClient.readRow(tableId, ROW_KEY_PREFIX + 0);
Expand All @@ -144,12 +147,12 @@ public void readSingleRow() {
} catch (NotFoundException e) {
System.err.println("Failed to read from a non-existent table: " + e.getMessage());
}
// [END reading_a_row]
// [END bigtable_hw_get_by_key_veneer]
}

/** Demonstrates how to read an entire table. */
public void readTable() {
// [START scanning_all_rows]
// [START bigtable_hw_scan_all_veneer]
try {
System.out.println("\nReading the entire table");
Query query = Query.create(tableId);
Expand All @@ -165,19 +168,19 @@ public void readTable() {
} catch (NotFoundException e) {
System.err.println("Failed to read a non-existent table: " + e.getMessage());
}
// [END scanning_all_rows]
// [END bigtable_hw_scan_all_veneer]
}

/** Demonstrates how to delete a table. */
public void deleteTable() {
// [START deleting_a_table]
// [START bigtable_hw_delete_table_veneer]
System.out.println("\nDeleting table: " + tableId);
try {
adminClient.deleteTable(tableId);
System.out.printf("Table %s deleted successfully%n", tableId);
} catch (NotFoundException e) {
System.err.println("Failed to delete a non-existent table: " + e.getMessage());
}
// [END deleting_a_table]
// [END bigtable_hw_delete_table_veneer]
}
}