You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hop.apache.org by "fskorgen (via GitHub)" <gi...@apache.org> on 2026/09/16 13:08:36 UTC

[PR] Keep connection details when the connection type changes (hop)

fskorgen opened a new pull request, #8424:
URL: https://github.com/apache/hop/pull/8424

   Fixes #8357.
   
   `DatabaseMetaEditor.changeConnectionType()` replaced the `IDatabase` instance with one from
   `metaMap` — a cache pre-filled with an *empty* instance of every database plugin. That threw away
   the hostname, database name, username and password `setDatabaseType()` had just carried over.
   
   **Commit 1** keeps the cached instance for its type-specific settings and copies the entered
   connection details onto it. A port that is filled in comes along; an empty one falls back to the
   new type's default rather than to a cached value.
   
   **Commit 2** adds a *Default port* button next to the port field, shown only for types that
   declare a default port. Once the port survives a type change, this is how you ask for the new
   type's default. Happy to drop this commit if you'd rather take the defect fix alone.
   
   Tested manually in Hop GUI, switching between MySQL, MariaDB, PostgreSQL and Infobright.
   
   ------------------------
   
   Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
   - [ ] Run `mvn clean install apache-rat:check` to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
   - [ ] If you have a group of commits related to the same change, please squash your commits into one and force push your branch using `git rebase -i`.
   - [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable.
   
   To make clear that you license your contribution under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
   - [ ] I hereby declare this contribution to be licensed under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   


-- 
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: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Keep connection details when the connection type changes (hop)

Posted by "mattcasters (via GitHub)" <gi...@apache.org>.
mattcasters commented on code in PR #8424:
URL: https://github.com/apache/hop/pull/8424#discussion_r4028637545


##########
ui/src/main/java/org/apache/hop/ui/core/database/DatabaseMetaEditor.java:
##########
@@ -528,6 +529,41 @@ private Optional<IGuiPluginCompositeWidgetsListener> pluginWidgetsListener() {
         : Optional.empty();
   }
 
+  // The port survives a connection type change, so fetching the new type's default has to be
+  // something the user asks for. The button sits at the right of the generated port field and is
+  // only there for types that declare a default port.
+  private void addDefaultPortButton() {
+    Control portControl = guiCompositeWidgets.getWidgetsMap().get(BaseDatabaseMeta.ELEMENT_ID_PORT);
+    if (portControl == null
+        || portControl.isDisposed()
+        || !(portControl.getLayoutData() instanceof FormData fdPort)
+        || getMetadata().getIDatabase().getDefaultDatabasePort() <= 0) {
+      return;
+    }
+
+    Button wbDefaultPort = new Button(wDatabaseSpecificComp, SWT.PUSH);

Review Comment:
   **[bug]** The Default port button is created as a sibling of the generated port field but is never registered in `GuiCompositeWidgets.getActionWidgetsMap()`. `setWidgetsHidden()` only hides the label, the widget, and that action control. Oracle hides hostname/port for TNS alias and descriptor connections, so this button stays visible, keeps its preferred height, and remains clickable on a collapsed row. Putting it in `widgetsMap` would break `getWidgetsContents` for the port field.
   
   **Suggestion:** Parent the button to `portControl.getParent()` and `put(ELEMENT_ID_PORT, wbDefaultPort)` on `actionWidgetsMap`, matching FILENAME/FOLDER browse buttons, so hide/show and row collapse include it.



##########
ui/src/main/java/org/apache/hop/ui/core/database/DatabaseMetaEditor.java:
##########
@@ -612,6 +658,29 @@ private void changeConnectionType() {
     busyChangingConnectionType.set(false);
   }
 
+  // Carry the connection details over to another database type. A port that is filled in comes
+  // along: a switch within a database family (MySQL, MariaDB) points at the same server, and a
+  // port the user typed or a variable reference is not the old type's to discard. An empty port
+  // falls back to the new type's default rather than to a cached value, so a port that was
+  // cleared does not come back from the type cache.
+  private void copyEnteredFields(IDatabase entered, IDatabase target) {
+    target.setAccessType(entered.getAccessType());
+    target.setHostname(entered.getHostname());
+    target.setDatabaseName(entered.getDatabaseName());
+    target.setUsername(entered.getUsername());
+    target.setPassword(entered.getPassword());
+    target.setServername(entered.getServername());
+    target.setDataTablespace(entered.getDataTablespace());
+    target.setIndexTablespace(entered.getIndexTablespace());
+    if (StringUtils.isNotEmpty(entered.getPort())) {

Review Comment:
   **[bug]** `copyEnteredFields` always writes a non-empty entered port onto the cached target. That is correct when the target shows a port widget. Databricks annotates `port` as `ignored = true` and builds `jdbc:databricks://host:port;...` from `DatabaseMeta.getPort()`. Switching MySQL (3306) → Databricks previously kept 443 from `populateMetaMap()`; this now silently stores 3306 with no field to correct it.
   
   **Suggestion:** Do not copy the port when the target type ignores/hides that GUI element (or after recreating widgets, if `ELEMENT_ID_PORT` is absent). Fall back to `target.getDefaultDatabasePort()` in that case, same as the empty-port branch.



##########
ui/src/main/java/org/apache/hop/ui/core/database/DatabaseMetaEditor.java:
##########
@@ -528,6 +529,41 @@ private Optional<IGuiPluginCompositeWidgetsListener> pluginWidgetsListener() {
         : Optional.empty();
   }
 
+  // The port survives a connection type change, so fetching the new type's default has to be
+  // something the user asks for. The button sits at the right of the generated port field and is
+  // only there for types that declare a default port.
+  private void addDefaultPortButton() {
+    Control portControl = guiCompositeWidgets.getWidgetsMap().get(BaseDatabaseMeta.ELEMENT_ID_PORT);
+    if (portControl == null
+        || portControl.isDisposed()
+        || !(portControl.getLayoutData() instanceof FormData fdPort)
+        || getMetadata().getIDatabase().getDefaultDatabasePort() <= 0) {
+      return;
+    }
+
+    Button wbDefaultPort = new Button(wDatabaseSpecificComp, SWT.PUSH);
+    wbDefaultPort.setText(BaseMessages.getString(PKG, "DatabaseDialog.button.DefaultPort"));
+    PropsUi.setLook(wbDefaultPort);
+    FormData fdDefaultPort = new FormData();
+    fdDefaultPort.right = new FormAttachment(100, 0);
+    fdDefaultPort.top = new FormAttachment(portControl, 0, SWT.CENTER);
+    wbDefaultPort.setLayoutData(fdDefaultPort);
+    fdPort.right = new FormAttachment(wbDefaultPort, -PropsUi.getMargin());
+
+    wbDefaultPort.addListener(SWT.Selection, event -> setDefaultPort());

Review Comment:
   **[suggestion]** `enableFields()` disables the port `TextVar` when a manual URL is set. This button is not in `widgetsMap` and is never disabled. `TextVar.setText` still applies to a disabled control, so Default port mutates a field the rest of the dialog treats as inactive.
   
   **Suggestion:** Keep a field (or the `actionWidgetsMap` entry) and disable the button with the port widget in `enableFields()`, or extend `enableWidgets` to cover action controls.



##########
ui/src/main/java/org/apache/hop/ui/core/database/DatabaseMetaEditor.java:
##########
@@ -528,6 +529,41 @@ private Optional<IGuiPluginCompositeWidgetsListener> pluginWidgetsListener() {
         : Optional.empty();
   }
 
+  // The port survives a connection type change, so fetching the new type's default has to be

Review Comment:
   **[suggestion]** The comments on `addDefaultPortButton` (here), the `metaMap` replacement, and `copyEnteredFields` narrate the bug history and restate what the code does (button placement, map-vs-entered split, MySQL/MariaDB family rationale). Hop comments should be short and explain a non-obvious constraint.
   
   **Suggestion:** Drop those three blocks. If anything remains, one line on the empty-port vs cached-port choice is enough.



-- 
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: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Keep connection details when the connection type changes (hop)

Posted by "hansva (via GitHub)" <gi...@apache.org>.
hansva merged PR #8424:
URL: https://github.com/apache/hop/pull/8424


-- 
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: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org