You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hop.apache.org by ha...@apache.org on 2026/06/01 08:36:45 UTC
(hop) branch main updated: Update logic for retrieving version information for a JDBC driver #7205 (#7206)
This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new cc1678bfd9 Update logic for retrieving version information for a JDBC driver #7205 (#7206)
cc1678bfd9 is described below
commit cc1678bfd924a88d4cf5f14f315475039ac5f3e9
Author: Nicolas Adment <39...@users.noreply.github.com>
AuthorDate: Mon Jun 1 10:36:38 2026 +0200
Update logic for retrieving version information for a JDBC driver #7205 (#7206)
---
.../hop/ui/core/database/DatabaseMetaEditor.java | 41 ++++++++++++++++------
1 file changed, 31 insertions(+), 10 deletions(-)
diff --git a/ui/src/main/java/org/apache/hop/ui/core/database/DatabaseMetaEditor.java b/ui/src/main/java/org/apache/hop/ui/core/database/DatabaseMetaEditor.java
index a71bde7498..020819cd2b 100644
--- a/ui/src/main/java/org/apache/hop/ui/core/database/DatabaseMetaEditor.java
+++ b/ui/src/main/java/org/apache/hop/ui/core/database/DatabaseMetaEditor.java
@@ -17,6 +17,7 @@
package org.apache.hop.ui.core.database;
+import java.sql.Driver;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -71,6 +72,7 @@ import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
+import org.jspecify.annotations.Nullable;
@GuiPlugin(description = "This is the editor for database connection metadata")
/**
@@ -1188,26 +1190,45 @@ public class DatabaseMetaEditor extends MetadataEditor<DatabaseMeta> {
meta.setSshTunnelPassphrase(wSshTunnelPassphrase.getText());
}
- /** Update JDBC driver information and version */
+ /** Updates the displayed driver information, including the driver name and version. */
protected void updateDriverInfo() {
+ String driverName;
+ String driverVersion = null;
try {
DatabaseMeta databaseMeta = new DatabaseMeta();
this.getWidgetsContent(databaseMeta);
- wDriverInfo.setText("");
- String driverName = databaseMeta.getDriverClass(getVariables());
+ driverName = databaseMeta.getDriverClass(getVariables());
if (!Utils.isEmpty(driverName)) {
ClassLoader classLoader = databaseMeta.getIDatabase().getClass().getClassLoader();
- Class<?> driver = classLoader.loadClass(driverName);
+ Class<? extends Driver> driverClass =
+ classLoader.loadClass(driverName).asSubclass(Driver.class);
+ driverVersion = getDriverVersion(driverClass);
+ }
+ } catch (Exception e) {
+ driverName = "No driver installed";
+ }
- if (driver.getPackage().getImplementationVersion() != null) {
- driverName = driverName + " (" + driver.getPackage().getImplementationVersion() + ")";
- }
+ wDriverInfo.setText(driverName + (driverVersion != null ? " (" + driverVersion + ")" : ""));
+ }
- wDriverInfo.setText(driverName);
- }
+ /**
+ * Retrieves the version information for the specified JDBC driver class.
+ *
+ * @param driverClass The JDBC driver class for which to retrieve the version information.
+ * @return The driver version as a string, or null if the version cannot be determined.
+ */
+ private static @Nullable String getDriverVersion(Class<? extends Driver> driverClass) {
+ String version = driverClass.getPackage().getImplementationVersion();
+ if (version != null) {
+ return version;
+ }
+ try {
+ Driver driver = driverClass.getDeclaredConstructor().newInstance();
+ return driver.getMajorVersion() + "." + driver.getMinorVersion();
} catch (Exception e) {
- wDriverInfo.setText("No driver installed");
+ // Ignore - version could not be determined
+ return null;
}
}