8000 Update cloud-sql sample region tags. (#1322) · tbirt666/java-docs-samples@f19a06e · GitHub
[go: up one dir, main page]

Skip to content

Commit f19a06e

Browse files
authored
Update cloud-sql sample region tags. (GoogleCloudPlatform#1322)
* Updated mysql/servlet region tags. * Updated postgres/servlet region tags.
1 parent eef1709 commit f19a06e

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ public class ConnectionPoolContextListener implements ServletContextListener {
3434

3535
// Saving credentials in environment variables is convenient, but not secure - consider a more
3636
// secure solution such as https://cloud.google.com/kms/ to help keep secrets safe.
37-
private static final String CLOUD_SQL_INSTANCE_NAME = System.getenv("CLOUD_SQL_INSTANCE_NAME");
37+
private static final String CLOUD_SQL_CONNECTION_NAME = System.getenv(
38+
"CLOUD_SQL_CONNECTION_NAME");
3839
private static final String DB_USER = System.getenv("DB_USER");
3940
private static final String DB_PASS = System.getenv("DB_PASS");
4041
private static final String DB_NAME = System.getenv("DB_NAME");
4142

4243
private DataSource createConnectionPool() {
43-
// [START cloud_sql_mysql_connection_pool]
44+
// [START cloud_sql_mysql_servlet_create]
4445
// The configuration object specifies behaviors for the connection pool.
4546
HikariConfig config = new HikariConfig();
4647

@@ -52,50 +53,49 @@ private DataSource createConnectionPool() {
5253
// For Java users, the Cloud SQL JDBC Socket Factory can provide authenticated connections.
5354
// See https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory for details.
5455
config.addDataSourceProperty("socketFactory", "com.google.cloud.sql.mysql.SocketFactory");
55-
config.addDataSourceProperty("cloudSqlInstance", CLOUD_SQL_INSTANCE_NAME);
56+
config.addDataSourceProperty("cloudSqlInstance", CLOUD_SQL_CONNECTION_NAME);
5657
config.addDataSourceProperty("useSSL", "false");
5758

5859
// ... Specify additional connection properties here.
59-
6060
// [START_EXCLUDE]
6161

62-
// [START cloud_sql_mysql_limit_connections]
62+
// [START cloud_sql_mysql_servlet_limit]
6363
// maximumPoolSize limits the total number of concurrent connections this pool will keep. Ideal
6464
// values for this setting are highly variable on app design, infrastructure, and database.
6565
config.setMaximumPoolSize(5);
6666
// minimumIdle is the minimum number of idle connections Hikari maintains in the pool.
6767
// Additional connections will be established to meet this value unless the pool is full.
6868
config.setMinimumIdle(5);
69-
// [END cloud_sql_mysql_limit_connections]
69+
// [END cloud_sql_mysql_servlet_limit]
7070

71-
// [START cloud_sql_mysql_connection_timeout]
71+
// [START cloud_sql_mysql_servlet_timeout]
7272
// setConnectionTimeout is the maximum number of milliseconds to wait for a connection checkout.
7373
// Any attempt to retrieve a connection from this pool that exceeds the set limit will throw an
7474
// SQLException.
7575
config.setConnectionTimeout(10000); // 10 seconds
7676
// idleTimeout is the maximum amount of time a connection can sit in the pool. Connections that
7777
// sit idle for this many milliseconds are retried if minimumIdle is exceeded.
7878
config.setIdleTimeout(600000); // 10 minutes
79-
// [END cloud_sql_mysql_connection_timeout]
79+
// [END cloud_sql_mysql_servlet_timeout]
8080

81-
// [START cloud_sql_mysql_connection_backoff]
81+
// [START cloud_sql_mysql_servlet_backoff]
8282
// Hikari automatically delays between failed connection attempts, eventually reaching a
8383
// maximum delay of `connectionTimeout / 2` between attempts.
84-
// [END cloud_sql_mysql_connection_backoff]
84+
// [END cloud_sql_mysql_servlet_backoff]
8585

86-
// [START cloud_sql_mysql_connection_lifetime]
86+
// [START cloud_sql_mysql_servlet_lifetime]
8787
// maxLifetime is the maximum possible lifetime of a connection in the pool. Connections that
8888
// live longer than this many milliseconds will be closed and reestablished between uses. This
8989
// value should be several minutes shorter than the database's timeout value to avoid unexpected
9090
// terminations.
9191
config.setMaxLifetime(1800000); // 30 minutes
92-
// [END cloud_sql_mysql_connection_lifetime]
92+
// [END cloud_sql_mysql_servlet_lifetime]
9393

9494
// [END_EXCLUDE]
9595

9696
// Initialize the connection pool using the configuration object.
9797
DataSource pool = new HikariDataSource(config);
98-
// [END cloud_sql_mysql_connection_pool]
98+
// [END cloud_sql_mysql_servlet_create]
9999
return pool;
100100
}
101101

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp)
110110

111111
// Reuse the pool that was created in the ContextListener when the Servlet started.
112112
DataSource pool = (DataSource) req.getServletContext().getAttribute("my-pool");
113-
// [START cloud_sql_mysql_example_statement]
113+
// [START cloud_sql_mysql_servlet_connection]
114114
// Using a try-with-resources statement ensures that the connection is always released back
115115
// into the pool at the end of the statement (even if an error occurs)
116116
try (Connection conn = pool.getConnection()) {
@@ -134,7 +134,7 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp)
134134
+ "logs for more details.");
135135
// [END_EXCLUDE]
136136
}
137-
// [END cloud_sql_mysql_example_statement]
137+
// [END cloud_sql_mysql_servlet_connection]
138138

139139
resp.setStatus(200);
140140
resp.getWriter().printf("Vote successfully cast for '%s' at time %s!\n", team, now);

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ public class ConnectionPoolContextListener implements ServletContextListener {
3434

3535
// Saving credentials in environment variables is convenient, but not secure - consider a more
3636
// secure solution such as https://cloud.google.com/kms/ to help keep secrets safe.
37-
private static final String CLOUD_SQL_INSTANCE_NAME = System.getenv("CLOUD_SQL_INSTANCE_NAME");
37+
private static final String CLOUD_SQL_CONNECTION_NAME = System.getenv(
38+
"CLOUD_SQL_CONNECTION_NAME");
3839
private static final String DB_USER = System.getenv("DB_USER");
3940
private static final String DB_PASS = System.getenv("DB_PASS");
4041
private static final String DB_NAME = System.getenv("DB_NAME");
4142

4243
private DataSource createConnectionPool() {
43-
// [START cloud_sql_postgres_connection_pool]
44+
// [START cloud_sql_postgres_servlet_create]
4445
// The configuration object specifies behaviors for the connection pool.
4546
HikariConfig config = new HikariConfig();
4647

@@ -52,49 +53,49 @@ private DataSource createConnectionPool() {
5253
// For Java users, the Cloud SQL JDBC Socket Factory can provide authenticated connections.
5354
// See https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory for details.
5455
config.addDataSourceProperty("socketFactory", "com.google.cloud.sql.postgres.SocketFactory");
55-
config.addDataSourceProperty("cloudSqlInstance", CLOUD_SQL_INSTANCE_NAME);
56+
config.addDataSourceProperty("cloudSqlInstance", CLOUD_SQL_CONNECTION_NAME);
5657

5758
// ... Specify additional connection properties here.
5859

5960
// [START_EXCLUDE]
6061

61-
// [START cloud_sql_postgres_limit_connections]
62+
// [START cloud_sql_postgres_servlet_limit]
6263
// maximumPoolSize limits the total number of concurrent connections this pool will keep. Ideal
6364
// values for this setting are highly variable on app design, infrastructure, and database.
6465
config.setMaximumPoolSize(5);
6566
// minimumIdle is the minimum number of idle connections Hikari maintains in the pool.
6667
// Additional connections will be established to meet this value unless the pool is full.
6768
config.setMinimumIdle(5);
68-
// [END cloud_sql_postgres_limit_connections]
69+
// [END cloud_sql_postgres_servlet_limit]
6970

70-
// [START cloud_sql_postgres_connection_timeout]
71+
// [START cloud_sql_postgres_servlet_timeout]
7172
// setConnectionTimeout is the maximum number of milliseconds to wait for a connection checkout.
7273
// Any attempt to retrieve a connection from this pool that exceeds the set limit will throw an
7374
// SQLException.
7475
config.setConnectionTimeout(10000); // 10 seconds
7576
// idleTimeout is the maximum amount of time a connection can sit in the pool. Connections that
7677
// sit idle for this many milliseconds are retried if minimumIdle is exceeded.
7778
config.setIdleTimeout(600000); // 10 minutes
78-
// [END cloud_sql_postgres_connection_timeout]
79+
// [END cloud_sql_postgres_servlet_timeout]
7980

80-
// [START cloud_sql_postgres_connection_backoff]
81+
// [START cloud_sql_postgres_servlet_backoff]
8182
// Hikari automatically delays between failed connection attempts, eventually reaching a
8283
// maximum delay of `connectionTimeout / 2` between attempts.
83-
// [END cloud_sql_postgres_connection_backoff]
84+
// [END cloud_sql_postgres_servlet_backoff]
8485

85-
// [START cloud_sql_postgres_connection_lifetime]
86+
// [START cloud_sql_postgres_servlet_lifetime]
8687
// maxLifetime is the maximum possible lifetime of a connection in the pool. Connections that
8788
// live longer than this many milliseconds will be closed and reestablished between uses. This
8889
// value should be several minutes shorter than the database's timeout value to avoid unexpected
8990
// terminations.
9091
config.setMaxLifetime(1800000); // 30 minutes
91-
// [END cloud_sql_postgres_connection_lifetime]
92+
// [END cloud_sql_postgres_servlet_lifetime]
9293

9394
// [END_EXCLUDE]
9495

9596
// Initialize the connection pool using the configuration object.
9697
DataSource pool = new HikariDataSource(config);
97-
// [END cloud_sql_postgres_connection_pool]
98+
// [END cloud_sql_postgres_servlet_create]
9899
return pool;
99100
}
100101

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp)
110110

111111
// Reuse the pool that was created in the ContextListener when the Servlet started.
112112
DataSource pool = (DataSource) req.getServletContext().getAttribute("my-pool");
113-
// [START cloud_sql_postgres_example_statement]
113+
// [START cloud_sql_postgres_servlet_connection]
114114
// Using a try-with-resources statement ensures that the connection is always released back
115115
// into the pool at the end of the statement (even if an error occurs)
116116
try (Connection conn = pool.getConnection()) {
@@ -134,7 +134,7 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp)
134134
+ "logs for more details.");
135135
// [END_EXCLUDE]
136136
}
137-
// [END cloud_sql_postgres_example_statement]
137+
// [END cloud_sql_postgres_servlet_connection]
138138

139139
resp.setStatus(200);
140140
resp.getWriter().printf("Vote successfully cast for '%s' at time %s!\n", team, now);

0 commit comments

Comments
 (0)
0