Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up Spanner region tags. #1045

Merged
merged 1 commit into from
Mar 1, 2018
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 @@ -84,7 +84,7 @@ static class Album {
}
}

// [START write]
// [START spanner_insert_data]
static final List<Singer> SINGERS =
Arrays.asList(
new Singer(1, "Marc", "Richards"),
Expand All @@ -100,8 +100,9 @@ static class Album {
new Album(2, 1, "Green"),
new Album(2, 2, "Forever Hold Your Peace"),
new Album(2, 3, "Terrified"));
// [END write]
// [END spanner_insert_data]

// [START spanner_create_database]
static void createDatabase(DatabaseAdminClient dbAdminClient, DatabaseId id) {
Operation<Database, CreateDatabaseMetadata> op = dbAdminClient
.createDatabase(
Expand All @@ -123,8 +124,9 @@ static void createDatabase(DatabaseAdminClient dbAdminClient, DatabaseId id) {
Database db = op.waitFor().getResult();
System.out.println("Created database [" + db.getId() + "]");
}
// [END spanner_create_database]

// [START write]
// [START spanner_insert_data]
static void writeExampleData(DatabaseClient dbClient) {
List<Mutation> mutations = new ArrayList<>();
for (Singer singer : SINGERS) {
Expand All @@ -151,9 +153,9 @@ static void writeExampleData(DatabaseClient dbClient) {
}
dbClient.write(mutations);
}
// [END write]
// [END spanner_insert_data]

// [START query]
// [START spanner_query_data]
static void query(DatabaseClient dbClient) {
// singleUse() can be used to execute a single read or query against Cloud Spanner.
ResultSet resultSet =
Expand All @@ -165,9 +167,9 @@ static void query(DatabaseClient dbClient) {
"%d %d %s\n", resultSet.getLong(0), resultSet.getLong(1), resultSet.getString(2));
}
}
// [END query]
// [END spanner_query_data]

// [START read]
// [START spanner_read_data]
static void read(DatabaseClient dbClient) {
ResultSet resultSet =
dbClient
Expand All @@ -182,21 +184,21 @@ static void read(DatabaseClient dbClient) {
"%d %d %s\n", resultSet.getLong(0), resultSet.getLong(1), resultSet.getString(2));
}
}
// [END read]
// [END spanner_read_data]

// [START add_marketing_budget]
// [START spanner_add_column]
static void addMarketingBudget(DatabaseAdminClient adminClient, DatabaseId dbId) {
adminClient.updateDatabaseDdl(dbId.getInstanceId().getInstance(),
dbId.getDatabase(),
Arrays.asList("ALTER TABLE Albums ADD COLUMN MarketingBudget INT64"),
null).waitFor();
System.out.println("Added MarketingBudget column");
}
// [END add_marketing_budget]
// [END spanner_add_column]

// Before executing this method, a new column MarketingBudget has to be added to the Albums
// table by applying the DDL statement "ALTER TABLE Albums ADD COLUMN MarketingBudget INT64".
// [START update]
// [START spanner_update_data]
static void update(DatabaseClient dbClient) {
// Mutation can be used to update/insert/delete a single row in a table. Here we use
// newUpdateBuilder to create update mutations.
Expand All @@ -221,9 +223,9 @@ static void update(DatabaseClient dbClient) {
// This writes all the mutations to Cloud Spanner atomically.
dbClient.write(mutations);
}
// [END update]
// [END spanner_update_data]

// [START transaction]
// [START spanner_read_write_transaction]
static void writeWithTransaction(DatabaseClient dbClient) {
dbClient
.readWriteTransaction()
Expand Down Expand Up @@ -270,9 +272,9 @@ public Void run(TransactionContext transaction) throws Exception {
}
});
}
// [END transaction]
// [END spanner_read_write_transaction]

// [START query_new_column]
// [START spanner_query_with_new_column]
static void queryMarketingBudget(DatabaseClient dbClient) {
// Rows without an explicit value for MarketingBudget will have a MarketingBudget equal to
// null.
Expand All @@ -290,21 +292,21 @@ static void queryMarketingBudget(DatabaseClient dbClient) {
resultSet.isNull("MarketingBudget") ? "NULL" : resultSet.getLong("MarketingBudget"));
}
}
// [END query_new_column]
// [END spanner_query_with_new_column]

