use of org.pentaho.commons.connection.memory.MemoryMetaData in project pentaho-platform by pentaho.
the class JavaScriptResultSet method jsFunction_setColumnHeaders.
public static Object jsFunction_setColumnHeaders(final Context cx, final Scriptable thisObj, final Object[] args, final Function funObj) {
if (args == null) {
return null;
}
if (args.length == 0) {
return null;
}
JavaScriptResultSet resultSet = (JavaScriptResultSet) thisObj;
if ((args.length == 1) && (args[0] instanceof NativeArray)) {
NativeArray array = (NativeArray) args[0];
resultSet.setMetaData(JavaScriptResultSet.createMetadata(array, thisObj));
} else if ((args.length == 2) && (args[0] instanceof NativeArray) && (args[1] instanceof NativeArray)) {
NativeArray array = (NativeArray) args[0];
MemoryMetaData metaData = JavaScriptResultSet.createMetadata(array, thisObj);
// create some metadata objects
array = (NativeArray) args[1];
int length = (int) array.getLength();
String[] columnTypes = new String[length];
for (int i = 0; i < length; i++) {
columnTypes[i] = array.get(i, thisObj).toString();
}
metaData.setColumnTypes(columnTypes);
resultSet.setMetaData(metaData);
} else {
int length = args.length;
String[] columnHeaders = new String[length];
for (int i = 0; i < length; i++) {
columnHeaders[i] = args[i].toString();
}
MemoryMetaData metaData = new MemoryMetaData(new String[][] { columnHeaders }, null);
resultSet.setMetaData(metaData);
}
return null;
}
use of org.pentaho.commons.connection.memory.MemoryMetaData in project pentaho-platform by pentaho.
the class JavaScriptResultSetIT method testPeek.
public void testPeek() {
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.peek();
assertEquals("a", row[0]);
assertEquals(1, row[1]);
row = data.peek();
assertEquals("a", row[0]);
assertEquals(1, row[1]);
row = data.peek();
assertEquals("a", row[0]);
assertEquals(1, row[1]);
row = data.next();
assertEquals("a", row[0]);
assertEquals(1, row[1]);
row = data.peek();
assertEquals("b", row[0]);
assertEquals(2, row[1]);
row = data.peek();
assertEquals("b", row[0]);
assertEquals(2, row[1]);
row = data.next();
assertEquals("b", row[0]);
assertEquals(2, row[1]);
row = data.peek();
assertEquals("c", row[0]);
assertEquals(3, row[1]);
row = data.peek();
assertEquals("c", row[0]);
assertEquals(3, row[1]);
row = data.next();
assertEquals("c", row[0]);
assertEquals(3, row[1]);
row = data.peek();
assertNull(row);
row = data.peek();
assertNull(row);
row = data.peek();
assertNull(row);
row = data.next();
assertNull(row);
data.beforeFirst();
row = data.peek();
assertEquals("a", row[0]);
assertEquals(1, row[1]);
}
use of org.pentaho.commons.connection.memory.MemoryMetaData in project pentaho-platform by pentaho.
the class JavaScriptResultSetIT method testAddRow.
public void testAddRow() {
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) });
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 MultipleComponentIT method getResultSet2.
private IPentahoResultSet getResultSet2() {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Object[][] columnHeaders = new Object[][] { { "COL1", "COL2", "COL3" } };
List columnHeadersList = new ArrayList();
// $NON-NLS-1$
columnHeadersList.add("COL1");
// $NON-NLS-1$
columnHeadersList.add("COL2");
// $NON-NLS-1$
columnHeadersList.add("COL3");
MemoryMetaData md2 = new MemoryMetaData(columnHeaders, null);
// emd.getAttribute(1, 1, "COL1"); //$NON-NLS-1$
// emd.setBusinessColumns(columnHeadersList);
MemoryResultSet rs = new MemoryResultSet(md2);
// $NON-NLS-1$ //$NON-NLS-2$
rs.addRow(new Object[] { "DATA1", "DATA2", new Date() });
return rs;
}
use of org.pentaho.commons.connection.memory.MemoryMetaData in project pentaho-platform by pentaho.
the class MultipleComponentIT method getResultSet3.
private IPentahoResultSet getResultSet3() {
List columnHeadersList = new ArrayList();
// $NON-NLS-1$
columnHeadersList.add("COL1");
// $NON-NLS-1$
columnHeadersList.add("COL2");
// $NON-NLS-1$
columnHeadersList.add("COL3");
MemoryMetaData md3 = new MemoryMetaData(columnHeadersList);
MemoryResultSet rs = new MemoryResultSet(md3);
// $NON-NLS-1$ //$NON-NLS-2$
rs.addRow(new Object[] { "DATA1", "DATA2", new Date() });
return rs;
}
Aggregations