|
55 | 55 | import org.pentaho.di.trans.steps.mergejoin.MergeJoinMeta; |
56 | 56 | import org.pentaho.di.trans.steps.tableinput.TableInputMeta; |
57 | 57 | import org.pentaho.di.trans.steps.tableoutput.TableOutputMeta; |
58 | | - |
| 58 | +import org.pentaho.di.trans.steps.insertupdate.InsertUpdateMeta; |
59 | 59 | import ca.sqlpower.architect.ArchitectSession; |
60 | 60 | import ca.sqlpower.architect.DepthFirstSearch; |
61 | 61 | import ca.sqlpower.architect.ddl.DDLUtils; |
@@ -334,36 +334,47 @@ public void doExport(List<SQLTable> tableList, SQLDatabase targetDB ) throws SQL |
334 | 334 | List<StepMeta> mergeSteps; |
335 | 335 |
|
336 | 336 | 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 |
349 | 364 | // if (!mergeSteps.isEmpty()) { |
350 | 365 | // transMeta.addNote(new NotePadMeta("The final hop is disabled because the join types may need to be updated.",0,0,125,125)); |
351 | 366 | // tasksToDo.add("Enable the final hop in " + transMeta.getName() + " after correcting the merge joins."); |
352 | 367 | // transHopMeta.setEnabled(false); |
353 | 368 | // } |
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()); |
363 | 372 | } |
364 | | - |
365 | | -// } |
366 | | - |
| 373 | + } |
| 374 | + if (monitor.isCancelled()) { |
| 375 | + cancel(); |
| 376 | + return; |
| 377 | + } |
367 | 378 | if (!noTransTables.isEmpty()) { |
368 | 379 | StringBuffer buffer = new StringBuffer(); |
369 | 380 | buffer.append("Transformations were not created for "); |
@@ -1085,6 +1096,13 @@ public void setSplittingJob(boolean newValue) { |
1085 | 1096 | settings.setSplittingJob(newValue); |
1086 | 1097 | } |
1087 | 1098 |
|
| 1099 | + public boolean isInsertUpdate() { |
| 1100 | + return settings.isInsertUpdate(); |
| 1101 | + } |
| 1102 | + |
| 1103 | + public void setIsInsertUpdate(boolean newValue) { |
| 1104 | + settings.setIsInsertUpdate(newValue); |
| 1105 | + } |
1088 | 1106 | /** |
1089 | 1107 | * Method to get the latest exported keys in a playpen. |
1090 | 1108 | * Exported keys are different for table in Database then table in PlayPen |
|
0 commit comments