use of org.olap4j.OlapConnection in project teiid by teiid.
the class TestOlapTranslator method testCannedProcedure.
@Test
public void testCannedProcedure() throws Exception {
String ddl = "create foreign procedure proc(arg integer, arg1 date) returns table (x string) options (\"teiid_rel:native-query\" '$2 $1 something')";
String query = "exec proc(2, {d'1970-01-01'})";
TransformationMetadata tm = RealMetadataFactory.fromDDL(ddl, "x", "phy");
CommandBuilder commandBuilder = new CommandBuilder(tm);
Command obj = commandBuilder.getCommand(query);
OlapExecutionFactory oef = new OlapExecutionFactory();
Connection mock = Mockito.mock(java.sql.Connection.class);
OlapWrapper mock2 = Mockito.mock(OlapWrapper.class);
OlapConnection mock3 = Mockito.mock(OlapConnection.class);
OlapStatement mock4 = Mockito.mock(OlapStatement.class);
Mockito.stub(mock4.executeOlapQuery(Mockito.anyString())).toThrow(new TeiidRuntimeException());
Mockito.stub(mock3.createStatement()).toReturn(mock4);
Mockito.stub(mock2.unwrap(OlapConnection.class)).toReturn(mock3);
Mockito.stub(mock.unwrap(OlapWrapper.class)).toReturn(mock2);
ProcedureExecution pe = oef.createProcedureExecution((Call) obj, Mockito.mock(ExecutionContext.class), new RuntimeMetadataImpl(tm), mock);
try {
pe.execute();
fail();
} catch (TeiidRuntimeException e) {
Mockito.verify(mock4).executeOlapQuery("'1970-01-01' 2 something");
}
}
use of org.olap4j.OlapConnection in project bamboobsc by billchen198318.
the class Pivot4JUtils method exportExcelFile.
public static File exportExcelFile(String mondrianUrl, String mdx, boolean showDimensionTitle, boolean showParentMembers) throws Exception {
if (StringUtils.isBlank(mondrianUrl) || StringUtils.isBlank(mdx)) {
throw new java.lang.IllegalArgumentException("mondrian url and MDX cannot blank.");
}
File file = new File(Constants.getWorkTmpDir() + "/" + SimpleUtils.getUUIDStr() + ".xlsx");
OutputStream os = new FileOutputStream(file);
OlapConnection connection = OlapUtils.getConnection(mondrianUrl);
OlapDataSource dataSource = new SingleConnectionOlapDataSource(connection);
try {
PivotModel model = getPivotModel(dataSource, mdx);
TableRenderer renderer = getTableRenderer(showDimensionTitle, showParentMembers);
ExcelExporter exporter = new ExcelExporter(os);
exporter.setFormat(Format.XSSF);
renderer.render(model, exporter);
} catch (Exception e) {
file = null;
throw e;
} finally {
if (os != null) {
IOUtils.closeQuietly(os);
os = null;
}
OlapUtils.nullConnection(connection);
connection = null;
dataSource = null;
}
return file;
}
use of org.olap4j.OlapConnection in project bamboobsc by billchen198318.
the class OlapUtils method getConnection.
/**
* 取出連線
*
* @param driver
* @param url
* @return
* @throws ClassNotFoundException
* @throws SQLException
*/
public static OlapConnection getConnection(String driver, String url) throws ClassNotFoundException, SQLException, Exception {
Class.forName(driver);
Connection connection = DriverManager.getConnection(url);
return connection.unwrap(OlapConnection.class);
}
use of org.olap4j.OlapConnection in project bamboobsc by billchen198318.
the class Pivot4JUtils method rendererHtml.
public static String rendererHtml(String mondrianUrl, String mdx, boolean showDimensionTitle, boolean showParentMembers) throws Exception {
if (StringUtils.isBlank(mondrianUrl) || StringUtils.isBlank(mdx)) {
throw new java.lang.IllegalArgumentException("mondrian url and MDX cannot blank.");
}
String body = "";
OlapConnection connection = OlapUtils.getConnection(mondrianUrl);
OlapDataSource dataSource = new SingleConnectionOlapDataSource(connection);
try {
PivotModel model = getPivotModel(dataSource, mdx);
TableRenderer renderer = getTableRenderer(showDimensionTitle, showParentMembers);
StringWriter writer = new StringWriter();
renderer.render(model, new HtmlRenderCallback(writer));
//writer.write(body);
body = writer.toString();
writer.flush();
writer.close();
} catch (Exception e) {
throw e;
} finally {
OlapUtils.nullConnection(connection);
connection = null;
dataSource = null;
}
return body;
}
use of org.olap4j.OlapConnection in project mondrian by pentaho.
the class DrillThroughQuerySpecTest method testMdxQuery.
// test that returns correct number of columns
public void testMdxQuery() throws SQLException {
String drillThroughMdx = "DRILLTHROUGH WITH " + "SET [*NATIVE_CJ_SET_WITH_SLICER] AS 'NONEMPTYCROSSJOIN([*BASE_MEMBERS__Product_],[*BASE_MEMBERS__Store Type_])' " + "SET [*NATIVE_CJ_SET] AS 'GENERATE([*NATIVE_CJ_SET_WITH_SLICER], {([Product].CURRENTMEMBER)})' " + "SET [*BASE_MEMBERS__Store Type_] AS 'FILTER([Store Type].[Store Type].MEMBERS,[Store Type].CURRENTMEMBER " + "NOT IN {[Store Type].[All Store Types].[Small Grocery]})' " + "SET [*SORTED_ROW_AXIS] AS 'ORDER([*CJ_ROW_AXIS],[Product].CURRENTMEMBER.ORDERKEY,BASC,ANCESTOR([Product]" + ".CURRENTMEMBER,[Product].[Product Family]).ORDERKEY,BASC)' " + "SET [*BASE_MEMBERS__Measures_] AS '{[Measures].[Warehouse Cost]}' " + "SET [*CJ_SLICER_AXIS] AS 'GENERATE([*NATIVE_CJ_SET_WITH_SLICER], {([Store Type].CURRENTMEMBER)})' " + "SET [*BASE_MEMBERS__Product_] AS '[Product].[Product Department].MEMBERS' " + "SET [*CJ_ROW_AXIS] AS 'GENERATE([*NATIVE_CJ_SET], {([Product].CURRENTMEMBER)})' " + "SELECT " + "FILTER([*BASE_MEMBERS__Measures_],([Measures].CurrentMember Is [Measures].[Warehouse Cost])) ON COLUMNS " + ",FILTER([*SORTED_ROW_AXIS],([Product].CurrentMember Is [Product].[Drink].[Alcoholic Beverages])) ON ROWS " + "FROM [Warehouse] " + "WHERE ([*CJ_SLICER_AXIS]) " + "RETURN [Product].[Product Department]";
OlapConnection olap4jConnection = TestContext.instance().getOlap4jConnection();
ResultSet resultSet = olap4jConnection.createStatement().executeQuery(drillThroughMdx);
assertEquals(1, resultSet.getMetaData().getColumnCount());
assertEquals("product_department", resultSet.getMetaData().getColumnName(1));
}
Aggregations