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
}
}
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);
}
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();
}
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);
}
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;
}
Aggregations