Repository: googleapis/java-spanner-jdbc
Pull request #1872 (2024-12-17 16:56:22)

chore(deps): update dependency com.google.cloud:libraries-bom to v26.52.0
This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud:libraries-bom](https://cloud.google.com/java/docs/bom) ([source](https://redirect.github.com/googleapis/java-cloud-bom)) | `26.51.0` -> `26.52.0` | [![age](https://developer.mend.io/api/mc/badges/age/maven/com.google.cloud:libraries-bom/26.52.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/com.google.cloud:libraries-bom/26.52.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/com.google.cloud:libraries-bom/26.51.0/26.52.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/com.google.cloud:libraries-bom/26.51.0/26.52.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>googleapis/java-cloud-bom (com.google.cloud:libraries-bom)</summary>

### [`v26.52.0`](https://redirect.github.com/googleapis/java-cloud-bom/blob/HEAD/CHANGELOG.md#26520-2024-12-17)

[Compare Source](https://redirect.github.com/googleapis/java-cloud-bom/compare/v26.51.0...v26.52.0)

##### Dependencies

-   update dependency com.google.cloud:first-party-dependencies to v3.41.0 ([#&#8203;6875](https://redirect.github.com/googleapis/java-cloud-bom/issues/6875)) ([eb138b6](https://redirect.github.com/googleapis/java-cloud-bom/commit/eb138b6a143edbb209b28342886504b74fe6b83f))
-   update dependency com.google.cloud:gapic-libraries-bom to v1.49.0 ([#&#8203;6892](https://redirect.github.com/googleapis/java-cloud-bom/issues/6892)) ([e095472](https://redirect.github.com/googleapis/java-cloud-bom/commit/e095472a057411f555f34612357d79d56a51d661))
-   update dependency com.google.cloud:google-cloud-bigquery to v2.45.0 ([#&#8203;6886](https://redirect.github.com/googleapis/java-cloud-bom/issues/6886)) ([cf9fe6e](https://redirect.github.com/googleapis/java-cloud-bom/commit/cf9fe6e13451f04e52d821deb8dcd87c74e213de))
-   update dependency com.google.cloud:google-cloud-bigquerystorage-bom to v3.11.0 ([#&#8203;6881](https://redirect.github.com/googleapis/java-cloud-bom/issues/6881)) ([b3da142](https://redirect.github.com/googleapis/java-cloud-bom/commit/b3da1426ed91ab19089afa07f51bf4512df47cf2))
-   update dependency com.google.cloud:google-cloud-bigtable-bom to v2.50.0 ([#&#8203;6874](https://redirect.github.com/googleapis/java-cloud-bom/issues/6874)) ([79bb5be](https://redirect.github.com/googleapis/java-cloud-bom/commit/79bb5bef2ecc1fd009b3435f9cd89a95a0077f54))
-   update dependency com.google.cloud:google-cloud-bigtable-bom to v2.51.0 ([#&#8203;6893](https://redirect.github.com/googleapis/java-cloud-bom/issues/6893)) ([125ffe4](https://redirect.github.com/googleapis/java-cloud-bom/commit/125ffe4a8f41703faef0df333ee6a28b9a6fb9ed))
-   update dependency com.google.cloud:google-cloud-datastore-bom to v2.25.0 ([#&#8203;6876](https://redirect.github.com/googleapis/java-cloud-bom/issues/6876)) ([17e75dc](https://redirect.github.com/googleapis/java-cloud-bom/commit/17e75dc0cf031ea91560c33101e6238df29bdd13))
-   update dependency com.google.cloud:google-cloud-datastore-bom to v2.25.1 ([#&#8203;6888](https://redirect.github.com/googleapis/java-cloud-bom/issues/6888)) ([a90efed](https://redirect.github.com/googleapis/java-cloud-bom/commit/a90efeda938370e5207aa4c6e527b71a301a4a8e))
-   update dependency com.google.cloud:google-cloud-firestore-bom to v3.30.1 ([#&#8203;6873](https://redirect.github.com/googleapis/java-cloud-bom/issues/6873)) ([699c4db](https://redirect.github.com/googleapis/java-cloud-bom/commit/699c4db42e8154129fb1ff2a57ccc1cc34d565bf))
-   update dependency com.google.cloud:google-cloud-firestore-bom to v3.30.2 ([#&#8203;6880](https://redirect.github.com/googleapis/java-cloud-bom/issues/6880)) ([050a33f](https://redirect.github.com/googleapis/java-cloud-bom/commit/050a33ff4fc60521fa0c3d1ba3d95e6434ed8e26))
-   update dependency com.google.cloud:google-cloud-logging-bom to v3.21.0 ([#&#8203;6884](https://redirect.github.com/googleapis/java-cloud-bom/issues/6884)) ([cb319f3](https://redirect.github.com/googleapis/java-cloud-bom/commit/cb319f39fac6ea3dfd1c61d98dd2cb6726fc4658))
-   update dependency com.google.cloud:google-cloud-logging-logback to v0.132.0-alpha ([#&#8203;6887](https://redirect.github.com/googleapis/java-cloud-bom/issues/6887)) ([30d9b73](https://redirect.github.com/googleapis/java-cloud-bom/commit/30d9b73af47eeb2af6959009dae36c06be6e1fd1))
-   update dependency com.google.cloud:google-cloud-nio to v0.127.28 ([#&#8203;6882](https://redirect.github.com/googleapis/java-cloud-bom/issues/6882)) ([0ae4361](https://redirect.github.com/googleapis/java-cloud-bom/commit/0ae43614031951631a4fe5c0016708f0ac548cb2))
-   update dependency com.google.cloud:google-cloud-pubsub-bom to v1.135.0 ([#&#8203;6877](https://redirect.github.com/googleapis/java-cloud-bom/issues/6877)) ([df7b955](https://redirect.github.com/googleapis/java-cloud-bom/commit/df7b95582d50907f3103ed5e0aee7baec63ae6ff))
-   update dependency com.google.cloud:google-cloud-pubsublite-bom to v1.15.0 ([#&#8203;6885](https://redirect.github.com/googleapis/java-cloud-bom/issues/6885)) ([eb74bc2](https://redirect.github.com/googleapis/java-cloud-bom/commit/eb74bc2c7e179252435dd5344528d28af0aa7269))
-   update dependency com.google.cloud:google-cloud-spanner-bom to v6.83.0 ([#&#8203;6889](https://redirect.github.com/googleapis/java-cloud-bom/issues/6889)) ([2fc8d1a](https://redirect.github.com/googleapis/java-cloud-bom/commit/2fc8d1af732814d3aa6e02b96d0f00f9482fa9cf))
-   update dependency com.google.cloud:google-cloud-spanner-jdbc to v2.25.1 ([#&#8203;6890](https://redirect.github.com/googleapis/java-cloud-bom/issues/6890)) ([fc4869e](https://redirect.github.com/googleapis/java-cloud-bom/commit/fc4869e8db241b43712fcef193764f12c3e4e877))
-   update dependency com.google.cloud:google-cloud-storage-bom to v2.46.0 ([#&#8203;6883](https://redirect.github.com/googleapis/java-cloud-bom/issues/6883)) ([dc38e51](https://redirect.github.com/googleapis/java-cloud-bom/commit/dc38e51220bbac43230e39caa429067588334831))
-   update dependency org.codehaus.plexus:plexus-utils to v3.6.0 ([#&#8203;6891](https://redirect.github.com/googleapis/java-cloud-bom/issues/6891)) ([4529f52](https://redirect.github.com/googleapis/java-cloud-bom/commit/4529f52a0f88567bea203d267c4a2e595dd16aa9))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/googleapis/java-spanner-jdbc).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS42OS4zIiwidXBkYXRlZEluVmVyIjoiMzkuNzIuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->


dpebot: /gcbrun

Patch:
diff --git a/pom.xml b/pom.xml
index adb86a0..d535c3d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -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>
diff --git a/samples/quickperf/pom.xml b/samples/quickperf/pom.xml
index 28ab098..b9f6a13 100644
--- a/samples/quickperf/pom.xml
+++ b/samples/quickperf/pom.xml
@@ -27,7 +27,7 @@
       <dependency>
         <groupId>com.google.cloud</groupId>
         <artifactId>libraries-bom</artifactId>
-        <version>26.51.0</version>
+        <version>26.52.0</version>
         <type>pom</type>
         <scope>import</scope>
       </dependency>
diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml
index 9bb63f3..11b8346 100644
--- a/samples/snippets/pom.xml
+++ b/samples/snippets/pom.xml
@@ -26,7 +26,7 @@
       <dependency>
         <groupId>com.google.cloud</groupId>
         <artifactId>libraries-bom</artifactId>
-        <version>26.51.0</version>
+        <version>26.52.0</version>
         <type>pom</type>
         <scope>import</scope>
       </dependency>
diff --git a/samples/spring-data-jdbc/pom.xml b/samples/spring-data-jdbc/pom.xml
index 246d743..e8fc57e 100644
--- a/samples/spring-data-jdbc/pom.xml
+++ b/samples/spring-data-jdbc/pom.xml
@@ -37,7 +37,7 @@
       <dependency>
         <groupId>com.google.cloud</groupId>
         <artifactId>libraries-bom</artifactId>
-        <version>26.51.0</version>
+        <version>26.52.0</version>
         <scope>import</scope>
         <type>pom</type>
       </dependency>
diff --git a/samples/spring-data-mybatis/pom.xml b/samples/spring-data-mybatis/pom.xml
index e958a85..6e294a1 100644
--- a/samples/spring-data-mybatis/pom.xml
+++ b/samples/spring-data-mybatis/pom.xml
@@ -35,7 +35,7 @@
       <dependency>
         <groupId>com.google.cloud</groupId>
         <artifactId>libraries-bom</artifactId>
-        <version>26.51.0</version>
+        <version>26.52.0</version>
         <scope>import</scope>
         <type>pom</type>
       </dependency>
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


Test patch:
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);
       }