Skip to content

Commit 708aa19

Browse files
authored
docs: added comments clarifying use of JDBC Socket Factory (GoogleCloudPlatform#4673)
> It's a good idea to open an issue first for discussion. - [x ] I have followed [Sample Format Guide](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/SAMPLE_FORMAT.md) - [ ] `pom.xml` parent set to latest `shared-configuration` - [ x] Appropriate changes to README are included in PR - [ ] API's need to be enabled to test (tell us) - [ ] Environment Variables need to be set (ask us to set them) - [ x] **Tests** pass: `mvn clean verify` **required** - [ x] **Lint** passes: `mvn -P lint checkstyle:check` **required** - [ ] **Static Analysis**: `mvn -P lint clean compile pmd:cpd-check spotbugs:check` **advisory only** - [ x] Please **merge** this PR for me once it is approved.
1 parent f170ed2 commit 708aa19

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

cloud-sql/mysql/servlet/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ for more details on connecting a Cloud Run service to Cloud SQL.
8585
--platform managed \
8686
--allow-unauthenticated \
8787
--region [REGION] \
88-
--update-env-vars CLOUD_SQL_CONNECTION_NAME=[INSTANCE_CONNECTION_NAME] \
88+
--update-env-vars CLOUD_SQL_CONNECTION_NAME=[CLOUD_SQL_CONNECTION_NAME] \
8989
--update-env-vars DB_USER=[MY_DB_USER] \
9090
--update-env-vars DB_PASS=[MY_DB_PASS] \
9191
--update-env-vars DB_NAME=[MY_DB]
@@ -96,6 +96,7 @@ for more details on connecting a Cloud Run service to Cloud SQL.
9696

9797
Take note of the URL output at the end of the deployment process.
9898

99+
99100
3. Navigate your browser to the URL noted in step 2.
100101

101102
For more details about using Cloud Run see http://cloud.run.

cloud-sql/mysql/servlet/src/main/java/com/example/cloudsql/ConnectionPoolContextListener.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public class ConnectionPoolContextListener implements ServletContextListener {
4747
justification = "Necessary for sample region tag.")
4848
private DataSource createConnectionPool() {
4949
// [START cloud_sql_mysql_servlet_create]
50+
// Note: For Java users, the Cloud SQL JDBC Socket Factory can provide authenticated connections
51+
// which is preferred to using the Cloud SQL Proxy with Unix sockets.
52+
// See https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory for details.
53+
5054
// The configuration object specifies behaviors for the connection pool.
5155
HikariConfig config = new HikariConfig();
5256

@@ -61,8 +65,6 @@ private DataSource createConnectionPool() {
6165
config.setUsername(DB_USER); // e.g. "root", "mysql"
6266
config.setPassword(DB_PASS); // e.g. "my-password"
6367

64-
// For Java users, the Cloud SQL JDBC Socket Factory can provide authenticated connections.
65-
// See https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory for details.
6668
config.addDataSourceProperty("socketFactory", "com.google.cloud.sql.mysql.SocketFactory");
6769
config.addDataSourceProperty("cloudSqlInstance", CLOUD_SQL_CONNECTION_NAME);
6870

cloud-sql/postgres/servlet/src/main/java/com/example/cloudsql/ConnectionPoolContextListener.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public class ConnectionPoolContextListener implements ServletContextListener {
4747
justification = "Necessary for sample region tag.")
4848
private DataSource createConnectionPool() {
4949
// [START cloud_sql_postgres_servlet_create]
50+
// Note: For Java users, the Cloud SQL JDBC Socket Factory can provide authenticated connections
51+
// which is preferred to using the Cloud SQL Proxy with Unix sockets.
52+
// See https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory for details.
53+
5054
// The configuration object specifies behaviors for the connection pool.
5155
HikariConfig config = new HikariConfig();
5256

@@ -61,8 +65,6 @@ private DataSource createConnectionPool() {
6165
config.setUsername(DB_USER); // e.g. "root", "postgres"
6266
config.setPassword(DB_PASS); // e.g. "my-password"
6367

64-
// For Java users, the Cloud SQL JDBC Socket Factory can provide authenticated connections.
65-
// See https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory for details.
6668
config.addDataSourceProperty("socketFactory", "com.google.cloud.sql.postgres.SocketFactory");
6769
config.addDataSourceProperty("cloudSqlInstance", CLOUD_SQL_CONNECTION_NAME);
6870

cloud-sql/sqlserver/servlet/src/main/java/com/example/cloudsql/ConnectionPoolContextListener.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public class ConnectionPoolContextListener implements ServletContextListener {
4242

4343
private DataSource createConnectionPool() {
4444
// [START cloud_sql_sqlserver_servlet_create]
45+
// Note: For Java users, the Cloud SQL JDBC Socket Factory can provide authenticated connections
46+
// which is preferred to using the Cloud SQL Proxy with Unix sockets.
47+
// See https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory for details.
48+
4549
// The configuration object specifies behaviors for the connection pool.
4650
HikariConfig config = new HikariConfig();
4751

@@ -60,8 +64,6 @@ private DataSource createConnectionPool() {
6064
config.setPassword(DB_PASS); // e.g. "my-password"
6165
config.addDataSourceProperty("databaseName", DB_NAME);
6266

63-
// For Java users, the Cloud SQL JDBC Socket Factory can provide authenticated connections.
64-
// See https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory for details.
6567
config.addDataSourceProperty("socketFactoryClass",
6668
"com.google.cloud.sql.sqlserver.SocketFactory");
6769
config.addDataSourceProperty("socketFactoryConstructorArg", CLOUD_SQL_CONNECTION_NAME);

0 commit comments

Comments
 (0)