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

samples: update PG samples #1917

Merged
merged 3 commits into from
Jun 16, 2022
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 @@ -66,6 +66,7 @@
* Example code for using the Cloud Spanner PostgreSQL interface.
*/
public class PgSpannerSample {
// [START spanner_postgresql_insert_data]
static final List<Singer> SINGERS =
Arrays.asList(
new Singer(1, "Marc", "Richards"),
Expand All @@ -80,6 +81,7 @@ public class PgSpannerSample {
new Album(2, 1, "Green"),
new Album(2, 2, "Forever Hold Your Peace"),
new Album(2, 3, "Terrified"));
// [END spanner_postgresql_insert_data]

/** Class to contain performance sample data. */
static class Performance {
Expand Down Expand Up @@ -201,6 +203,7 @@ static void createPostgreSqlDatabase(DatabaseAdminClient dbAdminClient, Database
// Initiate the request which returns an OperationFuture.
Database db = op.get();
System.out.println("Created database [" + db.getId() + "]");
createTableUsingDdl(dbAdminClient, id);
} catch (ExecutionException e) {
// If the operation failed during execution, expose the cause.
throw (SpannerException) e.getCause();
Expand Down Expand Up @@ -652,6 +655,7 @@ static void writeWithTransactionUsingDml(DatabaseClient dbClient) {
// [END spanner_postgresql_dml_getting_started_update]

// [START spanner_postgresql_create_table_using_ddl]
// [START spanner_postgresql_create_database]
static void createTableUsingDdl(DatabaseAdminClient dbAdminClient, DatabaseId id) {
OperationFuture<Void, UpdateDatabaseDdlMetadata> op =
dbAdminClient.updateDatabaseDdl(
Expand Down Expand Up @@ -685,6 +689,7 @@ static void createTableUsingDdl(DatabaseAdminClient dbAdminClient, DatabaseId id
throw SpannerExceptionFactory.propagateInterrupt(e);
}
}
// [END spanner_postgresql_create_database]
// [END spanner_postgresql_create_table_using_ddl]

// [START spanner_postgresql_read_stale_data]
Expand Down Expand Up @@ -1319,7 +1324,7 @@ static void run(
String command,
DatabaseId database) {
switch (command) {
case "createpgdatabase":
case "createdatabase":
createPostgreSqlDatabase(dbAdminClient, database);
break;
case "write":
Expand Down Expand Up @@ -1467,7 +1472,7 @@ static void printUsageAndExit() {
System.err.println(" PgSpannerExample <command> <instance_id> <database_id>");
System.err.println();
System.err.println("Examples:");
System.err.println(" PgSpannerExample createpgdatabase my-instance example-db");
System.err.println(" PgSpannerExample createdatabase my-instance example-db");
System.err.println(" PgSpannerExample write my-instance example-db");
System.err.println(" PgSpannerExample delete my-instance example-db");
System.err.println(" PgSpannerExample query my-instance example-db");
Expand Down