Skip to content

Commit

Permalink
Merge pull request #4053 from sramazzina/3836
Browse files Browse the repository at this point in the history
fix #3836 - Oracle Bulk Loader - specify connection through variables
  • Loading branch information
hansva authored Jun 20, 2024
2 parents 956d1b0 + 33df74f commit e40479f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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(
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<OraBulkLoader, OraBulkLoaderData>
implements IProvidesDatabaseConnectionInformation {
public class OraBulkLoaderMeta extends BaseTransformMeta<OraBulkLoader, OraBulkLoaderData> {
private static final Class<?> PKG =
OraBulkLoaderMeta.class; // for i18n purposes, needed by Translator2!!

Expand All @@ -62,9 +60,8 @@ public class OraBulkLoaderMeta extends BaseTransformMeta<OraBulkLoader, OraBulkL
/** Database connection */
@HopMetadataProperty(
key = "connection",
storeWithName = true,
injectionKeyDescription = "OraBulkLoader.Injection.Connection")
private DatabaseMeta databaseMeta;
private String connection;

/** Schema for the target */
@HopMetadataProperty(
Expand Down Expand Up @@ -274,18 +271,12 @@ public void setCommitSize(String commitSize) {
this.commitSize = commitSize;
}

/**
* @return Returns the database.
*/
public DatabaseMeta getDatabaseMeta() {
return databaseMeta;
public String getConnection() {
return connection;
}

/**
* @param database The database to set.
*/
public void setDatabaseMeta(DatabaseMeta database) {
this.databaseMeta = database;
public void setConnection(String connection) {
this.connection = connection;
}

/**
Expand Down Expand Up @@ -352,7 +343,7 @@ public void setAltRecordTerm(String altRecordTerm) {

@Override
public void setDefault() {
databaseMeta = null;
connection = null;
commitSize = Integer.toString(DEFAULT_COMMIT_SIZE);
bindSize = Integer.toString(DEFAULT_BIND_SIZE); // Use platform default
readSize = Integer.toString(DEFAULT_READ_SIZE); // Use platform default
Expand Down Expand Up @@ -392,6 +383,9 @@ public void check(
CheckResult cr;
String errorMessage = "";

DatabaseMeta databaseMeta =
getParentTransformMeta().getParentPipelineMeta().findDatabase(connection, variables);

if (databaseMeta != null) {
Database db = new Database(loggingObject, variables, databaseMeta);
try {
Expand Down Expand Up @@ -551,6 +545,10 @@ public SqlStatement getSqlStatements(
IRowMeta prev,
IHopMetadataProvider metadataProvider)
throws HopTransformException {

DatabaseMeta databaseMeta =
getParentTransformMeta().getParentPipelineMeta().findDatabase(connection, variables);

SqlStatement retval =
new SqlStatement(transformMeta.getName(), databaseMeta, null); // default: nothing to do!

Expand Down Expand Up @@ -619,6 +617,9 @@ public void analyseImpact(
IHopMetadataProvider metadataProvider)
throws HopTransformException {

DatabaseMeta databaseMeta =
getParentTransformMeta().getParentPipelineMeta().findDatabase(connection, variables);

if (prev != null) {
/* DEBUG CHECK THIS */
// Insert dateMask fields : read/write
Expand Down Expand Up @@ -660,6 +661,8 @@ public void setDirectPath(boolean directPath) {
public IRowMeta getRequiredFields(IVariables variables) throws HopException {
String realTableName = variables.resolve(tableName);
String realSchemaName = variables.resolve(schemaName);
DatabaseMeta databaseMeta =
getParentTransformMeta().getParentPipelineMeta().findDatabase(connection, variables);

if (databaseMeta != null) {
Database database = new Database(loggingObject, variables, databaseMeta);
Expand Down Expand Up @@ -849,9 +852,4 @@ public boolean isParallel() {
public void setParallel(boolean parallel) {
this.parallel = parallel;
}

@Override
public String getMissingDatabaseConnectionInformationMessage() {
return null;
}
}

0 comments on commit e40479f

Please sign in to comment.