PDGGK opened a new pull request, #18744:
URL: https://github.com/apache/iotdb/pull/18744
Follow-up to #18719, as discussed there.
## Why
Since JDBC 4, `DriverManager` loads drivers through `ServiceLoader` from
`META-INF/services/java.sql.Driver`, so an application can call
`DriverManager.getConnection("jdbc:iotdb://...")` without first calling
`Class.forName`. IoTDB's driver never took part in this. The file that existed
before #18719 sat at `services/META-INF/java.sql.Driver`, with the directories
in the wrong order, and its license header was a `/* */` block, which provider
files do not accept. Before #18719 a `<resources>` override in the jdbc pom
also kept `src/main/resources` out of the jar. None of the released jars from
0.9.3 to 2.0.11 that I checked contain a provider file at either path, so every
client has needed `Class.forName("org.apache.iotdb.jdbc.IoTDBDriver")`.
## Change
- Add
`iotdb-client/jdbc/src/main/resources/META-INF/services/java.sql.Driver` naming
`org.apache.iotdb.jdbc.IoTDBDriver`. The license header uses `#` comments, like
the other provider files in the repo.
- Add `DriverServiceRegistrationTest`. It asks `ServiceLoader` for
`java.sql.Driver` providers and expects an `IoTDBDriver` among them. Going
through `ServiceLoader` rather than `DriverManager` keeps the test independent
of other tests that already loaded the driver class, which registers it as a
side effect. The test is in a new file because #17865 adds
`IoTDBDriverTest.java`.
`Class.forName` keeps working, and the CLI, which uses it, is unaffected.
The only behaviour change is that `DriverManager` now finds the driver on its
own.
## Testing
- The new test passes on a clean build. With the provider file removed, a
clean build fails it with `META-INF/services/java.sql.Driver should name
IoTDBDriver`. An incremental build hid that failure behind a stale copy in
`target/classes`, so I checked this with `clean`.
- The jdbc module's 74 tests and the 47 tests in the modules it depends on
pass. `spotless:check` passes.
- Against a running IoTDB 2.0.8, I ran a client that calls only
`DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", ...)` and runs
`show version`:
| classpath | without `Class.forName` | with `Class.forName` |
|---|---|---|
| CLI `lib/` built from this branch | connects, returns `2.0.8` | connects
|
| `iotdb-jdbc-*-jar-with-dependencies.jar` from this branch | connects,
returns `2.0.8` | not run |
| CLI `lib/` built before this change | `No suitable driver found` |
connects |
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]