Repository: googleapis/java-spanner-jdbc
Pull request #1927 (2025-02-21 07:22:42)

chore: support spanner prefix jdbc url
Adds `spanner` (in addition to `cloudspanner`) as a valid JDBC prefix for this driver.


Patch:
diff --git a/.github/workflows/unmanaged_dependency_check.yaml b/.github/workflows/unmanaged_dependency_check.yaml
index 7e8b946..3081961 100644
--- a/.github/workflows/unmanaged_dependency_check.yaml
+++ b/.github/workflows/unmanaged_dependency_check.yaml
@@ -14,6 +14,6 @@ jobs:
       shell: bash
       run: .kokoro/build.sh
     - name: Unmanaged dependency check
-      uses: googleapis/sdk-platform-java/java-shared-dependencies/unmanaged-dependency-check@google-cloud-shared-dependencies/v3.44.0
+      uses: googleapis/sdk-platform-java/java-shared-dependencies/unmanaged-dependency-check@google-cloud-shared-dependencies/v3.45.0
       with:
         bom-path: pom.xml
diff --git a/.kokoro/presubmit/graalvm-native-17.cfg b/.kokoro/presubmit/graalvm-native-17.cfg
index 728751d..ca80689 100644
--- a/.kokoro/presubmit/graalvm-native-17.cfg
+++ b/.kokoro/presubmit/graalvm-native-17.cfg
@@ -3,7 +3,7 @@
 # Configure the docker image for kokoro-trampoline.
 env_vars: {
   key: "TRAMPOLINE_IMAGE"
-  value: "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_b:3.44.0"
+  value: "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_b:3.45.0"
 }
 
 env_vars: {
diff --git a/.kokoro/presubmit/graalvm-native.cfg b/.kokoro/presubmit/graalvm-native.cfg
index 3915146..166f407 100644
--- a/.kokoro/presubmit/graalvm-native.cfg
+++ b/.kokoro/presubmit/graalvm-native.cfg
@@ -3,7 +3,7 @@
 # Configure the docker image for kokoro-trampoline.
 env_vars: {
   key: "TRAMPOLINE_IMAGE"
-  value: "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_a:3.44.0"
+  value: "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_a:3.45.0"
 }
 
 env_vars: {
diff --git a/pom.xml b/pom.xml
index 34131db..00ead76 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
   <parent>
     <groupId>com.google.cloud</groupId>
     <artifactId>sdk-platform-java-config</artifactId>
-    <version>3.44.0</version>
+    <version>3.45.0</version>
   </parent>
   <developers>
     <developer>
diff --git a/samples/quickperf/pom.xml b/samples/quickperf/pom.xml
index 999647d..ef4f258 100644
--- a/samples/quickperf/pom.xml
+++ b/samples/quickperf/pom.xml
@@ -12,7 +12,7 @@
   <parent>
     <groupId>com.google.cloud</groupId>
     <artifactId>sdk-platform-java-config</artifactId>
-    <version>3.44.0</version>
+    <version>3.45.0</version>
     <relativePath/>
   </parent>
 
diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml
index 22d1ed5..5d0b87d 100644
--- a/samples/snippets/pom.xml
+++ b/samples/snippets/pom.xml
@@ -9,7 +9,7 @@
   <parent>
     <groupId>com.google.cloud</groupId>
     <artifactId>sdk-platform-java-config</artifactId>
-    <version>3.44.0</version>
+    <version>3.45.0</version>
     <relativePath/>
   </parent>
 
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 3fb7010..7c9b460 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java
@@ -216,7 +216,7 @@ public class JdbcDriver implements Driver {
 
   @Override
   public Connection connect(String url, Properties info) throws SQLException {
-    if (url != null && url.startsWith("jdbc:cloudspanner")) {
+    if (url != null && (url.startsWith("jdbc:cloudspanner") || url.startsWith("jdbc:spanner"))) {
       try {
         Matcher matcher = URL_PATTERN.matcher(url);
         Matcher matcherExternalHost = EXTERNAL_HOST_URL_PATTERN.matcher(url);
@@ -271,7 +271,7 @@ public class JdbcDriver implements Driver {
 
   @Override
   public boolean acceptsURL(String url) {
-    return URL_PATTERN.matcher(url).matches();
+    return URL_PATTERN.matcher(url).matches() || EXTERNAL_HOST_URL_PATTERN.matcher(url).matches();
   }
 
   @Override


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 b4ae04f..494233f 100644
--- a/src/test/java/com/google/cloud/spanner/jdbc/JdbcDriverTest.java
+++ b/src/test/java/com/google/cloud/spanner/jdbc/JdbcDriverTest.java
@@ -135,13 +135,14 @@ public class JdbcDriverTest {
 
   @Test
   public void testConnect() throws SQLException {
-    try (Connection connection =
-        DriverManager.getConnection(
-            String.format(
-                "jdbc:cloudspanner://localhost:%d/projects/some-company.com:test-project/instances/static-test-instance/databases/test-database;usePlainText=true;credentials=%s",
-                server.getPort(), TEST_KEY_PATH))) {
-      assertThat(connection.isClosed()).isFalse();
-    }
+    for (String prefix : new String[] {"cloudspanner", "spanner"})
+      try (Connection connection =
+          DriverManager.getConnection(
+              String.format(
+                  "jdbc:%s://localhost:%d/projects/some-company.com:test-project/instances/static-test-instance/databases/test-database;usePlainText=true;credentials=%s",
+                  prefix, server.getPort(), TEST_KEY_PATH))) {
+        assertThat(connection.isClosed()).isFalse();
+      }
   }
 
   @Test(expected = SQLException.class)
@@ -215,6 +216,17 @@ public class JdbcDriverTest {
     }
   }
 
+  @Test
+  public void testAcceptsURL() throws SQLException {
+    JdbcDriver driver = JdbcDriver.getRegisteredDriver();
+    assertTrue(
+        driver.acceptsURL(
+            "jdbc:cloudspanner:/projects/my-project/instances/my-instance/databases/my-database"));
+    assertTrue(
+        driver.acceptsURL(
+            "jdbc:spanner:/projects/my-project/instances/my-instance/databases/my-database"));
+  }
+
   @Test
   public void testJdbcExternalHostFormat() {
     Matcher matcherWithoutInstance =