Repository: googleapis/java-spanner-jdbc
Pull request #1883 (2025-01-06 16:56:38)

chore(deps): update dependency com.google.cloud:google-cloud-spanner-jdbc to v2.25.3
This PR contains the following updates:

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

---

### Release Notes

<details>
<summary>googleapis/java-spanner-jdbc (com.google.cloud:google-cloud-spanner-jdbc)</summary>

### [`v2.25.3`](https://redirect.github.com/googleapis/java-spanner-jdbc/blob/HEAD/CHANGELOG.md#2253-2025-01-06)

[Compare Source](https://redirect.github.com/googleapis/java-spanner-jdbc/compare/v2.25.2...v2.25.3)

##### Bug Fixes

-   Clear interrupted flag after cancel ([#&#8203;1880](https://redirect.github.com/googleapis/java-spanner-jdbc/issues/1880)) ([e1fd4e1](https://redirect.github.com/googleapis/java-spanner-jdbc/commit/e1fd4e131a039b80306991cc93c5c097f2538c90)), closes [#&#8203;1879](https://redirect.github.com/googleapis/java-spanner-jdbc/issues/1879)

##### Dependencies

-   Update dependency com.google.cloud:google-cloud-spanner-bom to v6.84.0 ([#&#8203;1881](https://redirect.github.com/googleapis/java-spanner-jdbc/issues/1881)) ([42ffaad](https://redirect.github.com/googleapis/java-spanner-jdbc/commit/42ffaadf0e671806269ba6c0fba8ce470911b8fe))
-   Update dependency org.springframework.boot:spring-boot to v3.4.1 ([#&#8203;1873](https://redirect.github.com/googleapis/java-spanner-jdbc/issues/1873)) ([c81941c](https://redirect.github.com/googleapis/java-spanner-jdbc/commit/c81941ca62face226804619e11b3e9de9b0aa801))
-   Update dependency org.springframework.boot:spring-boot-starter-data-jdbc to v3.4.1 ([#&#8203;1874](https://redirect.github.com/googleapis/java-spanner-jdbc/issues/1874)) ([cc3fc3e](https://redirect.github.com/googleapis/java-spanner-jdbc/commit/cc3fc3e8a2f455909eb9687a81d742250decb8c3))
-   Update dependency org.springframework.boot:spring-boot-starter-parent to v3.4.1 ([#&#8203;1876](https://redirect.github.com/googleapis/java-spanner-jdbc/issues/1876)) ([ea02e5d](https://redirect.github.com/googleapis/java-spanner-jdbc/commit/ea02e5da9d220782c2223bc7f2d4969e70a1b868))

##### Documentation

-   Add sample for using array of struct query param ([#&#8203;1871](https://redirect.github.com/googleapis/java-spanner-jdbc/issues/1871)) ([d7cb90d](https://redirect.github.com/googleapis/java-spanner-jdbc/commit/d7cb90d264eaf0793422d3bfcaadd5be2ebd6412))

</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:eyJjcmVhdGVkSW5WZXIiOiIzOS44NS4wIiwidXBkYXRlZEluVmVyIjoiMzkuODUuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->


dpebot: /gcbrun

Patch:
diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml
index 5b71398..91840fd 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.2</version>
+      <version>2.25.3</version>
     </dependency>
     <!-- [END spanner-jdbc_install_without_bom] -->
 
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 6bb7028..3fb7010 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java
@@ -25,6 +25,7 @@ import com.google.cloud.spanner.connection.ConnectionOptions;
 import com.google.cloud.spanner.connection.ConnectionOptionsHelper;
 import com.google.cloud.spanner.connection.ConnectionPropertiesHelper;
 import com.google.cloud.spanner.connection.ConnectionProperty;
+import com.google.common.annotations.VisibleForTesting;
 import com.google.rpc.Code;
 import io.opentelemetry.api.OpenTelemetry;
 import java.sql.Connection;
@@ -145,6 +146,11 @@ public class JdbcDriver implements Driver {
   private static final String JDBC_URL_FORMAT =
       "jdbc:" + ConnectionOptions.Builder.SPANNER_URI_FORMAT;
   private static final Pattern URL_PATTERN = Pattern.compile(JDBC_URL_FORMAT);
+  private static final String JDBC_EXTERNAL_HOST_FORMAT =
+      "jdbc:" + ConnectionOptions.Builder.EXTERNAL_HOST_FORMAT;
+
+  @VisibleForTesting
+  static final Pattern EXTERNAL_HOST_URL_PATTERN = Pattern.compile(JDBC_EXTERNAL_HOST_FORMAT);
 
   @InternalApi
   public static String getClientLibToken() {
@@ -213,7 +219,8 @@ public class JdbcDriver implements Driver {
     if (url != null && url.startsWith("jdbc:cloudspanner")) {
       try {
         Matcher matcher = URL_PATTERN.matcher(url);
-        if (matcher.matches()) {
+        Matcher matcherExternalHost = EXTERNAL_HOST_URL_PATTERN.matcher(url);
+        if (matcher.matches() || matcherExternalHost.matches()) {
           // strip 'jdbc:' from the URL, add any extra properties and pass on to the generic
           // Connection API
           String connectionUri = appendPropertiesToUrl(url.substring(5), info);


Test patch:
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 020848e..b4ae04f 100644
--- a/src/test/java/com/google/cloud/spanner/jdbc/JdbcDriverTest.java
+++ b/src/test/java/com/google/cloud/spanner/jdbc/JdbcDriverTest.java
@@ -16,8 +16,10 @@
 
 package com.google.cloud.spanner.jdbc;
 
+import static com.google.cloud.spanner.jdbc.JdbcDriver.EXTERNAL_HOST_URL_PATTERN;
 import static com.google.common.truth.Truth.assertThat;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -47,6 +49,7 @@ import java.sql.SQLException;
 import java.util.Collection;
 import java.util.Objects;
 import java.util.Properties;
+import java.util.regex.Matcher;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -211,4 +214,32 @@ public class JdbcDriverTest {
       assertThat(jdbc.getCode()).isEqualTo(Code.INVALID_ARGUMENT);
     }
   }
+
+  @Test
+  public void testJdbcExternalHostFormat() {
+    Matcher matcherWithoutInstance =
+        EXTERNAL_HOST_URL_PATTERN.matcher("jdbc:cloudspanner://localhost:15000/databases/test-db");
+    assertTrue(matcherWithoutInstance.matches());
+    assertEquals("test-db", matcherWithoutInstance.group("DATABASEGROUP"));
+    Matcher matcherWithProperty =
+        EXTERNAL_HOST_URL_PATTERN.matcher(
+            "jdbc:cloudspanner://localhost:15000/instances/default/databases/singers-db?usePlainText=true");
+    assertTrue(matcherWithProperty.matches());
+    assertEquals("default", matcherWithProperty.group("INSTANCEGROUP"));
+    assertEquals("singers-db", matcherWithProperty.group("DATABASEGROUP"));
+    Matcher matcherWithoutPort =
+        EXTERNAL_HOST_URL_PATTERN.matcher(
+            "jdbc:cloudspanner://localhost/instances/default/databases/test-db");
+    assertTrue(matcherWithoutPort.matches());
+    assertEquals("default", matcherWithoutPort.group("INSTANCEGROUP"));
+    assertEquals("test-db", matcherWithoutPort.group("DATABASEGROUP"));
+    Matcher matcherWithProject =
+        EXTERNAL_HOST_URL_PATTERN.matcher(
+            "jdbc:cloudspanner://localhost:15000/projects/default/instances/default/databases/singers-db");
+    assertFalse(matcherWithProject.matches());
+    Matcher matcherWithoutHost =
+        EXTERNAL_HOST_URL_PATTERN.matcher(
+            "jdbc:cloudspanner:/instances/default/databases/singers-db");
+    assertFalse(matcherWithoutHost.matches());
+  }
 }