Skip to content

Commit 79631e3

Browse files
authored
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 <1436286758@qq.com>
1 parent d587d8d commit 79631e3

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
org.apache.iotdb.jdbc.IoTDBDriver
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.jdbc;
21+
22+
import org.junit.Test;
23+
24+
import java.sql.Driver;
25+
import java.util.ServiceLoader;
26+
27+
import static org.junit.Assert.assertTrue;
28+
29+
public class DriverServiceRegistrationTest {
30+
31+
/**
32+
* JDBC 4 drivers are loaded by DriverManager through ServiceLoader, from
33+
* META-INF/services/java.sql.Driver. Asking ServiceLoader directly keeps this independent of
34+
* whether another test has already loaded IoTDBDriver, which registers it with DriverManager as a
35+
* side effect.
36+
*/
37+
@Test
38+
public void driverIsListedAsAJdbcServiceProvider() {
39+
boolean found = false;
40+
for (Driver driver : ServiceLoader.load(Driver.class)) {
41+
if (driver instanceof IoTDBDriver) {
42+
found = true;
43+
}
44+
}
45+
assertTrue("META-INF/services/java.sql.Driver should name IoTDBDriver", found);
46+
}
47+
}

0 commit comments

Comments
 (0)