whhe commented on code in PR #5712:
URL: https://github.com/apache/seatunnel/pull/5712#discussion_r1374039161
##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-common/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/AbstractJdbcIT.java:
##########
@@ -95,14 +96,38 @@ public abstract class AbstractJdbcIT extends TestSuiteBase
implements TestResour
abstract GenericContainer<?> initContainer();
+ protected URLClassLoader getUrlClassLoader() throws MalformedURLException {
+ if (urlClassLoader == null) {
+ urlClassLoader =
+ new URLClassLoader(
+ new URL[] {new URL(driverUrl())},
+ AbstractJdbcIT.class.getClassLoader());
+ Thread.currentThread().setContextClassLoader(urlClassLoader);
+ }
+ return urlClassLoader;
+ }
+
+ protected Class<?> loadDriverClassFromUrl() {
+ try {
+ return getUrlClassLoader().loadClass(jdbcCase.getDriverClass());
+ } catch (Exception e) {
+ throw new RuntimeException(
+ "Failed to load driver class: " +
jdbcCase.getDriverClass(), e);
+ }
+ }
+
+ protected Class<?> loadDriverClass() {
+ try {
+ return Class.forName(jdbcCase.getDriverClass());
+ } catch (Exception e) {
+ throw new RuntimeException(
+ "Failed to load driver class: " +
jdbcCase.getDriverClass(), e);
+ }
+ }
+
protected void initializeJdbcConnection(String jdbcUrl)
- throws SQLException, ClassNotFoundException, MalformedURLException,
- InstantiationException, IllegalAccessException {
- URLClassLoader urlClassLoader =
- new URLClassLoader(
- new URL[] {new URL(driverUrl())},
AbstractJdbcIT.class.getClassLoader());
- Thread.currentThread().setContextClassLoader(urlClassLoader);
- Driver driver = (Driver)
urlClassLoader.loadClass(jdbcCase.getDriverClass()).newInstance();
+ throws SQLException, InstantiationException,
IllegalAccessException {
+ Driver driver = (Driver) loadDriverClass().newInstance();
Review Comment:
> Got it. Shall we remove these useless `driverUrl` implement? And add
default implement for `driverUrl` method.
The driverUrl is still required by the engine containers (used in
extendedFactory).
I find there are some references to `URLClassLoader` in it cases of selectdb
and doris, but these classed are disabled now, maybe we can make some
improvements when the community decide to enable them.
--
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]