samuelwillyanto1 commented on code in PR #8911:
URL: https://github.com/apache/hop/pull/8911#discussion_r4271825656
##########
plugins/actions/columnsexist/src/main/java/org/apache/hop/workflow/actions/columnsexist/ActionColumnsExistDialog.java:
##########
@@ -319,55 +328,82 @@ private void ok() {
/** Get a list of columns */
private void getListColumns() {
- if (!Utils.isEmpty(wTablename.getText())) {
- DatabaseMeta databaseMeta = wConnection.loadSelectedElement();
- if (databaseMeta != null) {
- try (Database database = new Database(loggingObject, variables,
databaseMeta)) {
- database.connect();
- IRowMeta row =
- database.getTableFieldsMeta(
- variables.resolve(wSchemaname.getText()),
- variables.resolve(wTablename.getText()));
- if (row != null) {
- String[] available = row.getFieldNames();
-
- wFields.removeAll();
- for (String s : available) {
- wFields.add(s);
- }
- wFields.removeEmptyRows();
- wFields.setRowNums();
- } else {
- MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
- mb.setMessage(
- BaseMessages.getString(PKG,
"ActionColumnsExist.GetListColumsNoRow.DialogMessage"));
- mb.setText(BaseMessages.getString(PKG, CONST_ERROR_TITLE));
- mb.open();
+ if (Utils.isEmpty(wConnection.getText())) {
+ MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
+ mb.setMessage(
+ BaseMessages.getString(PKG,
"ActionColumnsExist.ConnectionError.DialogMessage"));
+ mb.setText(BaseMessages.getString(PKG, CONST_ERROR_TITLE));
+ mb.open();
+ return;
+ }
+ if (Utils.isEmpty(wTablename.getText())) {
+ MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
+ mb.setMessage(BaseMessages.getString(PKG,
"ActionColumnsExist.Error.TablenameEmpty"));
+ mb.setText(BaseMessages.getString(PKG, CONST_ERROR_TITLE));
+ mb.open();
+ return;
+ }
+
+ DatabaseMeta databaseMeta = wConnection.loadSelectedElement();
+ if (databaseMeta != null) {
+ try (Database database = new Database(loggingObject, variables,
databaseMeta)) {
+ database.connect();
+ IRowMeta row =
+ database.getTableFieldsMeta(
+ variables.resolve(wSchemaname.getText()),
variables.resolve(wTablename.getText()));
+ if (row != null) {
+ String[] available = row.getFieldNames();
+
+ wFields.removeAll();
+ for (String s : available) {
+ wFields.add(s);
}
- } catch (Exception e) {
- new ErrorDialog(
- shell,
- BaseMessages.getString(PKG, CONST_ERROR_TITLE),
- BaseMessages.getString(
- PKG, "ActionColumnsExist.ConnectionError2.DialogMessage",
wTablename.getText()),
- e);
+ wFields.removeEmptyRows();
+ wFields.setRowNums();
+ } else {
+ MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
+ mb.setMessage(
+ BaseMessages.getString(PKG,
"ActionColumnsExist.GetListColumsNoRow.DialogMessage"));
+ mb.setText(BaseMessages.getString(PKG, CONST_ERROR_TITLE));
+ mb.open();
}
+ } catch (Exception e) {
+ new ErrorDialog(
+ shell,
+ BaseMessages.getString(PKG, CONST_ERROR_TITLE),
+ BaseMessages.getString(
+ PKG, "ActionColumnsExist.ConnectionError2.DialogMessage",
wTablename.getText()),
+ e);
}
+ } else {
+ MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
+ mb.setMessage(
+ BaseMessages.getString(PKG,
"ActionColumnsExist.ConnectionError.DialogMessage"));
+ mb.setText(BaseMessages.getString(PKG, CONST_ERROR_TITLE));
+ mb.open();
}
}
private void getSchemaNames() {
if (wSchemaname.isDisposed()) {
return;
}
+ if (Utils.isEmpty(wConnection.getText())) {
+ MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
+ mb.setMessage(
+ BaseMessages.getString(PKG,
"ActionColumnsExist.ConnectionError.DialogMessage"));
+ mb.setText(BaseMessages.getString(PKG, CONST_ERROR_TITLE));
+ mb.open();
+ return;
+ }
DatabaseMeta databaseMeta = wConnection.loadSelectedElement();
if (databaseMeta != null) {
try (Database database = new Database(loggingObject, variables,
databaseMeta)) {
database.connect();
String[] schemas = database.getSchemas();
if (null != schemas && schemas.length > 0) {
- schemas = Const.sortStrings(schemas);
+ Arrays.sort(schemas,
Comparator.nullsFirst(String.CASE_INSENSITIVE_ORDER));
Review Comment:
Thanks for the detailed explanation, @mattcasters
Updated as suggested:
1. In `Database.getSchemas()` (and `getCatalogs()`), added
`schemaList.removeIf(Objects::isNull)` before sorting to prevent
`NullPointerException` globally when drivers return nulls.
2. In `ActionColumnsExistDialog.java`, filtered out null elements from the
schemas array before sorting with `Const.sortStrings(schemas)` and opening
`EnterSelectionDialog`. If no schemas remain, it displays the empty schema
message dialog.
3. Added unit tests in `DatabaseTest` (`testGetSchemasFiltersNulls` and
`testGetCatalogsFiltersNulls`) to verify null filtering.
--
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]