Repository: googleapis/java-spanner-jdbc
Pull request #1865 (2024-12-14 12:49:12)

chore: store query timeout as a java.time.Duration
Store the query timeout internally as a java.time.Duration, so we can use a smaller unit for testing. This again allows us to enable the timeout tests by default.



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 74bfd53..5355f38 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,15 @@
 # Changelog
 
+## [2.25.1](https://github.com/googleapis/java-spanner-jdbc/compare/v2.25.0...v2.25.1) (2024-12-14)
+
+
+### Dependencies
+
+* Update dependency com.google.cloud:google-cloud-spanner-bom to v6.83.0 ([#1863](https://github.com/googleapis/java-spanner-jdbc/issues/1863)) ([0e5680b](https://github.com/googleapis/java-spanner-jdbc/commit/0e5680b5dd7b433c850b389a64e8c8c1343151ed))
+* Update dependency com.google.cloud:sdk-platform-java-config to v3.41.0 ([#1857](https://github.com/googleapis/java-spanner-jdbc/issues/1857)) ([162fa47](https://github.com/googleapis/java-spanner-jdbc/commit/162fa476b6b45ec14700efe5fea8f6fad7d1c5ad))
+* Update dependency io.opentelemetry:opentelemetry-bom to v1.45.0 ([#1853](https://github.com/googleapis/java-spanner-jdbc/issues/1853)) ([350e755](https://github.com/googleapis/java-spanner-jdbc/commit/350e75519d13c81c820c51f88786ca8a61662858))
+* Update dependency org.springframework.data:spring-data-bom to v2024.1.1 ([#1859](https://github.com/googleapis/java-spanner-jdbc/issues/1859)) ([150827c](https://github.com/googleapis/java-spanner-jdbc/commit/150827c54042f9d754f1d130287f56ebfadeb7c8))
+
 ## [2.25.0](https://github.com/googleapis/java-spanner-jdbc/compare/v2.24.2...v2.25.0) (2024-12-04)
 
 
diff --git a/README.md b/README.md
index 8cb792f..8dbd963 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ If you are using Maven, add this to your pom.xml file:
 <dependency>
   <groupId>com.google.cloud</groupId>
   <artifactId>google-cloud-spanner-jdbc</artifactId>
-  <version>2.25.0</version>
+  <version>2.25.1</version>
 </dependency>
 ```
 <!--- {x-version-update-end} -->
@@ -30,7 +30,7 @@ If you are using Gradle without BOM, add this to your dependencies
 
 <!--- {x-version-update-start:google-cloud-spanner-jdbc:released} -->
 ```Groovy
-implementation 'com.google.cloud:google-cloud-spanner-jdbc:2.25.0'
+implementation 'com.google.cloud:google-cloud-spanner-jdbc:2.25.1'
 ```
 <!--- {x-version-update-end} -->
 
@@ -38,7 +38,7 @@ If you are using SBT, add this to your dependencies
 
 <!--- {x-version-update-start:google-cloud-spanner-jdbc:released} -->
 ```Scala
-libraryDependencies += "com.google.cloud" % "google-cloud-spanner-jdbc" % "2.25.0"
+libraryDependencies += "com.google.cloud" % "google-cloud-spanner-jdbc" % "2.25.1"
 ```
 <!--- {x-version-update-end} -->
 
@@ -105,6 +105,9 @@ The Cloud Spanner JDBC driver supports the following connection URL properties.
 these can also be supplied in a Properties instance that is passed to the
 `DriverManager#getConnection(String url, Properties properties)` method.
 
+See [Supported Connection Properties](documentation/connection_properties.md) for a full list of all
+supported connection properties.
+
 #### Commonly Used Properties
 - credentials (String): URL for the credentials file to use for the connection. If you do not specify any credentials at all, the default credentials of the environment as returned by `GoogleCredentials#getApplicationDefault()` is used. Example: `jdbc:cloudspanner:/projects/my-project/instances/my-instance/databases/my-db;credentials=/path/to/credentials.json`
 - autocommit (boolean): Sets the initial autocommit mode for the connection. Default is true.
@@ -135,7 +138,8 @@ these can also be supplied in a Properties instance that is passed to the
 - oauthToken (string): A valid pre-existing OAuth token to use for authentication for this connection. Setting this property will take precedence over any value set for a credentials file.
 - lenient (boolean): Enable this to force the JDBC driver to ignore unknown properties in the connection URL. Some applications automatically add additional properties to the URL that are not recognized by the JDBC driver. Normally, the JDBC driver will reject this, unless `lenient` mode is enabled.
 
-For a full list of supported connection properties see https://github.com/googleapis/java-spanner/blob/main/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionProperties.java.
+For a full list of supported connection properties, see
+[Supported Connection Properties](documentation/connection_properties.md).
 
 ### Jar with Dependencies
 A single jar with all dependencies can be downloaded from https://repo1.maven.org/maven2/com/google/cloud/google-cloud-spanner-jdbc/latest
@@ -259,7 +263,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
 [developer-console]: https://console.developers.google.com/
 [create-project]: https://cloud.google.com/resource-manager/docs/creating-managing-projects
 [cloud-sdk]: https://cloud.google.com/sdk/
-[troubleshooting]: https://github.com/googleapis/google-cloud-common/blob/main/troubleshooting/readme.md#troubleshooting
+[troubleshooting]: https://github.com/googleapis/google-cloud-java/blob/main/TROUBLESHOOTING.md
 [contributing]: https://github.com/googleapis/java-spanner-jdbc/blob/main/CONTRIBUTING.md
 [code-of-conduct]: https://github.com/googleapis/java-spanner-jdbc/blob/main/CODE_OF_CONDUCT.md#contributor-code-of-conduct
 [license]: https://github.com/googleapis/java-spanner-jdbc/blob/main/LICENSE
diff --git a/documentation/connection_properties.md b/documentation/connection_properties.md
new file mode 100644
index 0000000..8e157ff
--- /dev/null
+++ b/documentation/connection_properties.md
@@ -0,0 +1,56 @@
+# Supported Connection Properties
+
+This file contains all supported connection properties for the Spanner JDBC driver. These properties can be specified both in the connection URL and in the Properties map that is used to create a connection.
+
+The 'Context' value indicates whether the property can only be set when a connection is created (STARTUP), or whether the value can also be changed after a connection has been created.
+
+| Name | Description | Default | Enum values | Context |
+|------|-------------|---------|-------------|---------|
+| auto_batch_dml | Automatically buffer DML statements that are executed on this connection and execute them as one batch when a non-DML statement is executed, or when the current transaction is committed. The update count that is returned for DML statements that are buffered is by default 1. This default can be changed by setting the connection variable auto_batch_dml_update_count to value other than 1. This setting is only in read/write transactions. DML statements in auto-commit mode are executed directly. | false |  | USER |
+| auto_batch_dml_update_count | DML statements that are executed when auto_batch_dml is set to true, are not directly sent to Spanner, but are buffered in the client until the batch is flushed. This property determines the update count that is returned for these DML statements. The default is 1, as that is the update count that is expected by most ORMs (e.g. Hibernate). | 1 |  | USER |
+| auto_batch_dml_update_count_verification | The update count that is returned for DML statements that are buffered during an automatic DML batch is by default 1. This value can be changed by setting the connection variable auto_batch_dml_update_count. The update counts that are returned by Spanner when the DML statements are actually executed are verified against the update counts that were returned when they were buffered. If these do not match, a com.google.cloud.spanner.DmlBatchUpdateCountVerificationFailedException will be thrown. You can disable this verification by setting auto_batch_dml_update_count_verification to false. | true |  | USER |
+| autocommit | Should the connection start in autocommit (true/false) | true |  | USER |
+| autocommit_dml_mode | Should the connection automatically retry Aborted errors (true/false) | TRANSACTIONAL |  | USER |
+| autoconfigemulator | Automatically configure the connection to try to connect to the Cloud Spanner emulator (true/false). The instance and database in the connection string will automatically be created if these do not yet exist on the emulator. Add dialect=postgresql to the connection string to make sure that the database that is created uses the PostgreSQL dialect. | false |  | STARTUP |
+| autopartitionmode | Execute all queries on this connection as partitioned queries. Executing a query that cannot be partitioned will fail. Executing a query in a read/write transaction will also fail. | false |  | USER |
+| channelprovider | The name of the channel provider class. The name must reference an implementation of ExternalChannelProvider. If this property is not set, the connection will use the default grpc channel provider. |  |  | STARTUP |
+| connection_state_type | The type of connection state to use for this connection. Can only be set at start up. If no value is set, then the database dialect default will be used, which is NON_TRANSACTIONAL for GoogleSQL and TRANSACTIONAL for PostgreSQL. |  |  | STARTUP |
+| credentials | The location of the credentials file to use for this connection. If neither this property or encoded credentials are set, the connection will use the default Google Cloud credentials for the runtime environment. |  |  | STARTUP |
+| credentialsprovider | The class name of the com.google.api.gax.core.CredentialsProvider implementation that should be used to obtain credentials for connections. |  |  | STARTUP |
+| databaserole | Sets the database role to use for this connection. The default is privileges assigned to IAM role |  |  | STARTUP |
+| databoostenabled | Enable data boost for all partitioned queries that are executed by this connection. This setting is only used for partitioned queries and is ignored by all other statements. | false |  | USER |
+| ddlintransactionmode | Determines how the connection should handle DDL statements in a read/write transaction. | ALLOW_IN_EMPTY_TRANSACTION |  | USER |
+| delaytransactionstartuntilfirstwrite | Enabling this option will delay the actual start of a read/write transaction until the first write operation is seen in that transaction. All reads that happen before the first write in a transaction will instead be executed as if the connection was in auto-commit mode. Enabling this option will make read/write transactions lose their SERIALIZABLE isolation level. Read operations that are executed after the first write operation in a read/write transaction will be executed using the read/write transaction. Enabling this mode can reduce locking and improve performance for applications that can handle the lower transaction isolation semantics. | false |  | USER |
+| dialect | Sets the dialect to use for new databases that are created by this connection. | GOOGLE_STANDARD_SQL |  | STARTUP |
+| directed_read | The directed read options to apply to read-only transactions. |  |  | USER |
+| enableapitracing | Add OpenTelemetry traces for each individual RPC call. Enable this to get a detailed view of each RPC that is being executed by your application, or if you want to debug potential latency problems caused by RPCs that are being retried. |  |  | STARTUP |
+| enableendtoendtracing | Enable end-to-end tracing (true/false) to generate traces for both the time that is spent in the client, as well as time that is spent in the Spanner server. Server side traces can only go to Google Cloud Trace, so to see end to end traces, the application should configure an exporter that exports the traces to Google Cloud Trace. | false |  | STARTUP |
+| enableextendedtracing | Include the SQL string in the OpenTelemetry traces that are generated by this connection. The SQL string is added as the standard OpenTelemetry attribute 'db.statement'. |  |  | STARTUP |
+| encodedcredentials | Base64-encoded credentials to use for this connection. If neither this property or a credentials location are set, the connection will use the default Google Cloud credentials for the runtime environment. |  |  | STARTUP |
+| endpoint | The endpoint that the JDBC driver should connect to. The default is the default Spanner production endpoint when autoConfigEmulator=false, and the default Spanner emulator endpoint (localhost:9010) when autoConfigEmulator=true. This property takes precedence over any host name at the start of the connection URL. |  |  | STARTUP |
+| keeptransactionalive | Enabling this option will trigger the connection to keep read/write transactions alive by executing a SELECT 1 query once every 10 seconds if no other statements are being executed. This option should be used with caution, as it can keep transactions alive and hold on to locks longer than intended. This option should typically be used for CLI-type application that might wait for user input for a longer period of time. | false |  | USER |
+| lenient | Silently ignore unknown properties in the connection string/properties (true/false) | false |  | STARTUP |
+| maxcommitdelay | The max delay that Spanner may apply to commit requests to improve throughput. |  |  | USER |
+| maxpartitionedparallelism | The max partitions hint value to use for partitioned queries. Use 0 if you do not want to specify a hint. | 1 |  | USER |
+| maxpartitions | The max partitions hint value to use for partitioned queries. Use 0 if you do not want to specify a hint. | 0 |  | USER |
+| maxsessions | The maximum number of sessions in the backing session pool. The default is 400. |  |  | STARTUP |
+| minsessions | The minimum number of sessions in the backing session pool. The default is 100. |  |  | STARTUP |
+| numchannels | The number of gRPC channels to use to communicate with Cloud Spanner. The default is 4. |  |  | STARTUP |
+| oauthtoken | A valid pre-existing OAuth token to use for authentication for this connection. Setting this property will take precedence over any value set for a credentials file. |  |  | STARTUP |
+| optimizerstatisticspackage | Sets the query optimizer statistics package to use for this connection. |  |  | USER |
+| optimizerversion | Sets the default query optimizer version to use for this connection. |  |  | USER |
+| read_only_staleness | The read-only staleness to use for read-only transactions and single-use queries. | strong |  | USER |
+| readonly | Should the connection start in read-only mode (true/false) | false |  | USER |
+| retryabortsinternally | Should the connection automatically retry Aborted errors (true/false) | true |  | USER |
+| returncommitstats | Request that Spanner returns commit statistics for read/write transactions (true/false) | false |  | USER |
+| routetoleader | Should read/write transactions and partitioned DML be routed to leader region (true/false) | true |  | STARTUP |
+| rpcpriority | Sets the priority for all RPC invocations from this connection (HIGH/MEDIUM/LOW). The default is HIGH. |  |  | USER |
+| savepoint_support | Determines the behavior of the connection when savepoints are used. | FAIL_AFTER_ROLLBACK |  | USER |
+| tracing_prefix | The prefix that will be prepended to all OpenTelemetry traces that are generated by a Connection. | CloudSpanner |  | STARTUP |
+| trackconnectionleaks | Capture the call stack of the thread that created a connection. This will pre-create a LeakedConnectionException already when a connection is created. This can be disabled, for example if a monitoring system logs the pre-created exception. If disabled, the LeakedConnectionException will only be created when an actual connection leak is detected. The stack trace of the exception will in that case not contain the call stack of when the connection was created. | true |  | STARTUP |
+| tracksessionleaks | Capture the call stack of the thread that checked out a session of the session pool. This will pre-create a LeakedSessionException already when a session is checked out. This can be disabled, for example if a monitoring system logs the pre-created exception. If disabled, the LeakedSessionException will only be created when an actual session leak is detected. The stack trace of the exception will in that case not contain the call stack of when the session was checked out. | true |  | STARTUP |
+| useautosavepointsforemulator | Automatically creates savepoints for each statement in a read/write transaction when using the Emulator. This is no longer needed when using Emulator version 1.5.23 or higher. | false |  | STARTUP |
+| useplaintext | Use a plain text communication channel (i.e. non-TLS) for communicating with the server (true/false). Set this value to true for communication with the Cloud Spanner emulator. | false |  | STARTUP |
+| useragent | The custom user-agent property name to use when communicating with Cloud Spanner. This property is intended for internal library usage, and should not be set by applications. |  |  | STARTUP |
+| usevirtualgrpctransportthreads | Use a virtual thread instead of a platform thread for the gRPC executor (true/false). This option only has any effect if the application is running on Java 21 or higher. In all other cases, the option is ignored. | false |  | STARTUP |
+| usevirtualthreads | Use a virtual thread instead of a platform thread for each connection (true/false). This option only has any effect if the application is running on Java 21 or higher. In all other cases, the option is ignored. | false |  | STARTUP |
diff --git a/pom.xml b/pom.xml
index ec1d8ba..d535c3d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <artifactId>google-cloud-spanner-jdbc</artifactId>
-  <version>2.25.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner-jdbc:current} -->
+  <version>2.25.2-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner-jdbc:current} -->
   <packaging>jar</packaging>
   <name>Google Cloud Spanner JDBC</name>
   <url>https://github.com/googleapis/java-spanner-jdbc</url>
@@ -210,13 +210,13 @@
     <dependency>
       <groupId>com.google.cloud</groupId>
       <artifactId>google-cloud-trace</artifactId>
-      <version>2.54.0</version>
+      <version>2.55.0</version>
       <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>com.google.api.grpc</groupId>
       <artifactId>proto-google-cloud-trace-v1</artifactId>
-      <version>2.54.0</version>
+      <version>2.55.0</version>
       <scope>test</scope>
     </dependency>
 
@@ -241,7 +241,6 @@
         <configuration>
           <excludes>
             <exclude>com.google.cloud.spanner.jdbc.it.**</exclude>
-            <exclude>com.google.cloud.spanner.jdbc.JdbcStatementTimeoutTest</exclude>
           </excludes>
           <reportNameSuffix>sponge_log</reportNameSuffix>
           <systemPropertyVariables>
@@ -334,6 +333,25 @@
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>flatten-maven-plugin</artifactId>
       </plugin>
+
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>exec-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>generate_connection_properties_documentation</id>
+            <phase>test</phase>
+            <goals>
+              <goal>java</goal>
+            </goals>
+            <configuration>
+              <mainClass>com.google.cloud.spanner.connection.ConnectionPropertiesFileGenerator</mainClass>
+              <classpathScope>test</classpathScope>
+              <skip>false</skip>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
     <pluginManagement>
       <plugins>
diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml
index cd4967b..6761e1c 100644
--- a/samples/install-without-bom/pom.xml
+++ b/samples/install-without-bom/pom.xml
@@ -29,7 +29,7 @@
     <dependency>
       <groupId>com.google.cloud</groupId>
       <artifactId>google-cloud-spanner-jdbc</artifactId>
-      <version>2.25.0</version>
+      <version>2.25.1</version>
     </dependency>
     <!-- [END spanner-jdbc_install_without_bom] -->
 
diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml
index 2fde582..38b687e 100644
--- a/samples/snapshot/pom.xml
+++ b/samples/snapshot/pom.xml
@@ -28,7 +28,7 @@
     <dependency>
       <groupId>com.google.cloud</groupId>
       <artifactId>google-cloud-spanner-jdbc</artifactId>
-      <version>2.25.1-SNAPSHOT</version>
+      <version>2.25.2-SNAPSHOT</version>
     </dependency>
     <!-- {x-version-update-end} -->
 
diff --git a/src/main/java/com/google/cloud/spanner/connection/ConnectionPropertiesHelper.java b/src/main/java/com/google/cloud/spanner/connection/ConnectionPropertiesHelper.java
new file mode 100644
index 0000000..7e64b8f
--- /dev/null
+++ b/src/main/java/com/google/cloud/spanner/connection/ConnectionPropertiesHelper.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2024 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.cloud.spanner.connection;
+
+import com.google.api.core.InternalApi;
+import com.google.common.collect.ImmutableList;
+import java.sql.DriverPropertyInfo;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+// TODO: Remove this class when the Connection API has made the list of properties public.
+@InternalApi
+public class ConnectionPropertiesHelper {
+  public static ImmutableList<ConnectionProperty<?>> VALID_CONNECTION_PROPERTIES =
+      ImmutableList.copyOf(
+          ConnectionProperties.CONNECTION_PROPERTIES.values().stream()
+              .sorted(Comparator.comparing(ConnectionProperty::getName))
+              .collect(Collectors.toList()));
+
+  public static DriverPropertyInfo toDriverPropertyInfo(
+      String connectionUri, ConnectionProperty<?> connectionProperty) {
+    DriverPropertyInfo result =
+        new DriverPropertyInfo(
+            connectionProperty.getName(),
+            parseUriProperty(
+                connectionUri,
+                connectionProperty.getName(),
+                connectionProperty.getDefaultValue() == null
+                    ? null
+                    : connectionProperty.getDefaultValue().toString()));
+    result.description = connectionProperty.getDescription();
+    result.choices =
+        connectionProperty.getValidValues() == null
+            ? null
+            : Arrays.stream(connectionProperty.getValidValues())
+                .map(Object::toString)
+                .toArray(String[]::new);
+    return result;
+  }
+
+  public static String getConnectionPropertyName(ConnectionProperty<?> connectionProperty) {
+    return connectionProperty.getName();
+  }
+
+  private static String parseUriProperty(String uri, String property, String defaultValue) {
+    Pattern pattern = Pattern.compile(String.format("(?is)(?:;|\\?)%s=(.*?)(?:;|$)", property));
+    Matcher matcher = pattern.matcher(uri);
+    if (matcher.find() && matcher.groupCount() == 1) {
+      return matcher.group(1);
+    }
+    return defaultValue;
+  }
+
+  private ConnectionPropertiesHelper() {}
+}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcStatement.java b/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcStatement.java
index f3a1539..3152445 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcStatement.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcStatement.java
@@ -24,6 +24,7 @@ import com.google.cloud.spanner.connection.AbstractStatementParser;
 import com.google.cloud.spanner.connection.Connection;
 import com.google.cloud.spanner.connection.StatementResult;
 import com.google.cloud.spanner.connection.StatementResult.ClientSideStatementType;
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Stopwatch;
 import com.google.rpc.Code;
 import java.sql.ResultSet;
@@ -35,6 +36,7 @@ import java.util.Arrays;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.function.Supplier;
+import javax.annotation.Nonnull;
 
 /** Base class for Cloud Spanner JDBC {@link Statement}s */
 abstract class AbstractJdbcStatement extends AbstractJdbcWrapper implements Statement {
@@ -45,7 +47,7 @@ abstract class AbstractJdbcStatement extends AbstractJdbcWrapper implements Stat
   private boolean closeOnCompletion;
   private boolean poolable;
   private final JdbcConnection connection;
-  private int queryTimeout;
+  private Duration queryTimeout = Duration.ZERO;
 
   AbstractJdbcStatement(JdbcConnection connection) throws SQLException {
     this.connection = connection;
@@ -148,13 +150,22 @@ abstract class AbstractJdbcStatement extends AbstractJdbcWrapper implements Stat
    */
   StatementTimeout setTemporaryStatementTimeout() throws SQLException {
     StatementTimeout originalTimeout = null;
-    if (getQueryTimeout() > 0) {
+    if (!getQueryTimeoutDuration().isZero()) {
       if (connection.getSpannerConnection().hasStatementTimeout()) {
         TimeUnit unit = getAppropriateTimeUnit();
         originalTimeout =
             StatementTimeout.of(connection.getSpannerConnection().getStatementTimeout(unit), unit);
       }
-      connection.getSpannerConnection().setStatementTimeout(getQueryTimeout(), TimeUnit.SECONDS);
+      Duration queryTimeout = getQueryTimeoutDuration();
+      if (queryTimeout.getNano() > 0) {
+        connection
+            .getSpannerConnection()
+            .setStatementTimeout(queryTimeout.toMillis(), TimeUnit.MILLISECONDS);
+      } else {
+        connection
+            .getSpannerConnection()
+            .setStatementTimeout(queryTimeout.getSeconds(), TimeUnit.SECONDS);
+      }
     }
     return originalTimeout;
   }
@@ -164,7 +175,7 @@ abstract class AbstractJdbcStatement extends AbstractJdbcWrapper implements Stat
    * has been executed.
    */
   void resetStatementTimeout(StatementTimeout originalTimeout) throws SQLException {
-    if (getQueryTimeout() > 0) {
+    if (!getQueryTimeoutDuration().isZero()) {
       if (originalTimeout == null) {
         connection.getSpannerConnection().clearStatementTimeout();
       } else {
@@ -317,14 +328,26 @@ abstract class AbstractJdbcStatement extends AbstractJdbcWrapper implements Stat
 
   @Override
   public int getQueryTimeout() throws SQLException {
+    return (int) getQueryTimeoutDuration().getSeconds();
+  }
+
+  @VisibleForTesting
+  @Nonnull
+  Duration getQueryTimeoutDuration() throws SQLException {
     checkClosed();
-    return queryTimeout;
+    return this.queryTimeout;
   }
 
   @Override
   public void setQueryTimeout(int seconds) throws SQLException {
+    setQueryTimeout(Duration.ofSeconds(seconds));
+  }
+
+  @VisibleForTesting
+  void setQueryTimeout(@Nonnull Duration duration) throws SQLException {
+    JdbcPreconditions.checkArgument(!duration.isNegative(), "Timeout must be >= 0");
     checkClosed();
-    this.queryTimeout = seconds;
+    this.queryTimeout = duration;
   }
 
   @Override
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java
index d87aab0..1c499ab 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java
@@ -22,7 +22,8 @@ import com.google.cloud.spanner.SessionPoolOptions;
 import com.google.cloud.spanner.SessionPoolOptionsHelper;
 import com.google.cloud.spanner.SpannerException;
 import com.google.cloud.spanner.connection.ConnectionOptions;
-import com.google.cloud.spanner.connection.ConnectionOptions.ConnectionProperty;
+import com.google.cloud.spanner.connection.ConnectionPropertiesHelper;
+import com.google.cloud.spanner.connection.ConnectionProperty;
 import com.google.rpc.Code;
 import io.opentelemetry.api.OpenTelemetry;
 import java.sql.Connection;
@@ -265,29 +266,16 @@ public class JdbcDriver implements Driver {
   @Override
   public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
     String connectionUri = appendPropertiesToUrl(url.substring(5), info);
-    DriverPropertyInfo[] res = new DriverPropertyInfo[ConnectionOptions.VALID_PROPERTIES.size()];
+    DriverPropertyInfo[] res =
+        new DriverPropertyInfo[ConnectionPropertiesHelper.VALID_CONNECTION_PROPERTIES.size()];
     int i = 0;
-    for (ConnectionProperty prop : ConnectionOptions.VALID_PROPERTIES) {
-      res[i] =
-          new DriverPropertyInfo(
-              prop.getName(),
-              parseUriProperty(connectionUri, prop.getName(), prop.getDefaultValue()));
-      res[i].description = prop.getDescription();
-      res[i].choices = prop.getValidValues();
+    for (ConnectionProperty<?> prop : ConnectionPropertiesHelper.VALID_CONNECTION_PROPERTIES) {
+      res[i] = ConnectionPropertiesHelper.toDriverPropertyInfo(connectionUri, prop);
       i++;
     }
     return res;
   }
 
-  private String parseUriProperty(String uri, String property, String defaultValue) {
-    Pattern pattern = Pattern.compile(String.format("(?is)(?:;|\\?)%s=(.*?)(?:;|$)", property));
-    Matcher matcher = pattern.matcher(uri);
-    if (matcher.find() && matcher.groupCount() == 1) {
-      return matcher.group(1);
-    }
-    return defaultValue;
-  }
-
   @Override
   public int getMajorVersion() {
     return MAJOR_VERSION;
diff --git a/versions.txt b/versions.txt
index 56bc2ad..bd7d563 100644
--- a/versions.txt
+++ b/versions.txt
@@ -1,4 +1,4 @@
 # Format:
 # module:released-version:current-version
 
-google-cloud-spanner-jdbc:2.25.0:2.25.1-SNAPSHOT
+google-cloud-spanner-jdbc:2.25.1:2.25.2-SNAPSHOT


Test patch:
diff --git a/src/test/java/com/google/cloud/spanner/connection/ConnectionPropertiesFileGenerator.java b/src/test/java/com/google/cloud/spanner/connection/ConnectionPropertiesFileGenerator.java
new file mode 100644
index 0000000..fe8dd9c
--- /dev/null
+++ b/src/test/java/com/google/cloud/spanner/connection/ConnectionPropertiesFileGenerator.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2024 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.cloud.spanner.connection;
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+/** Generator for the documentation/connection_properties.md file. */
+public class ConnectionPropertiesFileGenerator {
+
+  public static void main(String[] args) throws IOException {
+    StringBuilder builder =
+        new StringBuilder("# Supported Connection Properties\n\n")
+            .append(
+                "This file contains all supported connection properties for the Spanner JDBC driver. "
+                    + "These properties can be specified both in the connection URL and in the Properties map "
+                    + "that is used to create a connection.\n\n"
+                    + "The 'Context' value indicates whether the property can only be set when a connection is "
+                    + "created (STARTUP), or whether the value can also be changed after a connection has been "
+                    + "created.\n\n");
+    builder.append("| Name | Description | Default | Enum values | Context |\n");
+    builder.append("|------|-------------|---------|-------------|---------|\n");
+    for (ConnectionProperty<?> connectionProperty :
+        ConnectionPropertiesHelper.VALID_CONNECTION_PROPERTIES) {
+      builder
+          .append("| ")
+          .append(connectionProperty.getName())
+          .append(" | ")
+          .append(connectionProperty.getDescription())
+          .append(" | ")
+          .append(
+              connectionProperty.getDefaultValue() == null
+                  ? ""
+                  : connectionProperty.getDefaultValue().toString())
+          .append(" | ")
+          .append(getValidValues(connectionProperty))
+          .append(" | ")
+          .append(connectionProperty.getContext())
+          .append(" |\n");
+    }
+    try (BufferedWriter writer =
+        new BufferedWriter(new FileWriter("documentation/connection_properties.md"))) {
+      writer.write(builder.toString());
+    }
+  }
+
+  static <T> String getValidValues(ConnectionProperty<T> connectionProperty) {
+    return connectionProperty.getValidValues() == null
+        ? ""
+        : Arrays.stream(connectionProperty.getValidValues())
+            .map(Object::toString)
+            .collect(Collectors.joining(", "));
+  }
+}
diff --git a/src/test/java/com/google/cloud/spanner/jdbc/JdbcDriverTest.java b/src/test/java/com/google/cloud/spanner/jdbc/JdbcDriverTest.java
index 13efeb8..020848e 100644
--- a/src/test/java/com/google/cloud/spanner/jdbc/JdbcDriverTest.java
+++ b/src/test/java/com/google/cloud/spanner/jdbc/JdbcDriverTest.java
@@ -24,8 +24,7 @@ import static org.junit.Assert.fail;
 
 import com.google.cloud.ServiceOptions;
 import com.google.cloud.spanner.MockSpannerServiceImpl;
-import com.google.cloud.spanner.connection.ConnectionOptions;
-import com.google.cloud.spanner.connection.ConnectionOptions.ConnectionProperty;
+import com.google.cloud.spanner.connection.ConnectionPropertiesHelper;
 import com.google.cloud.spanner.connection.SpannerPool;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableList;
@@ -174,10 +173,12 @@ public class JdbcDriverTest {
         JdbcDriver.getRegisteredDriver()
             .getPropertyInfo(
                 "jdbc:cloudspanner:/projects/p/instances/i/databases/d", new Properties());
-    assertThat(props).hasLength(ConnectionOptions.VALID_PROPERTIES.size());
+    assertThat(props).hasLength(ConnectionPropertiesHelper.VALID_CONNECTION_PROPERTIES.size());
 
     Collection<String> validConnectionPropertyNames =
-        Collections2.transform(ConnectionOptions.VALID_PROPERTIES, ConnectionProperty::getName);
+        Collections2.transform(
+            ConnectionPropertiesHelper.VALID_CONNECTION_PROPERTIES,
+            ConnectionPropertiesHelper::getConnectionPropertyName);
     Collection<String> driverPropertyNames =
         Collections2.transform(ImmutableList.copyOf(props), input -> input.name);
     assertThat(driverPropertyNames).containsExactlyElementsIn(validConnectionPropertyNames);
diff --git a/src/test/java/com/google/cloud/spanner/jdbc/JdbcStatementTimeoutTest.java b/src/test/java/com/google/cloud/spanner/jdbc/JdbcStatementTimeoutTest.java
index a9d1840..eb876c2 100644
--- a/src/test/java/com/google/cloud/spanner/jdbc/JdbcStatementTimeoutTest.java
+++ b/src/test/java/com/google/cloud/spanner/jdbc/JdbcStatementTimeoutTest.java
@@ -27,17 +27,21 @@ import com.google.cloud.spanner.jdbc.JdbcSqlExceptionFactory.JdbcSqlTimeoutExcep
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.time.Duration;
+import org.junit.After;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
 
-/**
- * Tests setting a statement timeout. This test is by default not included in unit test runs, as the
- * minimum timeout value in JDBC is 1 second, which again makes this test relatively slow.
- */
+/** Tests setting a statement timeout. */
 @RunWith(JUnit4.class)
 public class JdbcStatementTimeoutTest extends AbstractMockServerTest {
 
+  @After
+  public void resetExecutionTimes() {
+    mockSpanner.removeAllExecutionTimes();
+  }
+
   @Test
   public void testExecuteTimeout() throws SQLException {
     try (java.sql.Connection connection = createJdbcConnection()) {
@@ -50,7 +54,7 @@ public class JdbcStatementTimeoutTest extends AbstractMockServerTest {
         // Simulate that executeSql takes 2 seconds and set a statement timeout of 1 second.
         mockSpanner.setExecuteSqlExecutionTime(
             SimulatedExecutionTime.ofMinimumAndRandomTime(2000, 0));
-        statement.setQueryTimeout(1);
+        ((JdbcStatement) statement).setQueryTimeout(Duration.ofMillis(5L));
         assertThrows(
             JdbcSqlTimeoutException.class, () -> statement.execute(INSERT_STATEMENT.getSql()));
       }
@@ -74,7 +78,7 @@ public class JdbcStatementTimeoutTest extends AbstractMockServerTest {
         // second.
         mockSpanner.setExecuteStreamingSqlExecutionTime(
             SimulatedExecutionTime.ofMinimumAndRandomTime(2000, 0));
-        statement.setQueryTimeout(1);
+        ((JdbcStatement) statement).setQueryTimeout(Duration.ofMillis(5L));
         assertThrows(
             JdbcSqlTimeoutException.class,
             () -> statement.executeQuery(SELECT_RANDOM_STATEMENT.getSql()));
@@ -92,7 +96,7 @@ public class JdbcStatementTimeoutTest extends AbstractMockServerTest {
         // Simulate that executeSql takes 2 seconds and set a statement timeout of 1 second.
         mockSpanner.setExecuteSqlExecutionTime(
             SimulatedExecutionTime.ofMinimumAndRandomTime(2000, 0));
-        statement.setQueryTimeout(1);
+        ((JdbcStatement) statement).setQueryTimeout(Duration.ofMillis(5L));
         assertThrows(
             JdbcSqlTimeoutException.class,
             () -> statement.executeUpdate(INSERT_STATEMENT.getSql()));
@@ -112,7 +116,7 @@ public class JdbcStatementTimeoutTest extends AbstractMockServerTest {
         // Simulate that executeBatchDml takes 2 seconds and set a statement timeout of 1 second.
         mockSpanner.setExecuteBatchDmlExecutionTime(
             SimulatedExecutionTime.ofMinimumAndRandomTime(2000, 0));
-        statement.setQueryTimeout(1);
+        ((JdbcStatement) statement).setQueryTimeout(Duration.ofMillis(5L));
         statement.addBatch(INSERT_STATEMENT.getSql());
         assertThrows(JdbcSqlTimeoutException.class, statement::executeBatch);
       }