This is an automated email from the ASF dual-hosted git repository.

HTHou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 79631e3ec62 Register IoTDBDriver as a JDBC 4 service provider (#18744)
79631e3ec62 is described below

commit 79631e3ec622fc133392fd35e654d00056f224b0
Author: ZIHAN DAI <[email protected]>
AuthorDate: Mon Sep 28 23:11:25 2026 +1000

    Register IoTDBDriver as a JDBC 4 service provider (#18744)
    
    Add META-INF/services/java.sql.Driver naming 
org.apache.iotdb.jdbc.IoTDBDriver,
    so DriverManager finds the driver without a Class.forName call. The file 
that
    existed before (at services/META-INF/, with a /* */ header ServiceLoader 
does
    not accept) never took effect and was removed in #18719.
    
    A unit test asks ServiceLoader for java.sql.Driver providers and expects
    IoTDBDriver among them; it fails when the file is missing.
    
    Signed-off-by: Zihan Dai <[email protected]>
---
 .../resources/META-INF/services/java.sql.Driver    | 20 +++++++++
 .../iotdb/jdbc/DriverServiceRegistrationTest.java  | 47 ++++++++++++++++++++++
 2 files changed, 67 insertions(+)

diff --git 
a/iotdb-client/jdbc/src/main/resources/META-INF/services/java.sql.Driver 
b/iotdb-client/jdbc/src/main/resources/META-INF/services/java.sql.Driver
new file mode 100644
index 00000000000..bc95a99485c
--- /dev/null
+++ b/iotdb-client/jdbc/src/main/resources/META-INF/services/java.sql.Driver
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+#
+
+org.apache.iotdb.jdbc.IoTDBDriver
diff --git 
a/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/DriverServiceRegistrationTest.java
 
b/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/DriverServiceRegistrationTest.java
new file mode 100644
index 00000000000..c0e9365c92b
--- /dev/null
+++ 
b/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/DriverServiceRegistrationTest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.iotdb.jdbc;
+
+import org.junit.Test;
+
+import java.sql.Driver;
+import java.util.ServiceLoader;
+
+import static org.junit.Assert.assertTrue;
+
+public class DriverServiceRegistrationTest {
+
+  /**
+   * JDBC 4 drivers are loaded by DriverManager through ServiceLoader, from
+   * META-INF/services/java.sql.Driver. Asking ServiceLoader directly keeps 
this independent of
+   * whether another test has already loaded IoTDBDriver, which registers it 
with DriverManager as a
+   * side effect.
+   */
+  @Test
+  public void driverIsListedAsAJdbcServiceProvider() {
+    boolean found = false;
+    for (Driver driver : ServiceLoader.load(Driver.class)) {
+      if (driver instanceof IoTDBDriver) {
+        found = true;
+      }
+    }
+    assertTrue("META-INF/services/java.sql.Driver should name IoTDBDriver", 
found);
+  }
+}

Reply via email to