Search in sources :

Example 1 with XQResultSet

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

the class XQueryIT method testRowLimit.

public void testRowLimit() throws Exception {
    XQConnection connection = new XQConnection();
    connection.setMaxRows(2);
    IPentahoResultSet data = connection.executeQuery(TEST_QUERY);
    assertNotNull("result set is null", data);
    assertTrue("result set is wrong type", data instanceof XQResultSet);
    assertEquals("row count is wrong", 2, data.getRowCount());
    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]);
    Object[] row = data.next();
    assertEquals("Everyday Italian", row[0]);
    assertEquals("Giada De Laurentiis", row[1]);
    assertEquals("2005", row[2]);
    assertEquals("30.00", row[3]);
    row = data.next();
    assertEquals("Harry Potter", row[0]);
    assertEquals("J K. Rowling", row[1]);
    assertEquals("2005", row[2]);
    assertEquals("29.99", row[3]);
    row = data.next();
    assertNull(row);
}
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 2 with XQResultSet

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

the class XQueryIT method testPeek.

public void testPeek() 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);
    assertEquals("row count is wrong", 4, data.getRowCount());
    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]);
    assertTrue("result set is not peekable", data instanceof IPeekable);
    IPeekable peekable = (IPeekable) data;
    Object[] row = peekable.peek();
    assertEquals("Everyday Italian", row[0]);
    assertEquals("Giada De Laurentiis", row[1]);
    assertEquals("2005", row[2]);
    assertEquals("30.00", row[3]);
    row = peekable.peek();
    assertEquals("Everyday Italian", row[0]);
    row = peekable.peek();
    assertEquals("Everyday Italian", row[0]);
    row = peekable.peek();
    assertEquals("Everyday Italian", row[0]);
    row = data.next();
    assertEquals("Everyday Italian", row[0]);
    assertEquals("Giada De Laurentiis", row[1]);
    assertEquals("2005", row[2]);
    assertEquals("30.00", row[3]);
    row = peekable.peek();
    assertEquals("Harry Potter", row[0]);
    assertEquals("J K. Rowling", row[1]);
    assertEquals("2005", row[2]);
    assertEquals("29.99", row[3]);
    row = peekable.peek();
    assertEquals("Harry Potter", row[0]);
    assertEquals("J K. Rowling", row[1]);
    assertEquals("2005", row[2]);
    assertEquals("29.99", row[3]);
    row = data.next();
    assertEquals("Harry Potter", row[0]);
    assertEquals("J K. Rowling", row[1]);
    assertEquals("2005", row[2]);
    assertEquals("29.99", row[3]);
    row = peekable.peek();
    assertNotNull(row);
    row = data.next();
    assertNotNull(row);
    row = peekable.peek();
    assertNotNull(row);
    row = data.next();
    assertNotNull(row);
    row = peekable.peek();
    assertNull(row);
    row = data.next();
    assertNull(row);
    row = peekable.peek();
    assertNull(row);
}
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) IPeekable(org.pentaho.commons.connection.IPeekable)

Example 3 with XQResultSet

use of org.pentaho.platform.plugin.services.connections.xquery.XQResultSet 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)

Aggregations

IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)3 XQConnection (org.pentaho.platform.plugin.services.connections.xquery.XQConnection)3 XQResultSet (org.pentaho.platform.plugin.services.connections.xquery.XQResultSet)3 IPeekable (org.pentaho.commons.connection.IPeekable)1