1919 */
2020package com .example .cloud .bigtable .helloworld ;
2121
22+ // [START bigtable_hw_imports]
2223import com .google .cloud .bigtable .hbase .BigtableConfiguration ;
2324
2425import org .apache .hadoop .hbase .HColumnDescriptor ;
3536import org .apache .hadoop .hbase .util .Bytes ;
3637
3738import java .io .IOException ;
39+ // [END bigtable_hw_imports]
3840
3941/**
40- * A minimal application that connects to Cloud Bigtable using the native HBase API
41- * and performs some basic operations.
42+ * A minimal application that connects to Cloud Bigtable using the native HBase API and performs
43+ * some basic operations.
4244 */
4345public class HelloWorld {
4446
@@ -48,32 +50,31 @@ public class HelloWorld {
4850 private static final byte [] COLUMN_NAME = Bytes .toBytes ("greeting" );
4951
5052 // Write some friendly greetings to Cloud Bigtable
51- private static final String [] GREETINGS =
52- { "Hello World!" , "Hello Cloud Bigtable!" , "Hello HBase!" };
53+ private static final String [] GREETINGS = {
54+ "Hello World!" , "Hello Cloud Bigtable!" , "Hello HBase!"
55+ };
5356
54- /**
55- * Connects to Cloud Bigtable, runs some basic operations and prints the results.
56- */
57+ /** Connects to Cloud Bigtable, runs some basic operations and prints the results. */
5758 private static void doHelloWorld (String projectId , String instanceId ) {
5859
59- // [START connecting_to_bigtable ]
60+ // [START bigtable_hw_connect ]
6061 // Create the Bigtable connection, use try-with-resources to make sure it gets closed
6162 try (Connection connection = BigtableConfiguration .connect (projectId , instanceId )) {
6263
6364 // The admin API lets us create, manage and delete tables
6465 Admin admin = connection .getAdmin ();
65- // [END connecting_to_bigtable ]
66+ // [END bigtable_hw_connect ]
6667
67- // [START creating_a_table ]
68+ // [START bigtable_hw_create_table ]
6869 // Create a table with a single column family
6970 HTableDescriptor descriptor = new HTableDescriptor (TableName .valueOf (TABLE_NAME ));
7071 descriptor .addFamily (new HColumnDescriptor (COLUMN_FAMILY_NAME ));
7172
7273 print ("Create table " + descriptor .getNameAsString ());
7374 admin .createTable (descriptor );
74- // [END creating_a_table ]
75+ // [END bigtable_hw_create_table ]
7576
76- // [START writing_rows ]
77+ // [START bigtable_hw_write_rows ]
7778 // Retrieve the table we just created so we can do some reads and writes
7879 Table table = connection .getTable (TableName .valueOf (TABLE_NAME ));
7980
@@ -98,18 +99,18 @@ private static void doHelloWorld(String projectId, String instanceId) {
9899 put .addColumn (COLUMN_FAMILY_NAME , COLUMN_NAME , Bytes .toBytes (GREETINGS [i ]));
99100 table .put (put );
100101 }
101- // [END writing_rows ]
102+ // [END bigtable_hw_write_rows ]
102103
103- // [START getting_a_row ]
104+ // [START bigtable_hw_get_by_key ]
104105 // Get the first greeting by row key
105106 String rowKey = "greeting0" ;
106107 Result getResult = table .get (new Get (Bytes .toBytes (rowKey )));
107108 String greeting = Bytes .toString (getResult .getValue (COLUMN_FAMILY_NAME , COLUMN_NAME ));
108109 System .out .println ("Get a single greeting by row key" );
109110 System .out .printf ("\t %s = %s\n " , rowKey , greeting );
110- // [END getting_a_row ]
111+ // [END bigtable_hw_get_by_key ]
111112
112- // [START scanning_all_rows ]
113+ // [START bigtable_hw_scan_all ]
113114 // Now scan across all rows.
114115 Scan scan = new Scan ();
115116
@@ -119,14 +120,14 @@ private static void doHelloWorld(String projectId, String instanceId) {
119120 byte [] valueBytes = row .getValue (COLUMN_FAMILY_NAME , COLUMN_NAME );
120121 System .out .println ('\t' + Bytes .toString (valueBytes ));
121122 }
122- // [END scanning_all_rows ]
123+ // [END bigtable_hw_scan_all ]
123124
124- // [START deleting_a_table ]
125+ // [START bigtable_hw_delete_table ]
125126 // Clean up by disabling and then deleting the table
126127 print ("Delete the table" );
127128 admin .disableTable (table .getName ());
128129 admin .deleteTable (table .getName ());
129- // [END deleting_a_table ]
130+ // [END bigtable_hw_delete_table ]
130131
131132 } catch (IOException e ) {
132133 System .err .println ("Exception while running HelloWorld: " + e .getMessage ());
@@ -156,5 +157,4 @@ private static String requiredProperty(String prop) {
156157 }
157158 return value ;
158159 }
159-
160160}
0 commit comments