@@ -84,7 +84,7 @@ static class Album {
8484 }
8585 }
8686
87- // [START write ]
87+ // [START spanner_insert_data ]
8888 static final List <Singer > SINGERS =
8989 Arrays .asList (
9090 new Singer (1 , "Marc" , "Richards" ),
@@ -100,8 +100,9 @@ static class Album {
100100 new Album (2 , 1 , "Green" ),
101101 new Album (2 , 2 , "Forever Hold Your Peace" ),
102102 new Album (2 , 3 , "Terrified" ));
103- // [END write ]
103+ // [END spanner_insert_data ]
104104
105+ // [START spanner_create_database]
105106 static void createDatabase (DatabaseAdminClient dbAdminClient , DatabaseId id ) {
106107 Operation <Database , CreateDatabaseMetadata > op = dbAdminClient
107108 .createDatabase (
@@ -123,8 +124,9 @@ static void createDatabase(DatabaseAdminClient dbAdminClient, DatabaseId id) {
123124 Database db = op .waitFor ().getResult ();
124125 System .out .println ("Created database [" + db .getId () + "]" );
125126 }
127+ // [END spanner_create_database]
126128
127- // [START write ]
129+ // [START spanner_insert_data ]
128130 static void writeExampleData (DatabaseClient dbClient ) {
129131 List <Mutation > mutations = new ArrayList <>();
130132 for (Singer singer : SINGERS ) {
@@ -151,9 +153,9 @@ static void writeExampleData(DatabaseClient dbClient) {
151153 }
152154 dbClient .write (mutations );
153155 }
154- // [END write ]
156+ // [END spanner_insert_data ]
155157
156- // [START query ]
158+ // [START spanner_query_data ]
157159 static void query (DatabaseClient dbClient ) {
158160 // singleUse() can be used to execute a single read or query against Cloud Spanner.
159161 ResultSet resultSet =
@@ -165,9 +167,9 @@ static void query(DatabaseClient dbClient) {
165167 "%d %d %s\n " , resultSet .getLong (0 ), resultSet .getLong (1 ), resultSet .getString (2 ));
166168 }
167169 }
168- // [END query ]
170+ // [END spanner_query_data ]
169171
170- // [START read ]
172+ // [START spanner_read_data ]
171173 static void read (DatabaseClient dbClient ) {
172174 ResultSet resultSet =
173175 dbClient
@@ -182,21 +184,21 @@ static void read(DatabaseClient dbClient) {
182184 "%d %d %s\n " , resultSet .getLong (0 ), resultSet .getLong (1 ), resultSet .getString (2 ));
183185 }
184186 }
185- // [END read ]
187+ // [END spanner_read_data ]
186188
187- // [START add_marketing_budget ]
189+ // [START spanner_add_column ]
188190 static void addMarketingBudget (DatabaseAdminClient adminClient , DatabaseId dbId ) {
189191 adminClient .updateDatabaseDdl (dbId .getInstanceId ().getInstance (),
190192 dbId .getDatabase (),
191193 Arrays .asList ("ALTER TABLE Albums ADD COLUMN MarketingBudget INT64" ),
192194 null ).waitFor ();
193195 System .out .println ("Added MarketingBudget column" );
194196 }
195- // [END add_marketing_budget ]
197+ // [END spanner_add_column ]
196198
197199 // Before executing this method, a new column MarketingBudget has to be added to the Albums
198200 // table by applying the DDL statement "ALTER TABLE Albums ADD COLUMN MarketingBudget INT64".
199- // [START update ]
201+ // [START spanner_update_data ]
200202 static void update (DatabaseClient dbClient ) {
201203 // Mutation can be used to update/insert/delete a single row in a table. Here we use
202204 // newUpdateBuilder to create update mutations.
@@ -221,9 +223,9 @@ static void update(DatabaseClient dbClient) {
221223 // This writes all the mutations to Cloud Spanner atomically.
222224 dbClient .write (mutations );
223225 }
224- // [END update ]
226+ // [END spanner_update_data ]
225227
226- // [START transaction ]
228+ // [START spanner_read_write_transaction ]
227229 static void writeWithTransaction (DatabaseClient dbClient ) {
228230 dbClient
229231 .readWriteTransaction ()
@@ -270,9 +272,9 @@ public Void run(TransactionContext transaction) throws Exception {
270272 }
271273 });
272274 }
273- // [END transaction ]
275+ // [END spanner_read_write_transaction ]
274276
275- // [START query_new_column ]
277+ // [START spanner_query_with_new_column ]
276278 static void queryMarketingBudget (DatabaseClient dbClient ) {
277279 // Rows without an explicit value for MarketingBudget will have a MarketingBudget equal to
278280 // null.
@@ -290,21 +292,21 @@ static void queryMarketingBudget(DatabaseClient dbClient) {
290292 resultSet .isNull ("MarketingBudget" ) ? "NULL" : resultSet .getLong ("MarketingBudget" ));
291293 }
292294 }
293- // [END query_new_column ]
295+ // [END spanner_query_with_new_column ]
294296
295- // [START add_index ]
297+ // [START spanner_create_index ]
296298 static void addIndex (DatabaseAdminClient adminClient , DatabaseId dbId ) {
297299 adminClient .updateDatabaseDdl (dbId .getInstanceId ().getInstance (),
298300 dbId .getDatabase (),
299301 Arrays .asList ("CREATE INDEX AlbumsByAlbumTitle ON Albums(AlbumTitle)" ),
300302 null ).waitFor ();
301303 System .out .println ("Added AlbumsByAlbumTitle index" );
302304 }
303- // [END add_index ]
305+ // [END spanner_create_index ]
304306
305307 // Before running this example, add the index AlbumsByAlbumTitle by applying the DDL statement
306308 // "CREATE INDEX AlbumsByAlbumTitle ON Albums(AlbumTitle)".
307- // [START query_index ]
309+ // [START spanner_query_data_with_index ]
308310 static void queryUsingIndex (DatabaseClient dbClient ) {
309311 Statement statement = Statement
310312 // We use FORCE_INDEX hint to specify which index to use. For more details see
@@ -327,9 +329,9 @@ static void queryUsingIndex(DatabaseClient dbClient) {
327329 resultSet .isNull ("MarketingBudget" ) ? "NULL" : resultSet .getLong ("MarketingBudget" ));
328330 }
329331 }
330- // [END query_index ]
332+ // [END spanner_query_data_with_index ]
331333
332- // [START read_index ]
334+ // [START spanner_read_data_with_index ]
333335 static void readUsingIndex (DatabaseClient dbClient ) {
334336 ResultSet resultSet =
335337 dbClient
@@ -343,9 +345,9 @@ static void readUsingIndex(DatabaseClient dbClient) {
343345 System .out .printf ("%d %s\n " , resultSet .getLong (0 ), resultSet .getString (1 ));
344346 }
345347 }
346- // [END read_index ]
348+ // [END spanner_read_data_with_index ]
347349
348- // [START add_storing_index ]
350+ // [START spanner_create_storing_index ]
349351 static void addStoringIndex (DatabaseAdminClient adminClient , DatabaseId dbId ) {
350352 adminClient .updateDatabaseDdl (dbId .getInstanceId ().getInstance (),
351353 dbId .getDatabase (),
@@ -354,11 +356,11 @@ static void addStoringIndex(DatabaseAdminClient adminClient, DatabaseId dbId) {
354356 null ).waitFor ();
355357 System .out .println ("Added AlbumsByAlbumTitle2 index" );
356358 }
357- // [END add_storing_index ]
359+ // [END spanner_create_storing_index ]
358360
359361 // Before running this example, create a storing index AlbumsByAlbumTitle2 by applying the DDL
360362 // statement "CREATE INDEX AlbumsByAlbumTitle2 ON Albums(AlbumTitle) STORING (MarketingBudget)".
361- // [START read_storing_index ]
363+ // [START spanner_read_data_with_storing_index ]
362364 static void readStoringIndex (DatabaseClient dbClient ) {
363365 // We can read MarketingBudget also from the index since it stores a copy of MarketingBudget.
364366 ResultSet resultSet =
@@ -377,9 +379,9 @@ static void readStoringIndex(DatabaseClient dbClient) {
377379 resultSet .isNull ("MarketingBudget" ) ? "NULL" : resultSet .getLong ("MarketingBudget" ));
378380 }
379381 }
380- // [END read_storing_index ]
382+ // [END spanner_read_data_with_storing_index ]
381383
382- // [START read_only_transaction ]
384+ // [START spanner_read_only_transaction ]
383385 static void readOnlyTransaction (DatabaseClient dbClient ) {
384386 // ReadOnlyTransaction must be closed by calling close() on it to release resources held by it.
385387 // We use a try-with-resource block to automatically do so.
@@ -402,9 +404,9 @@ static void readOnlyTransaction(DatabaseClient dbClient) {
402404 }
403405 }
404406 }
405- // [END read_only_transaction ]
407+ // [END spanner_read_only_transaction ]
406408
407- // [START read_stale_data ]
409+ // [START spanner_read_stale_data ]
408410 static void readStaleData (DatabaseClient dbClient ) {
409411 ResultSet resultSet =
410412 dbClient
@@ -418,7 +420,7 @@ static void readStaleData(DatabaseClient dbClient) {
418420 resultSet .isNull (2 ) ? "NULL" : resultSet .getLong ("MarketingBudget" ));
419421 }
420422 }
421- // [END read_stale_data ]
423+ // [END spanner_read_stale_data ]
422424
423425 static void run (DatabaseClient dbClient , DatabaseAdminClient dbAdminClient , String command ,
424426 DatabaseId database ) {
0 commit comments