Skip to content

Commit 833d1fe

Browse files
committed
Implemented to allow user to select transformation output type. Now
Transformation output can also be generated in 'Insert/Update' type. issue #32
1 parent 90e8331 commit 833d1fe

File tree

4 files changed

+97
-27
lines changed

4 files changed

+97
-27
lines changed

src/main/java/ca/sqlpower/architect/etl/kettle/KettleJob.java

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
import org.pentaho.di.trans.steps.mergejoin.MergeJoinMeta;
5656
import org.pentaho.di.trans.steps.tableinput.TableInputMeta;
5757
import org.pentaho.di.trans.steps.tableoutput.TableOutputMeta;
58-
58+
import org.pentaho.di.trans.steps.insertupdate.InsertUpdateMeta;
5959
import ca.sqlpower.architect.ArchitectSession;
6060
import ca.sqlpower.architect.DepthFirstSearch;
6161
import ca.sqlpower.architect.ddl.DDLUtils;
@@ -334,36 +334,47 @@ public void doExport(List<SQLTable> tableList, SQLDatabase targetDB ) throws SQL
334334
List<StepMeta> mergeSteps;
335335

336336
mergeSteps = createMergeJoins(settings.getJoinType(), transMeta, inputSteps,keyFields1, keyFields2);
337-
TableOutputMeta tableOutputMeta = new TableOutputMeta();
338-
tableOutputMeta.setDatabaseMeta(targetDatabaseMeta);
339-
tableOutputMeta.setTablename(table.getName());
340-
tableOutputMeta.setSchemaName(settings.getSchemaName());
341-
StepMeta stepMeta = new StepMeta("TableOutput", "Output to " + table.getName(), tableOutputMeta);
342-
stepMeta.setDraw(true);
343-
stepMeta.setLocation((inputSteps.size()+1)*spacing, inputSteps.size()*spacing);
344-
transMeta.addStep(stepMeta);
345-
if (inputSteps.size() >0 ) {
346-
TransHopMeta transHopMeta =
347-
new TransHopMeta(mergeSteps.isEmpty()?inputSteps.get(0):mergeSteps.get(mergeSteps.size()-1), stepMeta);
348-
//Commented as it always disable the hop for merge join
337+
// boolean isInserUpdate = false;
338+
StepMeta stepMeta = null;
339+
if (settings.isInsertUpdate()) {
340+
InsertUpdateMeta insertUpdateMeta = new InsertUpdateMeta();
341+
insertUpdateMeta.setDefault();
342+
insertUpdateMeta.setDatabaseMeta(targetDatabaseMeta);
343+
insertUpdateMeta.setTableName(table.getName());
344+
insertUpdateMeta.setSchemaName(settings.getSchemaName());
345+
stepMeta = new StepMeta("InsertUpdate", "Insert/Update " + table.getName(), insertUpdateMeta);
346+
347+
} else {
348+
TableOutputMeta tableOutputMeta = new TableOutputMeta();
349+
tableOutputMeta.setDatabaseMeta(targetDatabaseMeta);
350+
tableOutputMeta.setTablename(table.getName());
351+
tableOutputMeta.setSchemaName(settings.getSchemaName());
352+
stepMeta = new StepMeta("TableOutput", "Output to " + table.getName(), tableOutputMeta);
353+
354+
}
355+
if(stepMeta != null) {
356+
stepMeta.setDraw(true);
357+
stepMeta.setLocation((inputSteps.size()+1)*spacing, inputSteps.size()*spacing);
358+
transMeta.addStep(stepMeta);
359+
}
360+
if (inputSteps.size() > 1 ) {
361+
TransHopMeta transHopMeta =
362+
new TransHopMeta(mergeSteps.isEmpty()?inputSteps.get(0):mergeSteps.get(mergeSteps.size()-1), stepMeta);
363+
//Commented as it always disable the hop for merge join
349364
// if (!mergeSteps.isEmpty()) {
350365
// transMeta.addNote(new NotePadMeta("The final hop is disabled because the join types may need to be updated.",0,0,125,125));
351366
// tasksToDo.add("Enable the final hop in " + transMeta.getName() + " after correcting the merge joins.");
352367
// transHopMeta.setEnabled(false);
353368
// }
354-
transMeta.addTransHop(transHopMeta);
355-
356-
transformations.add(transMeta);
357-
logger.debug("Added a Trnasformation job for table "+table.getName());
358-
}
359-
}
360-
if (monitor.isCancelled()) {
361-
cancel();
362-
return;
369+
transMeta.addTransHop(transHopMeta);
370+
transformations.add(transMeta);
371+
logger.debug("Added a Trnasformation job for table "+table.getName());
363372
}
364-
365-
// }
366-
373+
}
374+
if (monitor.isCancelled()) {
375+
cancel();
376+
return;
377+
}
367378
if (!noTransTables.isEmpty()) {
368379
StringBuffer buffer = new StringBuffer();
369380
buffer.append("Transformations were not created for ");
@@ -1085,6 +1096,13 @@ public void setSplittingJob(boolean newValue) {
10851096
settings.setSplittingJob(newValue);
10861097
}
10871098

1099+
public boolean isInsertUpdate() {
1100+
return settings.isInsertUpdate();
1101+
}
1102+
1103+
public void setIsInsertUpdate(boolean newValue) {
1104+
settings.setIsInsertUpdate(newValue);
1105+
}
10881106
/**
10891107
* Method to get the latest exported keys in a playpen.
10901108
* Exported keys are different for table in Database then table in PlayPen

src/main/java/ca/sqlpower/architect/etl/kettle/KettleSettings.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ public class KettleSettings extends AbstractSPObject {
7373

7474
private boolean isSplittingJob = false;
7575

76+
/**
77+
* Flag set to 'true' will write the output to 'Insert/Update' type
78+
* set to 'false' will write the output to the 'Table output' type
79+
*/
80+
private boolean isInsertUpdate = true;
81+
7682
/**
7783
* split job number
7884
* used to split the big job into smaller batch of spliJob no
@@ -212,12 +218,31 @@ public boolean isSplittingJob() {
212218
}
213219

214220
/**
215-
* @param isSplittingJob the isSplittingJob to set
221+
* @param newValue the isSplittingJob to set
216222
*/
217223
@Mutator
218224
public void setSplittingJob(boolean newValue) {
219225
boolean oldValue = isSplittingJob;
220226
this.isSplittingJob = newValue;
221227
firePropertyChange("isSplittingJob", oldValue, isSplittingJob);
222228
}
229+
230+
/**
231+
* @return isInsertUpdate
232+
*/
233+
@Accessor
234+
public boolean isInsertUpdate() {
235+
return isInsertUpdate;
236+
}
237+
238+
/**
239+
*
240+
* @param newValue
241+
*/
242+
@Mutator
243+
public void setIsInsertUpdate(boolean newValue) {
244+
boolean oldValue = isInsertUpdate;
245+
this.isInsertUpdate = newValue;
246+
firePropertyChange("isInsertUpdate", oldValue, isInsertUpdate);
247+
}
223248
}

