Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

/** Delete data in a database table. */
public class Delete extends BaseTransform<DeleteMeta, DeleteData> {

private static final Class<?> PKG = DeleteMeta.class;

public Delete(
Expand Down Expand Up @@ -75,21 +74,22 @@ private synchronized void deleteValues(IRowMeta rowMeta, Object[] row) throws Ho
PKG,
"Delete.Log.SetValuesForDelete",
data.deleteParameterRowMeta.getString(deleteRow),
rowMeta.getString(row)));
rowMeta.getString(row),
meta.isUseBatchUpdate()));
}

data.db.insertRow(data.prepStatementDelete);
data.db.insertRow(data.prepStatementDelete, meta.isUseBatchUpdate(), true);
incrementLinesUpdated();
}

@Override
public boolean processRow() throws HopException {
boolean sendToErrorRow = false;
String errorMessage = null;

Object[] r = getRow(); // Get row from input rowset & set row busy!
if (r == null) { // no more input to be expected...

// Get row from input rowset & set row busy!
Object[] r = getRow();
// no more input to be expected...
if (r == null) {
setOutputDone();
return false;
}
Expand Down Expand Up @@ -151,24 +151,24 @@ public boolean processRow() throws HopException {
}

try {
deleteValues(getInputRowMeta(), r); // add new values to the row in rowset[0].
putRow(
data.outputRowMeta, r); // output the same rows of data, but with a copy of the metadata
// add new values to the row in rowset[0].
deleteValues(getInputRowMeta(), r);
// output the same rows of data, but with a copy of the metadata
putRow(data.outputRowMeta, r);

if (checkFeedback(getLinesRead()) && isBasic()) {
logBasic(BaseMessages.getString(PKG, "Delete.Log.LineNumber") + getLinesRead());
}
} catch (HopException e) {

if (getTransformMeta().isDoingErrorHandling()) {
sendToErrorRow = true;
errorMessage = e.toString();
} else {

logError(BaseMessages.getString(PKG, "Delete.Log.ErrorInTransform") + e.getMessage());
setErrors(1);
stopAll();
setOutputDone(); // signal end to receiver(s)
// signal end to receiver(s)
setOutputDone();
return false;
}

Expand Down Expand Up @@ -225,7 +225,6 @@ public void prepareDelete(IRowMeta rowMeta) throws HopDatabaseException {
@Override
public boolean init() {
if (super.init()) {

if (Utils.isEmpty(meta.getConnection())) {
logError(BaseMessages.getString(PKG, "Delete.Init.ConnectionMissing", getTransformName()));
return false;
Expand All @@ -238,16 +237,13 @@ public boolean init() {
}

data.db = new Database(this, variables, databaseMeta);

try {
data.db.connect();

if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "Delete.Log.ConnectedToDB"));
}

data.db.setCommit(meta.getCommitSize(this));

return true;
} catch (HopException ke) {
logError(BaseMessages.getString(PKG, "Delete.Log.ErrorOccurred") + ke.getMessage());
Expand All @@ -274,18 +270,26 @@ private void commitBatch(boolean dispose) {
try {
if (!data.db.isAutoCommit()) {
if (getErrors() == 0) {
data.db.commit();
if (dispose) {
data.db.emptyAndCommit(data.prepStatementDelete, meta.isUseBatchUpdate());
data.prepStatementDelete = null;
} else {
data.db.commit();
}
} else {
data.db.rollback();
}
}
if (dispose) data.db.closeUpdate();
if (dispose && data.prepStatementDelete != null) {
data.db.closePreparedStatement(data.prepStatementDelete);
data.prepStatementDelete = null;
}
} catch (HopDatabaseException e) {
logError(
BaseMessages.getString(PKG, "Delete.Log.UnableToCommitUpdateConnection")
+ data.db
+ "] :"
+ e.toString());
+ e);
setErrors(1);
} finally {
if (dispose) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class DeleteDialog extends BaseTransformDialog {

private TextVar wCommit;

private Button wBatch;

private final DeleteMeta input;

private final List<String> inputFields = new ArrayList<>();
Expand Down Expand Up @@ -183,12 +185,37 @@ public void widgetSelected(SelectionEvent e) {
fdCommit.right = new FormAttachment(100, 0);
wCommit.setLayoutData(fdCommit);

// Batch delete
Label wlBatch = new Label(shell, SWT.RIGHT);
wlBatch.setText(BaseMessages.getString(PKG, "DeleteDialog.Batch.Label"));
PropsUi.setLook(wlBatch);
FormData fdlBatch = new FormData();
fdlBatch.left = new FormAttachment(0, 0);
fdlBatch.top = new FormAttachment(wCommit, margin);
fdlBatch.right = new FormAttachment(middle, -margin);
wlBatch.setLayoutData(fdlBatch);
wBatch = new Button(shell, SWT.CHECK);
PropsUi.setLook(wBatch);
FormData fdBatch = new FormData();
fdBatch.left = new FormAttachment(middle, 0);
fdBatch.top = new FormAttachment(wlBatch, 0, SWT.CENTER);
fdBatch.right = new FormAttachment(100, 0);
wBatch.setLayoutData(fdBatch);
wBatch.addSelectionListener(
new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
setFlags();
input.setChanged();
}
});

Label wlKey = new Label(shell, SWT.NONE);
wlKey.setText(BaseMessages.getString(PKG, "DeleteDialog.Key.Label"));
PropsUi.setLook(wlKey);
FormData fdlKey = new FormData();
fdlKey.left = new FormAttachment(0, 0);
fdlKey.top = new FormAttachment(wCommit, margin);
fdlKey.top = new FormAttachment(wBatch, margin);
wlKey.setLayoutData(fdlKey);

int nrKeyCols = 4;
Expand Down Expand Up @@ -288,6 +315,7 @@ public void widgetSelected(SelectionEvent e) {

getData();
setTableFieldCombo();
setFlags();
focusTransformName();
BaseDialog.defaultShellHandling(shell, c -> ok(), c -> cancel());

Expand All @@ -309,6 +337,7 @@ public void getData() {
}

wCommit.setText(input.getCommitSizeVar());
wBatch.setSelection(input.isUseBatchUpdate());

List<DeleteKeyField> keyFields = input.getLookup().getFields();

Expand Down Expand Up @@ -352,6 +381,25 @@ private void cancel() {
dispose();
}

/**
* Updates dialog control states based on the current configuration.
*
* <p>Batch deletes are disabled when this transform uses error handling and the selected database
* does not support batch updates together with error handling (for example mysql and look-likes).
*/
public void setFlags() {
DatabaseMeta databaseMeta = pipelineMeta.findDatabase(wConnection.getText(), variables);
boolean hasErrorHandling = pipelineMeta.findTransform(transformName).isDoingErrorHandling();

boolean enableBatch = wBatch.getSelection();
enableBatch =
enableBatch
&& !(databaseMeta != null
&& databaseMeta.supportsErrorHandlingOnBatchUpdates()
&& hasErrorHandling);
wBatch.setSelection(enableBatch);
}

private void setTableFieldCombo() {
Runnable fieldLoader =
() -> {
Expand Down Expand Up @@ -409,6 +457,7 @@ private void getInfo(DeleteMeta inf) {
int nrkeys = wKey.nrNonEmpty();

inf.setCommitSize(wCommit.getText());
inf.setUseBatchUpdate(wBatch.getSelection());

if (log.isDebug()) {
logDebug(BaseMessages.getString(PKG, "DeleteDialog.Log.FoundKeys", String.valueOf(nrkeys)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
package org.apache.hop.pipeline.transforms.delete;

import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import org.apache.hop.metadata.api.HopMetadataProperty;
import org.apache.hop.metadata.api.HopMetadataPropertyType;

@Getter
@Setter
public class DeleteKeyField {

/** which field in input stream to compare with? */
Expand Down Expand Up @@ -65,42 +69,14 @@ public DeleteKeyField(DeleteKeyField f) {
this.keyStream2 = f.keyStream2;
}

public String getKeyStream() {
return keyStream;
}

public void setKeyStream(String keyStream) {
this.keyStream = keyStream;
}

public String getKeyLookup() {
return keyLookup;
}

public void setKeyLookup(String keyLookup) {
this.keyLookup = keyLookup;
}

public String getKeyCondition() {
return keyCondition;
}

public void setKeyCondition(String keyCondition) {
this.keyCondition = keyCondition;
}

public String getKeyStream2() {
return keyStream2;
}

public void setKeyStream2(String keyStream2) {
this.keyStream2 = keyStream2;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DeleteKeyField that = (DeleteKeyField) o;
return keyStream.equals(that.keyStream)
&& keyLookup.equals(that.keyLookup)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import org.apache.hop.metadata.api.HopMetadataProperty;
import org.apache.hop.metadata.api.HopMetadataPropertyType;

@Getter
@Setter
public class DeleteLookupField {

@HopMetadataProperty(
Expand Down Expand Up @@ -65,48 +69,14 @@ public DeleteLookupField(String schemaName, String tableName, List<DeleteKeyFiel
this.tableName = tableName;
}

/**
* @return Returns the tableName.
*/
public String getTableName() {
return tableName;
}

/**
* @param tableName The tableName to set.
*/
public void setTableName(String tableName) {
this.tableName = tableName;
}

public String getSchemaName() {
return schemaName;
}

public void setSchemaName(String schemaName) {
this.schemaName = schemaName;
}

/**
* Gets fields
*
* @return value of fields
*/
public List<DeleteKeyField> getFields() {
return fields;
}

/**
* @param fields The fields to set
*/
public void setFields(List<DeleteKeyField> fields) {
this.fields = fields;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DeleteLookupField that = (DeleteLookupField) o;
return fields.equals(that.fields)
&& Objects.equals(schemaName, that.schemaName)
Expand Down
Loading
Loading