Skip to content

Commit a4fe0c5

Browse files
committed
Add region tags to Java Hello World sample.
1 parent 200813d commit a4fe0c5

File tree

1 file changed

+12
-0
lines changed
  • bigtable/hbase/snippets/src/main/java/com/example/cloud/bigtable/helloworld

1 file changed

+12
-0
lines changed

bigtable/hbase/snippets/src/main/java/com/example/cloud/bigtable/helloworld/HelloWorld.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,24 @@ public class HelloWorld {
5656
*/
5757
private static void doHelloWorld(String projectId, String zone, String clusterId) {
5858

59+
// [START connecting_to_bigtable]
5960
// Create the Bigtable connection, use try-with-resources to make sure it gets closed
6061
try (Connection connection = BigtableConfiguration.connect(projectId, zone, clusterId)) {
6162

6263
// The admin API lets us create, manage and delete tables
6364
Admin admin = connection.getAdmin();
65+
// [END connecting_to_bigtable]
6466

67+
// [START creating_a_table]
6568
// Create a table with a single column family
6669
HTableDescriptor descriptor = new HTableDescriptor(TableName.valueOf(TABLE_NAME));
6770
descriptor.addFamily(new HColumnDescriptor(COLUMN_FAMILY_NAME));
6871

6972
print("Create table " + descriptor.getNameAsString());
7073
admin.createTable(descriptor);
74+
// [END creating_a_table]
7175

76+
// [START writing_rows]
7277
// Retrieve the table we just created so we can do some reads and writes
7378
Table table = connection.getTable(TableName.valueOf(TABLE_NAME));
7479

@@ -93,14 +98,18 @@ private static void doHelloWorld(String projectId, String zone, String clusterId
9398
put.addColumn(COLUMN_FAMILY_NAME, COLUMN_NAME, Bytes.toBytes(GREETINGS[i]));
9499
table.put(put);
95100
}
101+
// [END writing_rows]
96102

103+
// [START getting_a_row]
97104
// Get the first greeting by row key
98105
String rowKey = "greeting0";
99106
Result getResult = table.get(new Get(Bytes.toBytes(rowKey)));
100107
String greeting = Bytes.toString(getResult.getValue(COLUMN_FAMILY_NAME, COLUMN_NAME));
101108
System.out.println("Get a single greeting by row key");
102109
System.out.printf("\t%s = %s\n", rowKey, greeting);
110+
// [END getting_a_row]
103111

112+
// [START scanning_all_rows]
104113
// Now scan across all rows.
105114
Scan scan = new Scan();
106115

@@ -110,11 +119,14 @@ private static void doHelloWorld(String projectId, String zone, String clusterId
110119
byte[] valueBytes = row.getValue(COLUMN_FAMILY_NAME, COLUMN_NAME);
111120
System.out.println('\t' + Bytes.toString(valueBytes));
112121
}
122+
// [END scanning_all_rows]
113123

124+
// [START deleting_a_table]
114125
// Clean up by disabling and then deleting the table
115126
print("Delete the table");
116127
admin.disableTable(table.getName());
117128
admin.deleteTable(table.getName());
129+
// [END deleting_a_table]
118130

119131
} catch (IOException e) {
120132
System.err.println("Exception while running HelloWorld: " + e.getMessage());

0 commit comments

Comments
 (0)