src/main/java/ca/sqlpower/architect/swingui/KettleJobPanel.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,17 @@ public class KettleJobPanel implements DataEntryPanel {
157157
*/
158158
private JComboBox reposDB;
159159

160+
/**
161+
* The radio button that denoted the output type is 'Table output'.
162+
*/
163+
private JRadioButton tableOutputRadioButton;
164+
165+
private ButtonGroup outputButtonGroup;
166+
/**
167+
* The radio button that denoted the output type is 'Insert/Update'.
168+
*/
169+
private JRadioButton insertUpdateRadioButton;
170+
160171
/**
161172
* The session that we will get the play pen from to create a Kettle job and transformations
162173
* for.
@@ -205,7 +216,9 @@ public void actionPerformed(ActionEvent e) {
205216
});
206217

207218
schemaName = new JTextField(settings.getSchemaName());
208-
219+
//output type
220+
insertUpdateRadioButton = new JRadioButton(Messages.getString("KettleJobPanel.inserUpdateOption"), settings.isInsertUpdate()); //$NON-NLS-1$
221+
tableOutputRadioButton = new JRadioButton(Messages.getString("KettleJobPanel.tableOutputOption"), !settings.isInsertUpdate()); //$NON-NLS-1$
209222
saveFileRadioButton = new JRadioButton(Messages.getString("KettleJobPanel.saveJobToFileOption"), settings.isSavingToFile()); //$NON-NLS-1$
210223
//saveto file(XML)
211224
filePath = new JTextField(settings.getFilePath());
@@ -280,6 +293,9 @@ public void actionPerformed(ActionEvent e) {
280293
ASUtils.showDbcsDialog(parentWindow, (JDBCDataSource)reposDB.getSelectedItem(), null);
281294
}
282295
});
296+
outputButtonGroup = new ButtonGroup();
297+
outputButtonGroup.add(insertUpdateRadioButton);
298+
outputButtonGroup.add(tableOutputRadioButton);
283299

284300
ButtonGroup saveByButtonGroup = new ButtonGroup();
285301
saveByButtonGroup.add(saveFileRadioButton);
@@ -359,6 +375,13 @@ public void stateChanged(ChangeEvent e) {
359375
builder.append(Messages.getString("KettleJobPanel.defaultJoinTypeLabel")); //$NON-NLS-1$
360376
builder.append(defaultJoinType);
361377
builder.nextLine();
378+
builder.appendSeparator();
379+
builder.append(""); //$NON-NLS-1$
380+
builder.append(Messages.getString("KettleJobPanel.outputTypeLabel")); //$NON-NLS-1$
381+
builder.append(insertUpdateRadioButton);
382+
builder.append(tableOutputRadioButton);
383+
builder.nextLine();
384+
builder.appendSeparator();
362385
builder.append(""); //$NON-NLS-1$
363386
builder.append(saveFileRadioButton, 3);
364387
builder.nextLine();
@@ -473,6 +496,7 @@ private void copySettingsToProject() {
473496
settings.setSavingToFile(isSaveFile());
474497
settings.setTimeStampExcluded(timeStampCheckBox.isSelected());
475498
settings.setSplittingJob(splitJobCheckBox.isSelected());
499+
settings.setIsInsertUpdate(insertUpdateRadioButton.isSelected());
476500
if(splitJobCheckBox.isSelected()) {
477501
settings.setSplitJobNo((Integer)splitSpinner.getValue());
478502
}

src/main/resources/ca/sqlpower/architect/swingui/messages.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ KettleJobPanel.jobPathNotSetError=The job path was not set.\n The Kettle job was
235235
KettleJobPanel.pathLabel=Path:
236236
KettleJobPanel.propertiesButton=Properties...
237237
KettleJobPanel.repositoryLabel=Repository:
238+
KettleJobPanel.inserUpdateOption=Insert/Update
239+
KettleJobPanel.tableOutputOption=Table output
240+
KettleJobPanel.outputTypeLabel=Output Type:
238241
KettleJobPanel.saveJobToFileOption=Save Job to File
239242
KettleJobPanel.saveJobToRepositoryOption=Save Job to Repository
240243
KettleJobPanel.schemaNameLabel=Schema Name:

0 commit comments

Comments
 (0)