Hisoka-X commented on code in PR #9667:
URL: https://github.com/apache/seatunnel/pull/9667#discussion_r2258713114
##########
seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/catalog/DorisCatalog.java:
##########
@@ -134,14 +157,164 @@ public void open() throws CatalogException {
queryPort,
defaultDatabase);
try {
- conn = DriverManager.getConnection(jdbcUrl, username, password);
+ // Prepare connection properties
+ Properties connectionInfo = new Properties();
+ if (username != null) {
+ connectionInfo.put("user", username);
+ }
+ if (password != null) {
+ connectionInfo.put("password", password);
+ }
+
+ // Attempt to connect using available drivers
+ conn = attemptConnectionWithDrivers(jdbcUrl, connectionInfo);
+
+ if (conn == null) {
+ LOG.warn(
+ "Failed to connect using driver enumeration, falling
back to DriverManager.getConnection");
+ conn = DriverManager.getConnection(jdbcUrl, username,
password);
+ }
+
+ // Validate connection and initialize catalog
conn.getCatalog();
dorisVersion = getDorisVersion();
typeConverter =
DorisTypeConverterFactory.getTypeConverter(dorisVersion);
+
} catch (SQLException e) {
- throw new CatalogException(String.format("Failed to connect url
%s", jdbcUrl), e);
+ throw new CatalogException(String.format("Failed to connect to
URL: %s", jdbcUrl), e);
+ }
+
+ LOG.info("Catalog [{}] successfully established connection to [{}]",
catalogName, jdbcUrl);
+ }
+
+ /**
+ * Attempt to establish connection by iterating through available JDBC
drivers. This method
+ * prioritizes the specified driver class if provided, otherwise tries all
available drivers.
+ *
+ * @param jdbcUrl The JDBC URL to connect to
+ * @param connectionInfo Connection properties including user credentials
and LDAP settings
+ * @return A valid database connection, or null if all attempts failed
+ */
+ private Connection attemptConnectionWithDrivers(String jdbcUrl, Properties
connectionInfo) {
+ Enumeration<Driver> drivers = DriverManager.getDrivers();
+
+ // If a specific driver class is specified, try it first
+ if (StringUtils.isNotBlank(driverClass)) {
+ LOG.debug("Attempting connection with specified driver class: {}",
driverClass);
+
+ while (drivers.hasMoreElements()) {
+ Driver driver = drivers.nextElement();
+ if (StringUtils.equals(driver.getClass().getName(),
driverClass)) {
+ Connection connection = tryConnectWithDriver(driver,
jdbcUrl, connectionInfo);
+ if (connection != null) {
+ LOG.info("Successfully connected using specified
driver: {}", driverClass);
+ return connection;
+ }
+ }
+ }
+
+ LOG.warn(
+ "Failed to connect using specified driver class: {},
trying other available drivers",
+ driverClass);
+
+ // Reset enumeration for fallback attempt
+ drivers = DriverManager.getDrivers();
+ }
+
+ // Try all available drivers
+ LOG.debug("Attempting connection with all available drivers");
Review Comment:
> No driver specified
We can use default driver value when enable ldap if no driver specified.
> Specified driver fails to connect
We should thrown exception when specified driver fails to connect
--
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]