// [START add_index]
// [START spanner_create_index]
static void addIndex(DatabaseAdminClient adminClient, DatabaseId dbId) {
adminClient.updateDatabaseDdl(dbId.getInstanceId().getInstance(),
dbId.getDatabase(),
Arrays.asList("CREATE INDEX AlbumsByAlbumTitle ON Albums(AlbumTitle)"),
null).waitFor();
System.out.println("Added AlbumsByAlbumTitle index");
}
// [END add_index]
// [END spanner_create_index]

// Before running this example, add the index AlbumsByAlbumTitle by applying the DDL statement
// "CREATE INDEX AlbumsByAlbumTitle ON Albums(AlbumTitle)".
// [START query_index]
// [START spanner_query_data_with_index]
static void queryUsingIndex(DatabaseClient dbClient) {
Statement statement = Statement
// We use FORCE_INDEX hint to specify which index to use. For more details see
Expand All @@ -327,9 +329,9 @@ static void queryUsingIndex(DatabaseClient dbClient) {
resultSet.isNull("MarketingBudget") ? "NULL" : resultSet.getLong("MarketingBudget"));
}
}
// [END query_index]
// [END spanner_query_data_with_index]

// [START read_index]
// [START spanner_read_data_with_index]
static void readUsingIndex(DatabaseClient dbClient) {
ResultSet resultSet =
dbClient
Expand All @@ -343,9 +345,9 @@ static void readUsingIndex(DatabaseClient dbClient) {
System.out.printf("%d %s\n", resultSet.getLong(0), resultSet.getString(1));
}
}
// [END read_index]
// [END spanner_read_data_with_index]

// [START add_storing_index]
// [START spanner_create_storing_index]
static void addStoringIndex(DatabaseAdminClient adminClient, DatabaseId dbId) {
adminClient.updateDatabaseDdl(dbId.getInstanceId().getInstance(),
dbId.getDatabase(),
Expand All @@ -354,11 +356,11 @@ static void addStoringIndex(DatabaseAdminClient adminClient, DatabaseId dbId) {
null).waitFor();
System.out.println("Added AlbumsByAlbumTitle2 index");
}
// [END add_storing_index]
// [END spanner_create_storing_index]

// Before running this example, create a storing index AlbumsByAlbumTitle2 by applying the DDL
// statement "CREATE INDEX AlbumsByAlbumTitle2 ON Albums(AlbumTitle) STORING (MarketingBudget)".
// [START read_storing_index]
// [START spanner_read_data_with_storing_index]
static void readStoringIndex(DatabaseClient dbClient) {
// We can read MarketingBudget also from the index since it stores a copy of MarketingBudget.
ResultSet resultSet =
Expand All @@ -377,9 +379,9 @@ static void readStoringIndex(DatabaseClient dbClient) {
resultSet.isNull("MarketingBudget") ? "NULL" : resultSet.getLong("MarketingBudget"));
}
}
// [END read_storing_index]
// [END spanner_read_data_with_storing_index]

// [START read_only_transaction]
// [START spanner_read_only_transaction]
static void readOnlyTransaction(DatabaseClient dbClient) {
// ReadOnlyTransaction must be closed by calling close() on it to release resources held by it.
// We use a try-with-resource block to automatically do so.
Expand All @@ -402,9 +404,9 @@ static void readOnlyTransaction(DatabaseClient dbClient) {
}
}
}
// [END read_only_transaction]
// [END spanner_read_only_transaction]

// [START read_stale_data]
// [START spanner_read_stale_data]
static void readStaleData(DatabaseClient dbClient) {
ResultSet resultSet =
dbClient
Expand All @@ -418,7 +420,7 @@ static void readStaleData(DatabaseClient dbClient) {
resultSet.isNull(2) ? "NULL" : resultSet.getLong("MarketingBudget"));
}
}
// [END read_stale_data]
// [END spanner_read_stale_data]

static void run(DatabaseClient dbClient, DatabaseAdminClient dbAdminClient, String command,
DatabaseId database) {
Expand Down