Search in sources :

Example 1 with MemoryMetaData

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;
}
Also used : NativeArray(org.mozilla.javascript.NativeArray) MemoryMetaData(org.pentaho.commons.connection.memory.MemoryMetaData)

Example 2 with MemoryMetaData

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]);
}
Also used : JavaScriptResultSet(org.pentaho.platform.plugin.services.connections.javascript.JavaScriptResultSet) MemoryMetaData(org.pentaho.commons.connection.memory.MemoryMetaData) MemoryResultSet(org.pentaho.commons.connection.memory.MemoryResultSet)

Example 3 with MemoryMetaData

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));
}
Also used : JavaScriptResultSet(org.pentaho.platform.plugin.services.connections.javascript.JavaScriptResultSet) MemoryMetaData(org.pentaho.commons.connection.memory.MemoryMetaData) MemoryResultSet(org.pentaho.commons.connection.memory.MemoryResultSet)

Example 4 with MemoryMetaData

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;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MemoryMetaData(org.pentaho.commons.connection.memory.MemoryMetaData) Date(java.util.Date) MemoryResultSet(org.pentaho.commons.connection.memory.MemoryResultSet)

Example 5 with MemoryMetaData

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;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MemoryMetaData(org.pentaho.commons.connection.memory.MemoryMetaData) Date(java.util.Date) MemoryResultSet(org.pentaho.commons.connection.memory.MemoryResultSet)

Aggregations

MemoryMetaData (org.pentaho.commons.connection.memory.MemoryMetaData)29 MemoryResultSet (org.pentaho.commons.connection.memory.MemoryResultSet)24 IPentahoMetaData (org.pentaho.commons.connection.IPentahoMetaData)9 JavaScriptResultSet (org.pentaho.platform.plugin.services.connections.javascript.JavaScriptResultSet)8 ArrayList (java.util.ArrayList)4 Date (java.util.Date)3 List (java.util.List)3 Test (org.junit.Test)3 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)3 SQLException (java.sql.SQLException)2 NativeArray (org.mozilla.javascript.NativeArray)2 MarshallableResultSet (org.pentaho.commons.connection.marshal.MarshallableResultSet)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 StepMetaDataCombi (org.pentaho.di.trans.step.StepMetaDataCombi)2 SQLConnection (org.pentaho.platform.plugin.services.connections.sql.SQLConnection)2 SQLMetaData (org.pentaho.platform.plugin.services.connections.sql.SQLMetaData)2 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1