Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,6 +72,7 @@
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")
/**
Expand Down Expand Up @@ -1188,26 +1190,45 @@ public void getWidgetsContent(DatabaseMeta meta) {
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;
}
}

Expand Down
Loading