From 5339309e013dd65cba81b8c3a1d0c47786156b9f Mon Sep 17 00:00:00 2001 From: Zihan Dai <1436286758@qq.com> Date: Mon, 28 Sep 2026 20:53:08 +1000 Subject: [PATCH] Register IoTDBDriver as a JDBC 4 service provider 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 <1436286758@qq.com> --- .../META-INF/services/java.sql.Driver | 20 ++++++++ .../jdbc/DriverServiceRegistrationTest.java | 47 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 iotdb-client/jdbc/src/main/resources/META-INF/services/java.sql.Driver create mode 100644 iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/DriverServiceRegistrationTest.java 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 0000000000000..bc95a99485c02 --- /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 0000000000000..c0e9365c92b4c --- /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); + } +}