Skip to content

Commit

Permalink
docs: replace 'traditional' with 'open-source'
Browse files Browse the repository at this point in the history
  • Loading branch information
olavloite committed Sep 8, 2023
1 parent 112f38b commit 1a4c98c
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 25 deletions.
14 changes: 7 additions & 7 deletions samples/spring-data-jdbc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion samples/spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.22.0</version>
<type>pom</type>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 3 additions & 3 deletions samples/spring-data-jdbc/src/main/resources/create_schema.sql
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 1a4c98c

Please sign in to comment.