use of org.pentaho.commons.connection.memory.MemoryMetaData in project pentaho-platform by pentaho.
the class JavaScriptResultSetIT method testCopy.
public void testCopy() {
MemoryMetaData metadata = new MemoryMetaData(new String[][] { { "col1", "col2" } }, null);
MemoryResultSet data1 = new MemoryResultSet(metadata);
data1.addRow(new Object[] { "a", new Integer(1) });
data1.addRow(new Object[] { "b", new Integer(2) });
data1.addRow(new Object[] { "c", new Integer(3) });
MemoryResultSet data = (MemoryResultSet) data1.memoryCopy();
assertNotNull(data.getMetaData());
assertNotNull(data.getMetaData().getColumnHeaders());
assertNull(data.getMetaData().getRowHeaders());
assertEquals(2, data.getMetaData().getColumnCount());
assertEquals(1, data.getMetaData().getColumnHeaders().length);
assertEquals(2, data.getMetaData().getColumnHeaders()[0].length);
assertEquals("col1", data.getMetaData().getColumnHeaders()[0][0]);
assertEquals("col2", data.getMetaData().getColumnHeaders()[0][1]);
assertEquals(3, data.getRowCount());
assertEquals("a", data.getValueAt(0, 0));
assertEquals(1, data.getValueAt(0, 1));
assertEquals("b", data.getValueAt(1, 0));
assertEquals(2, data.getValueAt(1, 1));
assertEquals("c", data.getValueAt(2, 0));
assertEquals(3, data.getValueAt(2, 1));
}
use of org.pentaho.commons.connection.memory.MemoryMetaData in project pentaho-platform by pentaho.
the class JavaScriptResultSetIT method testGetDataRow.
public void testGetDataRow() {
MemoryMetaData metadata = new MemoryMetaData(new String[][] { { "col1", "col2" } }, null);
MemoryResultSet dataSet = new MemoryResultSet(metadata);
JavaScriptResultSet data = new JavaScriptResultSet();
data.setResultSet(dataSet);
data.addRow(new Object[] { "a", new Integer(1) });
data.addRow(new Object[] { "b", new Integer(2) });
data.addRow(new Object[] { "c", new Integer(3) });
Object[] row = data.getDataRow(0);
assertEquals(2, row.length);
assertEquals("a", row[0]);
assertEquals(1, row[1]);
row = data.getDataRow(1);
assertEquals("b", row[0]);
assertEquals(2, row[1]);
row = data.getDataRow(2);
assertEquals("c", row[0]);
assertEquals(3, row[1]);
assertNull(data.getDataRow(99));
}
use of org.pentaho.commons.connection.memory.MemoryMetaData in project pentaho-platform by pentaho.
the class JavaScriptResultSetIT method testGetDataColumn.
public void testGetDataColumn() {
MemoryMetaData metadata = new MemoryMetaData(new String[][] { { "col1", "col2" } }, null);
MemoryResultSet dataSet = new MemoryResultSet(metadata);
JavaScriptResultSet data = new JavaScriptResultSet();
data.setResultSet(dataSet);
data.addRow(new Object[] { "a", new Integer(1) });
data.addRow(new Object[] { "b", new Integer(2) });
data.addRow(new Object[] { "c", new Integer(3) });
Object[] col = data.getDataColumn(0);
assertEquals(3, col.length);
assertEquals("a", col[0]);
assertEquals("b", col[1]);
assertEquals("c", col[2]);
col = data.getDataColumn(1);
assertEquals(3, col.length);
assertEquals(1, col[0]);
assertEquals(2, col[1]);
assertEquals(3, col[2]);
}
use of org.pentaho.commons.connection.memory.MemoryMetaData in project pdi-platform-plugin by pentaho.
the class PdiAction method registerAsStepListener.
/**
* Registers this component as a step listener of a transformation. This allows this component to receive rows of data
* from the transformation when it executes. These rows are made available to other components in the action sequence
* as a result set.
*
* @param stepName
* @param trans
* @return
* @throws KettleStepException
*/
protected void registerAsStepListener(String stepName, Trans trans) throws KettleStepException {
if (trans != null) {
List<StepMetaDataCombi> stepList = trans.getSteps();
// find the specified step
for (StepMetaDataCombi step : stepList) {
if (step.stepname.equals(stepName)) {
if (log.isDebugEnabled()) {
// $NON-NLS-1$
log.debug(Messages.getInstance().getString("Kettle.DEBUG_FOUND_STEP_IMPORTER"));
}
// this is the step we are looking for
if (log.isDebugEnabled()) {
// $NON-NLS-1$
log.debug(Messages.getInstance().getString("Kettle.DEBUG_GETTING_STEP_METADATA"));
}
RowMetaInterface row = trans.getTransMeta().getStepFields(stepName);
// create the metadata that the Pentaho result sets need
String[] fieldNames = row.getFieldNames();
String[][] columns = new String[1][fieldNames.length];
for (int column = 0; column < fieldNames.length; column++) {
columns[0][column] = fieldNames[column];
}
if (log.isDebugEnabled()) {
// $NON-NLS-1$
log.debug(Messages.getInstance().getString("Kettle.DEBUG_CREATING_RESULTSET_METADATA"));
}
MemoryMetaData metaData = new MemoryMetaData(columns, null);
transformationOutputRows = new MemoryResultSet(metaData);
transformationOutputErrorRows = new MemoryResultSet(metaData);
// add ourself as a row listener
step.step.addRowListener(this);
break;
}
}
}
}
Aggregations