@@ -56,19 +56,24 @@ public class HelloWorld {
56
56
*/
57
57
private static void doHelloWorld (String projectId , String zone , String clusterId ) {
58
58
59
+ // [START connecting_to_bigtable]
59
60
// Create the Bigtable connection, use try-with-resources to make sure it gets closed
60
61
try (Connection connection = BigtableConfiguration .connect (projectId , zone , clusterId )) {
61
62
62
63
// The admin API lets us create, manage and delete tables
63
64
Admin admin = connection .getAdmin ();
65
+ // [END connecting_to_bigtable]
64
66
67
+ // [START creating_a_table]
65
68
// Create a table with a single column family
66
69
HTableDescriptor descriptor = new HTableDescriptor (TableName .valueOf (TABLE_NAME ));
67
70
descriptor .addFamily (new HColumnDescriptor (COLUMN_FAMILY_NAME ));
68
71
69
72
print ("Create table " + descriptor .getNameAsString ());
70
73
admin .createTable (descriptor );
74
+ // [END creating_a_table]
71
75
76
+ // [START writing_rows]
72
77
// Retrieve the table we just created so we can do some reads and writes
73
78
Table table = connection .getTable (TableName .valueOf (TABLE_NAME ));
74
79
@@ -93,14 +98,18 @@ private static void doHelloWorld(String projectId, String zone, String clusterId
93
98
put .addColumn (COLUMN_FAMILY_NAME , COLUMN_NAME , Bytes .toBytes (GREETINGS [i ]));
94
99
table .put (put );
95
100
}
101
+ // [END writing_rows]
96
102
103
+ // [START getting_a_row]
97
104
// Get the first greeting by row key
98
105
String rowKey = "greeting0" ;
99
106
Result getResult = table .get (new Get (Bytes .toBytes (rowKey )));
100
107
String greeting = Bytes .toString (getResult .getValue (COLUMN_FAMILY_NAME , COLUMN_NAME ));
101
108
System .out .println ("Get a single greeting by row key" );
102
109
System .out .printf ("\t %s = %s\n " , rowKey , greeting );
110
+ // [END getting_a_row]
103
111
112
+ // [START scanning_all_rows]
104
113
// Now scan across all rows.
105
114
Scan scan = new Scan ();
106
115
@@ -110,11 +119,14 @@ private static void doHelloWorld(String projectId, String zone, String clusterId
110
119
byte [] valueBytes = row .getValue (COLUMN_FAMILY_NAME , COLUMN_NAME );
111
120
System .out .println ('\t' + Bytes .toString (valueBytes ));
112
121
}
122
+ // [END scanning_all_rows]
113
123
124
+ // [START deleting_a_table]
114
125
// Clean up by disabling and then deleting the table
115
126
print ("Delete the table" );
116
127
admin .disableTable (table .getName ());
117
128
admin .deleteTable (table .getName ());
129
+ // [END deleting_a_table]
118
130
119
131
} catch (IOException e ) {
120
132
System .err .println ("Exception while running HelloWorld: " + e .getMessage ());
0 commit comments