Search in sources :

Example 6 with OlapConnection

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");
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) OlapConnection(org.olap4j.OlapConnection) Connection(java.sql.Connection) OlapConnection(org.olap4j.OlapConnection) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) OlapStatement(org.olap4j.OlapStatement) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) OlapWrapper(org.olap4j.OlapWrapper) ProcedureExecution(org.teiid.translator.ProcedureExecution) RuntimeMetadataImpl(org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 7 with OlapConnection

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;
}
Also used : TableRenderer(org.pivot4j.ui.table.TableRenderer) SingleConnectionOlapDataSource(org.pivot4j.datasource.SingleConnectionOlapDataSource) OlapDataSource(org.olap4j.OlapDataSource) PivotModel(org.pivot4j.PivotModel) ExcelExporter(org.pivot4j.ui.poi.ExcelExporter) OlapConnection(org.olap4j.OlapConnection) SingleConnectionOlapDataSource(org.pivot4j.datasource.SingleConnectionOlapDataSource) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) IOException(java.io.IOException)

Example 8 with OlapConnection

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);
}
Also used : Connection(java.sql.Connection) OlapConnection(org.olap4j.OlapConnection)

Example 9 with OlapConnection

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;
}
Also used : TableRenderer(org.pivot4j.ui.table.TableRenderer) SingleConnectionOlapDataSource(org.pivot4j.datasource.SingleConnectionOlapDataSource) OlapDataSource(org.olap4j.OlapDataSource) PivotModel(org.pivot4j.PivotModel) StringWriter(java.io.StringWriter) OlapConnection(org.olap4j.OlapConnection) SingleConnectionOlapDataSource(org.pivot4j.datasource.SingleConnectionOlapDataSource) HtmlRenderCallback(org.pivot4j.ui.html.HtmlRenderCallback) IOException(java.io.IOException)

Example 10 with OlapConnection

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));
}
Also used : OlapConnection(org.olap4j.OlapConnection) ResultSet(java.sql.ResultSet)

Aggregations

OlapConnection (org.olap4j.OlapConnection)22 SQLException (java.sql.SQLException)8 RolapConnection (mondrian.rolap.RolapConnection)5 OlapException (org.olap4j.OlapException)5 Properties (java.util.Properties)4 MondrianServer (mondrian.olap.MondrianServer)4 IOlapServiceException (org.pentaho.platform.plugin.action.olap.IOlapServiceException)4 PrintWriter (java.io.PrintWriter)3 Connection (java.sql.Connection)3 Test (org.junit.Test)3 OlapWrapper (org.olap4j.OlapWrapper)3 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)3 IOException (java.io.IOException)2 Connection (mondrian.olap.Connection)2 RolapConnectionProperties (mondrian.rolap.RolapConnectionProperties)2 UrlRepositoryContentFinder (mondrian.server.UrlRepositoryContentFinder)2 XmlaHandler (mondrian.xmla.XmlaHandler)2 XmlaTestContext (mondrian.xmla.test.XmlaTestContext)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 OlapDataSource (org.olap4j.OlapDataSource)2