Search in sources :

Example 16 with IPentahoResultSet

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

the class ConnectionIT method testMDX_VFS_zipped_Schema.

/**
 * This test currently fails, due to Mondrian not understanding the catalog URL. I'm guessing we're not using the
 * latest mondrian libs that support mondrian
 */
@SuppressWarnings("deprecation")
public void testMDX_VFS_zipped_Schema() {
    startTest();
    // StandaloneSession session = new StandaloneSession(Messages.getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
    // SolutionRepositoryVfs.setSolutionRepository( PentahoSystem.getSolutionRepository( session ) );
    IPentahoSession session = new StandaloneSession("Admin");
    // $NON-NLS-1$ //$NON-NLS-2$
    OutputStream outputStream = this.getOutputStream("ConnectionTest.testSQLConnection", ".csv");
    File file = // $NON-NLS-1$
    new File(PentahoSystem.getApplicationContext().getSolutionPath("test/datasources/SampleDataSchema.zip"));
    // $NON-NLS-1$ //$NON-NLS-2$
    String catalog = "zip:" + file.toURI().toString() + "!/SampleData.mondrian.xml";
    // $NON-NLS-1$
    catalog = "solution:/test/datasources/SampleData.mondrian.xml;vfs=true";
    IPentahoConnection connection = PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, "jdbc:hsqldb:hsql://localhost:9001/sampledata; Catalog=" + catalog, "mondrian", "sa", "", session, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    null);
    String query = // $NON-NLS-1$
    "select {[Measures].[Actual], [Measures].[Budget]} on rows, {[Region].[All Regions]} ON columns from [Quadrant Analysis] WHERE ([Positions].[All Positions])";
    try {
        IPentahoResultSet results = connection.executeQuery(query);
        Object[][] columnHeaders = results.getMetaData().getColumnHeaders();
        for (int row = columnHeaders.length - 1; row >= 0; row--) {
            for (int col = 0; col < columnHeaders[row].length; col++) {
                // $NON-NLS-1$
                outputStream.write((columnHeaders[row][col] + "\t").getBytes());
            }
            outputStream.write('\n');
        }
        Object[][] rowHeaders = results.getMetaData().getRowHeaders();
        int rowIdx = 0;
        Object[] row = results.next();
        while (row != null) {
            for (int colIdx = rowHeaders[rowIdx].length - 1; colIdx >= 0; colIdx--) {
                // $NON-NLS-1$
                outputStream.write((rowHeaders[rowIdx][colIdx].toString() + "\t").getBytes());
            }
            for (int colIdx = 0; colIdx < row.length; colIdx++) {
                // $NON-NLS-1$
                outputStream.write((row[colIdx] + "\t").getBytes());
            }
            outputStream.write('\n');
            row = results.next();
            rowIdx++;
        }
        results.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    connection.close();
    finishTest();
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) OutputStream(java.io.OutputStream) File(java.io.File)

Example 17 with IPentahoResultSet

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

the class ConnectionIT method testSQLConnectionWithAllInfo.

public void testSQLConnectionWithAllInfo() {
    startTest();
    IPentahoSession session = new StandaloneSession("Admin");
    // $NON-NLS-1$ //$NON-NLS-2$
    OutputStream outputStream = this.getOutputStream("ConnectionTest.testConnectionWithPropertyName", ".csv");
    File file = // $NON-NLS-1$
    new File(PentahoSystem.getApplicationContext().getSolutionPath("test/datasources/SampleData.mondrian.xml"));
    IPentahoConnection connection = PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, "jdbc:hsqldb:hsql://localhost:9001/sampledata; Catalog=" + file.toURI().toString(), "mondrian", "sa", "", session, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    this);
    try {
        // $NON-NLS-1$
        IPentahoResultSet results = connection.executeQuery("select * from DEPARTMENT_MANAGERS");
        Object[][] columnHeaders = results.getMetaData().getColumnHeaders();
        for (int row = 0; row < columnHeaders.length; row++) {
            for (int col = 0; col < columnHeaders[0].length; col++) {
                outputStream.write(columnHeaders[row][col].toString().getBytes());
                // $NON-NLS-1$
                outputStream.write(",".getBytes());
            }
            // $NON-NLS-1$
            outputStream.write("\n".getBytes());
        }
        Object[] row = results.next();
        while (row != null) {
            for (int i = 0; i < row.length; i++) {
                outputStream.write(row[i].toString().getBytes());
                // $NON-NLS-1$
                outputStream.write(",".getBytes());
            }
            // $NON-NLS-1$
            outputStream.write("\n".getBytes());
            row = results.next();
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    connection.close();
    finishTest();
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) OutputStream(java.io.OutputStream) File(java.io.File)

Example 18 with IPentahoResultSet

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

the class MultipleComponentIT method testDataUtility4.

public void testDataUtility4() {
    startTest();
    IPentahoResultSet rs4 = getResultSet3();
    String xmlString4 = DataUtilities.getXMLString(rs4);
    // $NON-NLS-1$
    assertTrue(xmlString4.indexOf("DATA2") > 0);
    finishTest();
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet)

Example 19 with IPentahoResultSet

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

the class MultipleComponentIT method testDataUtility.

public void testDataUtility() {
    startTest();
    IPentahoResultSet rs = getResultSet();
    String xmlString = DataUtilities.getXMLString(rs);
    // $NON-NLS-1$
    assertTrue(xmlString.indexOf("DATA2") > 0);
    finishTest();
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet)

Example 20 with IPentahoResultSet

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

the class FilterDefinitionIT method setGlobalParams.

private void setGlobalParams() {
    IPentahoResultSet rs = getFakeResultSet();
    SimpleParameterProvider spp = (SimpleParameterProvider) PentahoSystem.getGlobalParameters();
    // $NON-NLS-1$
    spp.setParameter("customerNamesList", rs);
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Aggregations

IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)113 Test (org.junit.Test)26 Node (org.dom4j.Node)18 ArrayList (java.util.ArrayList)17 IPentahoMetaData (org.pentaho.commons.connection.IPentahoMetaData)12 Iterator (java.util.Iterator)10 List (java.util.List)10 IPentahoConnection (org.pentaho.commons.connection.IPentahoConnection)10 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)10 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)10 OutputStream (java.io.OutputStream)9 ResultSetCompareAction (org.pentaho.actionsequence.dom.actions.ResultSetCompareAction)8 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)8 XQConnection (org.pentaho.platform.plugin.services.connections.xquery.XQConnection)8 SQLException (java.sql.SQLException)7 HashMap (java.util.HashMap)6 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)6 Map (java.util.Map)5 Set (java.util.Set)5 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)5