Search in sources :

Example 6 with XQConnection

use of org.pentaho.platform.plugin.services.connections.xquery.XQConnection in project pentaho-platform by pentaho.

the class XQueryIT method testExecuteWrongQuery.

public void testExecuteWrongQuery() throws Exception {
    try {
        XQConnection connection = new XQConnection();
        StaticQueryContext mockContext = mock(StaticQueryContext.class);
        when(mockContext.compileQuery(TEST_QUERY)).thenThrow(new XPathException("Test XPathException"));
        connection.sqc = mockContext;
        IPentahoResultSet data = connection.executeQuery(TEST_QUERY);
        fail("Should throw XPathException");
    } catch (XPathException e) {
    // valid
    }
}
Also used : StaticQueryContext(net.sf.saxon.query.StaticQueryContext) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) XQConnection(org.pentaho.platform.plugin.services.connections.xquery.XQConnection) XPathException(net.sf.saxon.trans.XPathException)

Example 7 with XQConnection

use of org.pentaho.platform.plugin.services.connections.xquery.XQConnection in project pentaho-platform by pentaho.

the class XQueryIT method testGetDataRow.

public void testGetDataRow() throws Exception {
    XQConnection connection = new XQConnection();
    IPentahoResultSet data = connection.executeQuery(TEST_QUERY);
    assertNotNull("result set is null", data);
    Object[] row = data.getDataRow(1);
    assertEquals("Harry Potter", row[0]);
    assertEquals("J K. Rowling", row[1]);
    assertEquals("2005", row[2]);
    assertEquals("29.99", row[3]);
    row = data.getDataRow(3);
    assertEquals("Learning XML", row[0]);
    assertEquals("Erik T. Ray", row[1]);
    assertEquals("2003", row[2]);
    assertEquals("39.95", row[3]);
    row = data.getDataRow(99);
    assertNull(row);
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) XQConnection(org.pentaho.platform.plugin.services.connections.xquery.XQConnection)

Example 8 with XQConnection

use of org.pentaho.platform.plugin.services.connections.xquery.XQConnection in project pentaho-platform by pentaho.

the class XQueryIT method testExecuteQuery.

public void testExecuteQuery() throws Exception {
    XQConnection connection = new XQConnection();
    IPentahoResultSet data = connection.executeQuery(TEST_QUERY);
    assertNotNull("result set is null", data);
    assertTrue("result set is wrong type", data instanceof XQResultSet);
    assertFalse("Should not be scrollable", data.isScrollable());
    assertEquals("row count is wrong", 4, data.getRowCount());
    assertEquals("column count is wrong", 4, data.getColumnCount());
    assertEquals("column header is wrong", "title", data.getMetaData().getColumnHeaders()[0][0]);
    assertEquals("column header is wrong", "author", data.getMetaData().getColumnHeaders()[0][1]);
    assertEquals("column header is wrong", "year", data.getMetaData().getColumnHeaders()[0][2]);
    assertEquals("column header is wrong", "price", data.getMetaData().getColumnHeaders()[0][3]);
    // these don't do much but they should not cause errors
    data.close();
    data.closeConnection();
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) XQConnection(org.pentaho.platform.plugin.services.connections.xquery.XQConnection) XQResultSet(org.pentaho.platform.plugin.services.connections.xquery.XQResultSet)

Example 9 with XQConnection

use of org.pentaho.platform.plugin.services.connections.xquery.XQConnection in project pentaho-platform by pentaho.

the class XQueryIT method testGetDataColumn.

public void testGetDataColumn() throws Exception {
    XQConnection connection = new XQConnection();
    IPentahoResultSet data = connection.executeQuery(TEST_QUERY);
    assertNotNull("result set is null", data);
    Object[] col = data.getDataColumn(2);
    assertEquals("row count is wrong", 4, col.length);
    assertEquals("2005", col[0]);
    assertEquals("2005", col[1]);
    assertEquals("2003", col[2]);
    assertEquals("2003", col[3]);
    col = data.getDataColumn(99);
    assertNull(col);
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) XQConnection(org.pentaho.platform.plugin.services.connections.xquery.XQConnection)

Example 10 with XQConnection

use of org.pentaho.platform.plugin.services.connections.xquery.XQConnection in project pentaho-platform by pentaho.

the class XQueryBaseComponent method runFinalQuery.

protected boolean runFinalQuery(final IPentahoConnection localConnection, final String rawQuery, final String[] columnTypes) {
    XQueryAction xQueryAction = (XQueryAction) getActionDefinition();
    boolean success = false;
    String finalQuery = applyInputsToFormat(rawQuery);
    // execute the query, read the results and cache them
    try {
        IPentahoResultSet resultSet = ((XQConnection) localConnection).executeQuery(finalQuery, columnTypes);
        if (resultSet != null) {
            if (!xQueryAction.getLive().getBooleanValue(true)) {
                resultSet = resultSet.memoryCopy();
            }
            try {
                IActionOutput resultSetOutput = xQueryAction.getOutputResultSet();
                if (resultSetOutput != null) {
                    resultSetOutput.setValue(resultSet);
                }
                success = true;
            } finally {
                resultSet.close();
            }
        }
    } catch (XPathException e) {
        error(Messages.getInstance().getErrorString("XQueryBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), // $NON-NLS-1$
        e);
    }
    return success;
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) XQConnection(org.pentaho.platform.plugin.services.connections.xquery.XQConnection) XPathException(net.sf.saxon.trans.XPathException) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput) XQueryAction(org.pentaho.actionsequence.dom.actions.XQueryAction)

Aggregations

XQConnection (org.pentaho.platform.plugin.services.connections.xquery.XQConnection)10 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)8 XPathException (net.sf.saxon.trans.XPathException)4 XQResultSet (org.pentaho.platform.plugin.services.connections.xquery.XQResultSet)3 StaticQueryContext (net.sf.saxon.query.StaticQueryContext)2 Properties (java.util.Properties)1 IActionOutput (org.pentaho.actionsequence.dom.IActionOutput)1 XQueryAction (org.pentaho.actionsequence.dom.actions.XQueryAction)1 IPeekable (org.pentaho.commons.connection.IPeekable)1 ILogger (org.pentaho.platform.api.engine.ILogger)1