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 856bdcf6d3 Fix #4054 - Snowflake Action: manage connection through
variables (#6183)
856bdcf6d3 is described below
commit 856bdcf6d3f29b600bdf2bdfaa6906541f08ade3
Author: Sergio Ramazzina <[email protected]>
AuthorDate: Fri Dec 12 05:13:44 2025 +0100
Fix #4054 - Snowflake Action: manage connection through variables (#6183)
---
.../actions/snowflake/WarehouseManager.java | 131 ++-------------------
.../actions/snowflake/WarehouseManagerDialog.java | 21 ++--
2 files changed, 23 insertions(+), 129 deletions(-)
diff --git
a/plugins/actions/snowflake/src/main/java/org/apache/hop/workflow/actions/snowflake/WarehouseManager.java
b/plugins/actions/snowflake/src/main/java/org/apache/hop/workflow/actions/snowflake/WarehouseManager.java
index ce6694cf97..53dc9495d1 100644
---
a/plugins/actions/snowflake/src/main/java/org/apache/hop/workflow/actions/snowflake/WarehouseManager.java
+++
b/plugins/actions/snowflake/src/main/java/org/apache/hop/workflow/actions/snowflake/WarehouseManager.java
@@ -22,6 +22,8 @@ import static
org.apache.hop.workflow.action.validator.ActionValidatorUtils.notB
import static
org.apache.hop.workflow.action.validator.AndValidator.putValidators;
import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
import org.apache.hop.core.Const;
import org.apache.hop.core.ICheckResult;
import org.apache.hop.core.Result;
@@ -30,6 +32,7 @@ import org.apache.hop.core.database.Database;
import org.apache.hop.core.database.DatabaseMeta;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.util.StringUtil;
+import org.apache.hop.core.util.Utils;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.i18n.BaseMessages;
import org.apache.hop.metadata.api.HopMetadataProperty;
@@ -38,6 +41,8 @@ import org.apache.hop.workflow.WorkflowMeta;
import org.apache.hop.workflow.action.ActionBase;
import org.apache.hop.workflow.action.IAction;
+@Getter
+@Setter
@Action(
id = "SnowflakeWarehouseManager",
image = "snowflake-whm.svg",
@@ -89,8 +94,8 @@ public class WarehouseManager extends ActionBase implements
Cloneable, IAction {
public static final String CONST_COMMIT = ";\ncommit;";
/** The database to connect to. */
- @HopMetadataProperty(key = CONNECTION, storeWithName = true)
- private DatabaseMeta databaseMeta;
+ @HopMetadataProperty(key = CONNECTION)
+ private String connection;
/** The management action to perform. */
@HopMetadataProperty(key = MANAGEMENT_ACTION)
@@ -168,22 +173,6 @@ public class WarehouseManager extends ActionBase
implements Cloneable, IAction {
return super.clone();
}
- public DatabaseMeta getDatabaseMeta() {
- return databaseMeta;
- }
-
- public void setDatabaseMeta(DatabaseMeta databaseMeta) {
- this.databaseMeta = databaseMeta;
- }
-
- public String getManagementAction() {
- return managementAction;
- }
-
- public void setManagementAction(String managementAction) {
- this.managementAction = managementAction;
- }
-
public int getManagementActionId() {
if (managementAction != null) {
for (int i = 0; i < MANAGEMENT_ACTIONS.length; i++) {
@@ -203,46 +192,6 @@ public class WarehouseManager extends ActionBase
implements Cloneable, IAction {
}
}
- public String getWarehouseName() {
- return warehouseName;
- }
-
- public void setWarehouseName(String warehouseName) {
- this.warehouseName = warehouseName;
- }
-
- public boolean isReplace() {
- return replace;
- }
-
- public void setReplace(boolean replace) {
- this.replace = replace;
- }
-
- public boolean isFailIfExists() {
- return failIfExists;
- }
-
- public void setFailIfExists(boolean failIfExists) {
- this.failIfExists = failIfExists;
- }
-
- public boolean isFailIfNotExists() {
- return failIfNotExists;
- }
-
- public void setFailIfNotExists(boolean failIfNotExists) {
- this.failIfNotExists = failIfNotExists;
- }
-
- public String getWarehouseSize() {
- return warehouseSize;
- }
-
- public void setWarehouseSize(String warehouseSize) {
- this.warehouseSize = warehouseSize;
- }
-
public int getWarehouseSizeId() {
if (warehouseSize != null) {
for (int i = 0; i < WAREHOUSE_SIZES.length; i++) {
@@ -289,62 +238,6 @@ public class WarehouseManager extends ActionBase
implements Cloneable, IAction {
}
}
- public String getMaxClusterCount() {
- return maxClusterCount;
- }
-
- public void setMaxClusterCount(String maxClusterCount) {
- this.maxClusterCount = maxClusterCount;
- }
-
- public String getMinClusterCount() {
- return minClusterCount;
- }
-
- public void setMinClusterCount(String minClusterCount) {
- this.minClusterCount = minClusterCount;
- }
-
- public String getAutoSuspend() {
- return autoSuspend;
- }
-
- public void setAutoSuspend(String autoSuspend) {
- this.autoSuspend = autoSuspend;
- }
-
- public boolean isAutoResume() {
- return autoResume;
- }
-
- public void setAutoResume(boolean autoResume) {
- this.autoResume = autoResume;
- }
-
- public boolean isInitiallySuspended() {
- return initiallySuspended;
- }
-
- public void setInitiallySuspended(boolean initiallySuspended) {
- this.initiallySuspended = initiallySuspended;
- }
-
- public String getResourceMonitor() {
- return resourceMonitor;
- }
-
- public void setResourceMonitor(String resourceMonitor) {
- this.resourceMonitor = resourceMonitor;
- }
-
- public String getComment() {
- return comment;
- }
-
- public void setComment(String comment) {
- this.comment = comment;
- }
-
@Override
public void clear() {
super.clear();
@@ -362,20 +255,20 @@ public class WarehouseManager extends ActionBase
implements Cloneable, IAction {
setInitiallySuspended(false);
setResourceMonitor(null);
setComment(null);
- setDatabaseMeta(null);
+ setConnection(null);
setFailIfNotExists(true);
}
public boolean validate() {
boolean result = true;
- if (databaseMeta == null || StringUtil.isEmpty(databaseMeta.getName())) {
+ if (Utils.isEmpty(connection)) {
logError(BaseMessages.getString(PKG,
"SnowflakeWarehouseManager.Validate.DatabaseIsEmpty"));
result = false;
- } else if (StringUtil.isEmpty(managementAction)) {
+ } else if (Utils.isEmpty(managementAction)) {
logError(BaseMessages.getString(PKG,
"SnowflakeWarehouseManager.Validate.ManagementAction"));
result = false;
} else if
(managementAction.equals(MANAGEMENT_ACTIONS[MANAGEMENT_ACTION_CREATE])) {
- if (!StringUtil.isEmpty(resolve(maxClusterCount))
+ if (!Utils.isEmpty(resolve(maxClusterCount))
&& Const.toInt(resolve(maxClusterCount), -1) <= 0) {
logError(
@@ -414,7 +307,7 @@ public class WarehouseManager extends ActionBase implements
Cloneable, IAction {
if (!result.isResult()) {
return result;
}
-
+ DatabaseMeta databaseMeta = parentWorkflowMeta.findDatabase(connection,
getVariables());
try (Database db = new Database(this, this, databaseMeta)) {
String sql = null;
String successMessage = null;
diff --git
a/plugins/actions/snowflake/src/main/java/org/apache/hop/workflow/actions/snowflake/WarehouseManagerDialog.java
b/plugins/actions/snowflake/src/main/java/org/apache/hop/workflow/actions/snowflake/WarehouseManagerDialog.java
index c3b9f891c0..082f32b603 100644
---
a/plugins/actions/snowflake/src/main/java/org/apache/hop/workflow/actions/snowflake/WarehouseManagerDialog.java
+++
b/plugins/actions/snowflake/src/main/java/org/apache/hop/workflow/actions/snowflake/WarehouseManagerDialog.java
@@ -41,6 +41,7 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
@@ -172,6 +173,7 @@ public class WarehouseManagerDialog extends ActionDialog
implements IActionDialo
PropsUi.setLook(shell);
WorkflowDialog.setShellImage(shell, warehouseManager);
+ ModifyListener lsMod = e -> warehouseManager.setChanged();
backupChanged = warehouseManager.hasChanged();
FormLayout formLayout = new FormLayout();
@@ -203,10 +205,13 @@ public class WarehouseManagerDialog extends ActionDialog
implements IActionDialo
wName.setLayoutData(fdName);
// Connection line
- wConnection = addConnectionLine(shell, wName,
warehouseManager.getDatabaseMeta(), null);
- if (warehouseManager.getDatabaseMeta() == null &&
workflowMeta.nrDatabases() == 1) {
- wConnection.select(0);
- }
+ // Connection line
+ DatabaseMeta databaseMeta =
+ workflowMeta.findDatabase(warehouseManager.getConnection(), variables);
+ wConnection = addConnectionLine(shell, wName, databaseMeta, lsMod);
+ // if (warehouseManager.getDatabaseMeta() == null &&
workflowMeta.nrDatabases() == 1) {
+ // wConnection.select(0);
+ // }
// Warehouse name line
//
@@ -1007,10 +1012,7 @@ public class WarehouseManagerDialog extends ActionDialog
implements IActionDialo
public void getData() {
wName.setText(Const.NVL(warehouseManager.getName(), ""));
- wConnection.setText(
- warehouseManager.getDatabaseMeta() != null
- ? warehouseManager.getDatabaseMeta().getName()
- : "");
+ wConnection.setText(Const.NVL(warehouseManager.getConnection(), ""));
wWarehouseName.setText(Const.NVL(warehouseManager.getWarehouseName(), ""));
int actionId = warehouseManager.getManagementActionId();
if (actionId >= 0 && actionId < MANAGEMENT_ACTION_DESCS.length) {
@@ -1084,8 +1086,7 @@ public class WarehouseManagerDialog extends ActionDialog
implements IActionDialo
return;
}
warehouseManager.setName(wName.getText());
- warehouseManager.setDatabaseMeta(
- workflowMeta.findDatabase(Const.NVL(wConnection.getText(), ""),
variables));
+ warehouseManager.setConnection(wConnection.getText());
warehouseManager.setWarehouseName(wWarehouseName.getText());
warehouseManager.setManagementActionById(wAction.getSelectionIndex());
if (wAction.getSelectionIndex() ==
WarehouseManager.MANAGEMENT_ACTION_CREATE) {