Skip to content

Commit

Permalink
samples: update PG samples (#1917)
Browse files Browse the repository at this point in the history
* samples: update PG samples
  • Loading branch information
rajatbhatta authored Jun 16, 2022
1 parent 05aeb8b commit eef4e92
Showing 1 changed file with 7 additions and 2 deletions.
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

0 comments on commit eef4e92

Please sign in to comment.