From 33df74f72a2d3a775319fa3e10e26ba72e4048e6 Mon Sep 17 00:00:00 2001 From: sramazzina Date: Thu, 13 Jun 2024 15:07:54 +0200 Subject: [PATCH] fix #3836 - Oracle Bulk Loader - specify connection through variables --- .../orabulkloader/OraBulkLoader.java | 15 +++++-- .../orabulkloader/OraBulkLoaderDialog.java | 33 ++++++++------- .../orabulkloader/OraBulkLoaderMeta.java | 40 +++++++++---------- 3 files changed, 50 insertions(+), 38 deletions(-) diff --git a/plugins/transforms/orabulkloader/src/main/java/org/apache/hop/pipeline/transforms/orabulkloader/OraBulkLoader.java b/plugins/transforms/orabulkloader/src/main/java/org/apache/hop/pipeline/transforms/orabulkloader/OraBulkLoader.java index 27e5697cd3d..d562072bd05 100644 --- a/plugins/transforms/orabulkloader/src/main/java/org/apache/hop/pipeline/transforms/orabulkloader/OraBulkLoader.java +++ b/plugins/transforms/orabulkloader/src/main/java/org/apache/hop/pipeline/transforms/orabulkloader/OraBulkLoader.java @@ -186,7 +186,9 @@ private String encodeRecordTerminator(String terminator, String encoding) throws */ public String getControlFileContents(OraBulkLoaderMeta meta, IRowMeta rowMeta, Object[] row) throws HopException { - DatabaseMeta dm = meta.getDatabaseMeta(); + + DatabaseMeta dm = getPipelineMeta().findDatabase(meta.getConnection(), variables); + String inputName = "'" + getFilename(getFileObject(meta.getDataFile(), variables)) + "'"; String loadAction = meta.getLoadAction(); @@ -410,7 +412,7 @@ public String createCommandLine(OraBulkLoaderMeta meta, boolean password) throws } } - DatabaseMeta db = meta.getDatabaseMeta(); + DatabaseMeta db = getPipelineMeta().findDatabase(meta.getConnection(), variables); if (db != null) { String user = Const.NVL(db.getUsername(), ""); String pass = @@ -579,7 +581,14 @@ public boolean processRow() throws HopException { } protected void verifyDatabaseConnection() throws HopException { - if (meta.getDatabaseMeta() == null) { + + if (meta.getConnection() == null) { + throw new HopException( + BaseMessages.getString(PKG, "OraBulkLoaderMeta.GetSQL.NoConnectionDefined")); + } + + DatabaseMeta dm = getPipelineMeta().findDatabase(meta.getConnection(), variables); + if (dm == null) { throw new HopException( BaseMessages.getString(PKG, "OraBulkLoaderMeta.GetSQL.NoConnectionDefined")); } diff --git a/plugins/transforms/orabulkloader/src/main/java/org/apache/hop/pipeline/transforms/orabulkloader/OraBulkLoaderDialog.java b/plugins/transforms/orabulkloader/src/main/java/org/apache/hop/pipeline/transforms/orabulkloader/OraBulkLoaderDialog.java index b9cb6ebdf9c..494d1a5892d 100644 --- a/plugins/transforms/orabulkloader/src/main/java/org/apache/hop/pipeline/transforms/orabulkloader/OraBulkLoaderDialog.java +++ b/plugins/transforms/orabulkloader/src/main/java/org/apache/hop/pipeline/transforms/orabulkloader/OraBulkLoaderDialog.java @@ -55,6 +55,7 @@ import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; @@ -216,9 +217,18 @@ public String open() { fdComp.bottom = new FormAttachment(100, 0); wBulkLoaderComposite.setLayoutData(fdComp); + SelectionListener lsSelection = + new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + input.setChanged(); + setTableFieldCombo(); + } + }; + // Connection line - wConnection = - addConnectionLine(wBulkLoaderComposite, wTransformName, input.getDatabaseMeta(), lsMod); + wConnection = addConnectionLine(shell, wTransformName, input.getConnection(), lsMod); + wConnection.addSelectionListener(lsSelection); // Schema line... Label wlSchema = new Label(wBulkLoaderComposite, SWT.RIGHT); @@ -1041,8 +1051,8 @@ public void getData() { } } - if (input.getDatabaseMeta() != null) { - wConnection.setText(input.getDatabaseMeta().getName()); + if (input.getConnection() != null) { + wConnection.setText(input.getConnection()); } if (input.getSchemaName() != null) { wSchema.setText(input.getSchemaName()); @@ -1159,7 +1169,7 @@ private void getInfo(OraBulkLoaderMeta meta) { meta.setMappings(mappings); meta.setSchemaName(wSchema.getText()); meta.setTableName(wTable.getText()); - meta.setDatabaseMeta(pipelineMeta.findDatabase(wConnection.getText(), variables)); + meta.setConnection(wConnection.getText()); meta.setSqlldr(wSqlldr.getText()); meta.setControlFile(wControlFile.getText()); meta.setDataFile(wDataFile.getText()); @@ -1232,7 +1242,7 @@ private void ok() { // Get the information for the dialog into the input structure. getInfo(input); - if (input.getDatabaseMeta() == null) { + if (input.getConnection() == null) { MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); mb.setMessage( BaseMessages.getString(PKG, "OraBulkLoaderDialog.InvalidConnection.DialogMessage")); @@ -1352,7 +1362,7 @@ private void create() { try { OraBulkLoaderMeta info = new OraBulkLoaderMeta(); getInfo(info); - + DatabaseMeta databaseMeta = pipelineMeta.findDatabase(info.getConnection(), variables); String name = transformName; // new name might not yet be linked to other transforms! TransformMeta transformMeta = new TransformMeta( @@ -1365,12 +1375,7 @@ private void create() { if (sql.hasSql()) { SqlEditor sqledit = new SqlEditor( - shell, - SWT.NONE, - variables, - info.getDatabaseMeta(), - DbCache.getInstance(), - sql.getSql()); + shell, SWT.NONE, variables, databaseMeta, DbCache.getInstance(), sql.getSql()); sqledit.open(); } else { MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION); @@ -1419,7 +1424,7 @@ private void generateMappings() { return; } // refresh data - input.setDatabaseMeta(pipelineMeta.findDatabase(wConnection.getText(), variables)); + input.setConnection(wConnection.getText()); input.setTableName(variables.resolve(wTable.getText())); ITransformMeta transformMetaInterface = transformMeta.getTransform(); try { diff --git a/plugins/transforms/orabulkloader/src/main/java/org/apache/hop/pipeline/transforms/orabulkloader/OraBulkLoaderMeta.java b/plugins/transforms/orabulkloader/src/main/java/org/apache/hop/pipeline/transforms/orabulkloader/OraBulkLoaderMeta.java index 116f977e423..675ba914715 100644 --- a/plugins/transforms/orabulkloader/src/main/java/org/apache/hop/pipeline/transforms/orabulkloader/OraBulkLoaderMeta.java +++ b/plugins/transforms/orabulkloader/src/main/java/org/apache/hop/pipeline/transforms/orabulkloader/OraBulkLoaderMeta.java @@ -21,7 +21,6 @@ import org.apache.hop.core.CheckResult; import org.apache.hop.core.Const; import org.apache.hop.core.ICheckResult; -import org.apache.hop.core.IProvidesDatabaseConnectionInformation; import org.apache.hop.core.SqlStatement; import org.apache.hop.core.annotations.Transform; import org.apache.hop.core.database.Database; @@ -49,8 +48,7 @@ categoryDescription = "i18n:org.apache.hop.pipeline.transform:BaseTransform.Category.Bulk", keywords = "i18n::OraBulkLoader.Keywords", documentationUrl = "/pipeline/transforms/orabulkloader.html") -public class OraBulkLoaderMeta extends BaseTransformMeta - implements IProvidesDatabaseConnectionInformation { +public class OraBulkLoaderMeta extends BaseTransformMeta { private static final Class PKG = OraBulkLoaderMeta.class; // for i18n purposes, needed by Translator2!! @@ -62,9 +60,8 @@ public class OraBulkLoaderMeta extends BaseTransformMeta