From 17cf1e1515e09e422b5cb18b802ce670023b8b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Tue, 13 May 2025 11:45:24 +0200 Subject: [PATCH] chore: make StatementExecutorType public Make the getter/setter for StatementExecutorType public, so these can be set by the JDBC driver and PGAdapter. --- .../spanner/connection/ConnectionOptions.java | 12 ++++++++++-- .../spanner/connection/StatementExecutor.java | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionOptions.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionOptions.java index 9811a946200..58b2c78fb2f 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionOptions.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionOptions.java @@ -556,7 +556,11 @@ Builder setCredentials(Credentials credentials) { return this; } - Builder setStatementExecutorType(StatementExecutorType statementExecutorType) { + /** + * Sets the executor type to use for connections. See {@link StatementExecutorType} for more + * information on what the different options mean. + */ + public Builder setStatementExecutorType(StatementExecutorType statementExecutorType) { this.statementExecutorType = statementExecutorType; return this; } @@ -920,7 +924,11 @@ CredentialsProvider getCredentialsProvider() { return getInitialConnectionPropertyValue(CREDENTIALS_PROVIDER); } - StatementExecutorType getStatementExecutorType() { + /** + * Returns the executor type that is used by connections that are created from this {@link + * ConnectionOptions} instance. + */ + public StatementExecutorType getStatementExecutorType() { return this.statementExecutorType; } diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/StatementExecutor.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/StatementExecutor.java index 6e410f31e83..b022158b917 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/StatementExecutor.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/StatementExecutor.java @@ -172,9 +172,23 @@ private static ListeningExecutorService createExecutorService(StatementExecutorT */ private final List interceptors; - enum StatementExecutorType { + /** The executor type that is used for statements that are executed on a connection. */ + public enum StatementExecutorType { + /** + * Use a platform thread per connection. This allows async execution of statements, but costs + * more resources than the other options. + */ PLATFORM_THREAD, + /** + * Use a virtual thread per connection. This allows async execution of statements. Virtual + * threads are only supported on Java 21 and higher. + */ VIRTUAL_THREAD, + /** + * Use the calling thread for execution. This does not support async execution of statements. + * This option is used by drivers that do not support async execution, such as JDBC and + * PGAdapter. + */ DIRECT_EXECUTOR, }