Search in sources :

Example 16 with IPentahoMetaData

use of org.pentaho.commons.connection.IPentahoMetaData in project pentaho-platform by pentaho.

the class SQLResultSetTest method testMemoryCopy_setMetadaQuery.

@Test
public void testMemoryCopy_setMetadaQuery() throws SQLException {
    IPentahoMetaData metadata = new QueryModelMetaData(mock(QueryModelMetaData.class));
    SQLResultSet resultSet = new SQLResultSet(nativeResultSet, nativeConnection);
    resultSet.setMetaData(metadata);
    IPentahoResultSet memoryCopyResultSet = resultSet.memoryCopy();
    assertEquals(metadata.getClass(), memoryCopyResultSet.getMetaData().getClass());
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) QueryModelMetaData(org.pentaho.metadata.query.model.util.QueryModelMetaData) IPentahoMetaData(org.pentaho.commons.connection.IPentahoMetaData) Test(org.junit.Test)

Example 17 with IPentahoMetaData

use of org.pentaho.commons.connection.IPentahoMetaData in project pentaho-platform by pentaho.

the class PentahoFlashChartTest method createFromLists.

public static MemoryResultSet createFromLists(List colHeaders, List rHeaders, List data) {
    Object[][] columnHeaders = new String[1][colHeaders.size()];
    for (int i = 0; i < colHeaders.size(); i++) {
        columnHeaders[0][i] = colHeaders.get(i);
    }
    Object[][] rowHeaders = new String[rHeaders.size()][1];
    for (int i = 0; i < rHeaders.size(); i++) {
        rowHeaders[i][0] = rHeaders.get(i);
    }
    IPentahoMetaData metaData = new MemoryMetaData(columnHeaders, rowHeaders);
    MemoryResultSet result = new MemoryResultSet(metaData);
    for (int i = 0; i < data.size(); i++) {
        result.addRow(((List) data.get(i)).toArray());
    }
    return result;
}
Also used : MemoryMetaData(org.pentaho.commons.connection.memory.MemoryMetaData) IPentahoMetaData(org.pentaho.commons.connection.IPentahoMetaData) MemoryResultSet(org.pentaho.commons.connection.memory.MemoryResultSet)

Example 18 with IPentahoMetaData

use of org.pentaho.commons.connection.IPentahoMetaData in project pentaho-platform by pentaho.

the class MultipleComponentIT method getResultSet.

private IPentahoResultSet getResultSet() {
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    Object[][] columnHeaders = new Object[][] { { "COL1", "COL2", "COL3" } };
    IPentahoMetaData md = new MemoryMetaData(columnHeaders, null);
    MemoryResultSet rs = new MemoryResultSet(md);
    // $NON-NLS-1$ //$NON-NLS-2$
    rs.addRow(new Object[] { "DATA1", "DATA2", new Date() });
    rs.isScrollable();
    return rs;
}
Also used : MemoryMetaData(org.pentaho.commons.connection.memory.MemoryMetaData) IPentahoMetaData(org.pentaho.commons.connection.IPentahoMetaData) Date(java.util.Date) MemoryResultSet(org.pentaho.commons.connection.memory.MemoryResultSet)

Example 19 with IPentahoMetaData

use of org.pentaho.commons.connection.IPentahoMetaData in project pentaho-platform by pentaho.

the class RulesIT method testQueryRule.

public void testQueryRule() {
    startTest();
    IPentahoResultSet resultSet = null;
    try {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        IRuntimeContext context = run("/test/rules/query_rule1.xaction");
        // $NON-NLS-1$
        assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus());
        // $NON-NLS-1$
        Object result = context.getOutputParameter("rule-result").getValue();
        // $NON-NLS-1$
        assertNotNull(Messages.getInstance().getString("RulesTest.ERROR_0001_NULL_RESULT"), result);
        // $NON-NLS-1$
        assertTrue(Messages.getInstance().getString("RulesTest.ERROR_0007_LOOKUP_RULE_INVALID_RESULT"), (result instanceof IPentahoResultSet));
        resultSet = (IPentahoResultSet) result;
        IPentahoMetaData metaData = resultSet.getMetaData();
        Object[][] columnHeaders = metaData.getColumnHeaders();
        String columnHeader = columnHeaders[0][0].toString();
        // $NON-NLS-1$ //$NON-NLS-2$
        assertEquals(Messages.getInstance().getString("RulesTest.ERROR_0009_LOOKUP_RULE_COLUMN_MISSING"), "POSITIONTITLE", columnHeader);
        Object[] row = resultSet.next();
        // $NON-NLS-1$
        assertNotNull(Messages.getInstance().getString("RulesTest.ERROR_0007_LOOKUP_RULE_INVALID_RESULT"), row);
        // $NON-NLS-1$
        info(Messages.getInstance().getString("RulesTest.DEBUG_LOOKUP_RULE_SUCCESS", row[0].toString()));
    } finally {
        if (resultSet != null) {
            resultSet.closeConnection();
        }
    }
    finishTest();
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IPentahoMetaData(org.pentaho.commons.connection.IPentahoMetaData) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext)

