diff --git a/samples/spring-data-jdbc/README.md b/samples/spring-data-jdbc/README.md index b32ab16b2..0907e4a40 100644 --- a/samples/spring-data-jdbc/README.md +++ b/samples/spring-data-jdbc/README.md @@ -2,12 +2,12 @@ This sample application shows how to develop portable applications using Spring Data JDBC in combination with Cloud Spanner PostgreSQL. This application can be configured to run on either a -[Cloud Spanner PostgreSQL](https://cloud.google.com/spanner/docs/postgresql-interface) database or a -traditional PostgreSQL database. The only change that is needed to switch between the two is +[Cloud Spanner PostgreSQL](https://cloud.google.com/spanner/docs/postgresql-interface) database or +an open-source PostgreSQL database. The only change that is needed to switch between the two is changing the active Spring profile that is used by the application. The application uses the Cloud Spanner JDBC driver to connect to Cloud Spanner PostgreSQL, and it -uses the PostgreSQL JDBC driver to connect to traditional PostgreSQL. Spring Data JDBC works with +uses the PostgreSQL JDBC driver to connect to open-source PostgreSQL. Spring Data JDBC works with both drivers and offers a single consistent API to the application developer, regardless of the actual database or JDBC driver being used. @@ -36,7 +36,7 @@ and queries written against the PostgreSQL interface can be easily ported to ano environment. This sample showcases this portability with an application that works on both Cloud Spanner PostgreSQL -and traditional PostgreSQL with the same code base. +and open-source PostgreSQL with the same code base. ## Spring Data JDBC @@ -51,10 +51,10 @@ limited, opinionated ORM. ## Sample Application This sample shows how to create a portable application using Spring Data JDBC and the Cloud Spanner -PostgreSQL dialect. The application works on both Cloud Spanner PostgreSQL and traditional +PostgreSQL dialect. The application works on both Cloud Spanner PostgreSQL and open-source PostgreSQL. You can switch between the two by changing the active Spring profile: * Profile `cs` runs the application on Cloud Spanner PostgreSQL. -* Profile `pg` runs the application on traditional PostgreSQL. +* Profile `pg` runs the application on open-source PostgreSQL. The default profile is `cs`. You can change the default profile by modifying the [application.properties](src/main/resources/application.properties) file. @@ -78,7 +78,7 @@ The main application components are: schema is created from the [create_schema.sql](src/main/resources/create_schema.sql) file. The `DatabaseSeeder` class loads this file into memory and executes it on the active database using standard JDBC APIs. The class also removes Cloud Spanner-specific extensions to the PostgreSQL - dialect when the application runs on traditional PostgreSQL. + dialect when the application runs on open-source PostgreSQL. * [JdbcConfiguration.java](src/main/java/com/google/cloud/spanner/sample/JdbcConfiguration.java): Spring Data JDBC by default detects the database dialect based on the JDBC driver that is used. This class overrides this default and instructs Spring Data JDBC to also use the PostgreSQL diff --git a/samples/spring-data-jdbc/pom.xml b/samples/spring-data-jdbc/pom.xml index cdbdca5d8..99bf102de 100644 --- a/samples/spring-data-jdbc/pom.xml +++ b/samples/spring-data-jdbc/pom.xml @@ -28,8 +28,8 @@ com.google.cloud libraries-bom 26.22.0 - pom import + pom diff --git a/samples/spring-data-jdbc/src/main/java/com/google/cloud/spanner/sample/Application.java b/samples/spring-data-jdbc/src/main/java/com/google/cloud/spanner/sample/Application.java index 0f8177bb2..cd1a797ec 100644 --- a/samples/spring-data-jdbc/src/main/java/com/google/cloud/spanner/sample/Application.java +++ b/samples/spring-data-jdbc/src/main/java/com/google/cloud/spanner/sample/Application.java @@ -62,7 +62,7 @@ public Application( @Override public void run(String... args) { - // databaseSeeder.dropDatabaseSchema(); +// databaseSeeder.dropDatabaseSchemaIfExists(); logger.info("Creating database schema if it does not already exist"); databaseSeeder.createDatabaseSchemaIfNotExists(); logger.info("Deleting existing test data"); diff --git a/samples/spring-data-jdbc/src/main/java/com/google/cloud/spanner/sample/DatabaseSeeder.java b/samples/spring-data-jdbc/src/main/java/com/google/cloud/spanner/sample/DatabaseSeeder.java index 02bce5cae..421ed6d52 100644 --- a/samples/spring-data-jdbc/src/main/java/com/google/cloud/spanner/sample/DatabaseSeeder.java +++ b/samples/spring-data-jdbc/src/main/java/com/google/cloud/spanner/sample/DatabaseSeeder.java @@ -90,24 +90,24 @@ private static String resourceAsString(Resource resource) { /** * Returns true if this application is currently running on a Cloud Spanner PostgreSQL database, - * and false if it is running on a traditional PostgreSQL database. + * and false if it is running on an open-source PostgreSQL database. */ private boolean isCloudSpanner() { return isCloudSpannerPG.get(); } /** - * Removes all statements that start with a 'skip_on_traditional_pg' comment if the application is - * running on traditional PostgreSQL. This ensures that we can use the same DDL script both on - * Cloud Spanner and on traditional PostgreSQL. It also removes any empty statements in the given + * Removes all statements that start with a 'skip_on_open_source_pg' comment if the application is + * running on open-source PostgreSQL. This ensures that we can use the same DDL script both on + * Cloud Spanner and on open-source PostgreSQL. It also removes any empty statements in the given * array. */ private String[] updateDdlStatements(String[] statements) { for (int i = 0; i < statements.length; i++) { if (!isCloudSpanner()) { - // Replace any line that starts with '/* skip_on_traditional_pg */' with an empty string. + // Replace any line that starts with '/* skip_on_open_source_pg */' with an empty string. statements[i] = - statements[i].replaceAll("(?m)^\\s*/\\*\\s*skip_on_traditional_pg\\s*\\*/.+$", ""); + statements[i].replaceAll("(?m)^\\s*/\\*\\s*skip_on_open_source_pg\\s*\\*/.+$", ""); } statements[i] = statements[i].trim(); } diff --git a/samples/spring-data-jdbc/src/main/resources/application-cs.properties b/samples/spring-data-jdbc/src/main/resources/application-cs.properties index bf9c955a7..96aaae7ff 100644 --- a/samples/spring-data-jdbc/src/main/resources/application-cs.properties +++ b/samples/spring-data-jdbc/src/main/resources/application-cs.properties @@ -1,10 +1,8 @@ # This profile uses a Cloud Spanner PostgreSQL database. -#spanner.project=my-project -#spanner.instance=my-instance -spanner.project=appdev-soda-spanner-staging -spanner.instance=knut-test-ycsb +spanner.project=my-project +spanner.instance=my-instance spanner.database=spring-data-jdbc spring.datasource.url=jdbc:cloudspanner:/projects/${spanner.project}/instances/${spanner.instance}/databases/${spanner.database} diff --git a/samples/spring-data-jdbc/src/main/resources/application-pg.properties b/samples/spring-data-jdbc/src/main/resources/application-pg.properties index ccb64327b..894f63eba 100644 --- a/samples/spring-data-jdbc/src/main/resources/application-pg.properties +++ b/samples/spring-data-jdbc/src/main/resources/application-pg.properties @@ -1,5 +1,5 @@ -# This profile uses a traditional PostgreSQL database. +# This profile uses an open-source PostgreSQL database. spring.datasource.url=jdbc:postgresql://localhost:5432/spring-data-jdbc spring.datasource.driver-class-name=org.postgresql.Driver diff --git a/samples/spring-data-jdbc/src/main/resources/application.properties b/samples/spring-data-jdbc/src/main/resources/application.properties index af441931d..3347f3137 100644 --- a/samples/spring-data-jdbc/src/main/resources/application.properties +++ b/samples/spring-data-jdbc/src/main/resources/application.properties @@ -1,8 +1,8 @@ -# This application can use both a Cloud Spanner PostgreSQL database or a traditional PostgreSQL +# This application can use both a Cloud Spanner PostgreSQL database or an open-source PostgreSQL # database. Which database is used is determined by the active profile: # 1. 'cs' means use Cloud Spanner. -# 2. 'pg' means use traditional PostgreSQL. +# 2. 'pg' means use open-source PostgreSQL. # Activate the Cloud Spanner profile by default. # Change to 'pg' to activate the PostgreSQL profile. diff --git a/samples/spring-data-jdbc/src/main/resources/create_schema.sql b/samples/spring-data-jdbc/src/main/resources/create_schema.sql index c4e8d727c..84e89cbf5 100644 --- a/samples/spring-data-jdbc/src/main/resources/create_schema.sql +++ b/samples/spring-data-jdbc/src/main/resources/create_schema.sql @@ -1,12 +1,12 @@ /* This script creates the database schema for this sample application. - All lines that start with /* skip_on_traditional_pg */ are skipped when the application is running on a + All lines that start with /* skip_on_open_source_pg */ are skipped when the application is running on a normal PostgreSQL database. The same lines are executed when the application is running on a Cloud Spanner database. The script is executed by the DatabaseSeeder class. */ create sequence if not exists id_generator -/* skip_on_traditional_pg */ bit_reversed_positive +/* skip_on_open_source_pg */ bit_reversed_positive ; create table if not exists singers ( @@ -42,7 +42,7 @@ create table if not exists tracks ( updated_at timestamptz default current_timestamp, primary key (id, track_number) ) -/* skip_on_traditional_pg */ interleave in parent albums on delete cascade +/* skip_on_open_source_pg */ interleave in parent albums on delete cascade ; create table if not exists venues (