use of org.pentaho.di.trans.RowStepCollector in project pentaho-kettle by pentaho.
the class ExecSQLRowIT method testExecSQLRow4.
/**
* Basic Test case for Exec SQL Row. This tests a commit size of three (i.e. not autocommit but equal to input row
* size)
*/
@Test
public void testExecSQLRow4() throws Exception {
KettleEnvironment.init();
//
// Create a new transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName("transname");
// Add the database connections
for (int i = 0; i < databasesXML.length; i++) {
DatabaseMeta databaseMeta = new DatabaseMeta(databasesXML[i]);
transMeta.addDatabase(databaseMeta);
}
DatabaseMeta dbInfo = transMeta.findDatabase("db");
PluginRegistry registry = PluginRegistry.getInstance();
//
// create an injector step...
//
String injectorStepname = "injector step";
InjectorMeta im = new InjectorMeta();
// Set the information of the injector.
String injectorPid = registry.getPluginId(StepPluginType.class, im);
StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, im);
transMeta.addStep(injectorStep);
//
// create the Exec SQL Row step...
//
String stepName = "delete from [" + execsqlrow_testtable + "]";
ExecSQLRowMeta execsqlmeta = new ExecSQLRowMeta();
execsqlmeta.setDatabaseMeta(transMeta.findDatabase("db"));
execsqlmeta.setCommitSize(3);
execsqlmeta.setSqlFieldName("SQL");
String execSqlRowId = registry.getPluginId(StepPluginType.class, execsqlmeta);
StepMeta execSqlRowStep = new StepMeta(execSqlRowId, stepName, execsqlmeta);
execSqlRowStep.setDescription("Deletes information from table [" + execsqlrow_testtable + "] on database [" + dbInfo + "]");
transMeta.addStep(execSqlRowStep);
TransHopMeta hi = new TransHopMeta(injectorStep, execSqlRowStep);
transMeta.addTransHop(hi);
// Now execute the transformation...
Trans trans = new Trans(transMeta);
trans.prepareExecution(null);
StepInterface si = trans.getStepInterface(stepName, 0);
RowStepCollector rc = new RowStepCollector();
si.addRowListener(rc);
RowProducer rp = trans.addRowProducer(injectorStepname, 0);
trans.startThreads();
// add rows
List<RowMetaAndData> inputList = createDataRows();
for (RowMetaAndData rm : inputList) {
rp.putRow(rm.getRowMeta(), rm.getData());
}
rp.finished();
trans.waitUntilFinished();
List<RowMetaAndData> resultRows = rc.getRowsWritten();
List<RowMetaAndData> goldRows = createResultDataRows();
checkRows(goldRows, resultRows);
}
use of org.pentaho.di.trans.RowStepCollector in project pentaho-kettle by pentaho.
the class ExecSQLRowIT method testExecSQLRow2.
/**
* Basic Test case for Exec SQL Row. This tests a commit size of one (i.e. "simulated" autocommit)
*/
@Test
public void testExecSQLRow2() throws Exception {
KettleEnvironment.init();
//
// Create a new transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName("transname");
// Add the database connections
for (int i = 0; i < databasesXML.length; i++) {
DatabaseMeta databaseMeta = new DatabaseMeta(databasesXML[i]);
transMeta.addDatabase(databaseMeta);
}
DatabaseMeta dbInfo = transMeta.findDatabase("db");
PluginRegistry registry = PluginRegistry.getInstance();
//
// create an injector step...
//
String injectorStepname = "injector step";
InjectorMeta im = new InjectorMeta();
// Set the information of the injector.
String injectorPid = registry.getPluginId(StepPluginType.class, im);
StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, im);
transMeta.addStep(injectorStep);
//
// create the Exec SQL Row step...
//
String stepName = "delete from [" + execsqlrow_testtable + "]";
ExecSQLRowMeta execsqlmeta = new ExecSQLRowMeta();
execsqlmeta.setDatabaseMeta(transMeta.findDatabase("db"));
execsqlmeta.setCommitSize(1);
execsqlmeta.setSqlFieldName("SQL");
String execSqlRowId = registry.getPluginId(StepPluginType.class, execsqlmeta);
StepMeta execSqlRowStep = new StepMeta(execSqlRowId, stepName, execsqlmeta);
execSqlRowStep.setDescription("Deletes information from table [" + execsqlrow_testtable + "] on database [" + dbInfo + "]");
transMeta.addStep(execSqlRowStep);
TransHopMeta hi = new TransHopMeta(injectorStep, execSqlRowStep);
transMeta.addTransHop(hi);
// Now execute the transformation...
Trans trans = new Trans(transMeta);
trans.prepareExecution(null);
StepInterface si = trans.getStepInterface(stepName, 0);
RowStepCollector rc = new RowStepCollector();
si.addRowListener(rc);
RowProducer rp = trans.addRowProducer(injectorStepname, 0);
trans.startThreads();
// add rows
List<RowMetaAndData> inputList = createDataRows();
for (RowMetaAndData rm : inputList) {
rp.putRow(rm.getRowMeta(), rm.getData());
}
rp.finished();
trans.waitUntilFinished();
List<RowMetaAndData> resultRows = rc.getRowsWritten();
List<RowMetaAndData> goldRows = createResultDataRows();
checkRows(goldRows, resultRows);
}
Aggregations