Example 20 with IPentahoMetaData

use of org.pentaho.commons.connection.IPentahoMetaData in project pentaho-platform by pentaho.

the class RulesIT method testQueryRule2.

public void testQueryRule2() {
    startTest();
    IPentahoResultSet resultSet = null;
    try {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        IRuntimeContext context = run("/test/rules/query_rule2.xaction");
        // $NON-NLS-1$
        assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus());
        // $NON-NLS-1$
        Object result = context.getOutputParameter("rule-result").getValue();
        // $NON-NLS-1$
        assertNotNull(Messages.getInstance().getString("RulesTest.ERROR_0001_NULL_RESULT"), result);
        // $NON-NLS-1$
        assertTrue(Messages.getInstance().getString("RulesTest.ERROR_0007_LOOKUP_RULE_INVALID_RESULT"), (result instanceof IPentahoResultSet));
        resultSet = (IPentahoResultSet) result;
        IPentahoMetaData metaData = resultSet.getMetaData();
        Object[][] columnHeaders = metaData.getColumnHeaders();
        String regionHeader = columnHeaders[0][0].toString();
        String departmentHeader = columnHeaders[0][1].toString();
        // $NON-NLS-1$ //$NON-NLS-2$
        assertEquals(Messages.getInstance().getString("RulesTest.ERROR_0009_LOOKUP_RULE_COLUMN_MISSING"), "REGION", regionHeader);
        assertEquals(Messages.getInstance().getString("RulesTest.ERROR_0009_LOOKUP_RULE_COLUMN_MISSING"), "DEPARTMENT", // $NON-NLS-1$ //$NON-NLS-2$
        departmentHeader);
        Object[] row = resultSet.next();
        while (row != null) {
            String region = row[0].toString();
            String department = row[1].toString();
            // $NON-NLS-1$
            assertNotNull(Messages.getInstance().getString("RulesTest.ERROR_0009_LOOKUP_RULE_COLUMN_MISSING"), region);
            // $NON-NLS-1$
            assertNotNull(Messages.getInstance().getString("RulesTest.ERROR_0009_LOOKUP_RULE_COLUMN_MISSING"), department);
            // $NON-NLS-1$
            info(region + ", " + department);
            row = resultSet.next();
        }
    } finally {
        if (resultSet != null) {
            resultSet.closeConnection();
        }
    }
    finishTest();
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IPentahoMetaData(org.pentaho.commons.connection.IPentahoMetaData) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext)

Aggregations

IPentahoMetaData (org.pentaho.commons.connection.IPentahoMetaData)26 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)12 MemoryMetaData (org.pentaho.commons.connection.memory.MemoryMetaData)9 MemoryResultSet (org.pentaho.commons.connection.memory.MemoryResultSet)7 ArrayList (java.util.ArrayList)4 List (java.util.List)4 SQLConnection (org.pentaho.platform.plugin.services.connections.sql.SQLConnection)4 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 MarshallableResultSet (org.pentaho.commons.connection.marshal.MarshallableResultSet)3 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)3 SQLMetaData (org.pentaho.platform.plugin.services.connections.sql.SQLMetaData)3 StringTokenizer (java.util.StringTokenizer)2 Element (org.dom4j.Element)2 Test (org.junit.Test)2 MarshallableRow (org.pentaho.commons.connection.marshal.MarshallableRow)2 SerializedResultSet (org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet)2 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)2 ModifiableConfiguration (org.pentaho.reporting.libraries.base.config.ModifiableConfiguration)2 FileNotFoundException (java.io.FileNotFoundException)1