Search in sources :

Example 1 with OlapWrapper

use of org.olap4j.OlapWrapper in project pentaho-kettle by pentaho.

the class OlapHelper method openQuery.

public void openQuery() throws Exception {
    Class.forName(olap4jDriver);
    OlapConnection connection = null;
    if (Utils.isEmpty(username) && Utils.isEmpty(password)) {
        connection = (OlapConnection) DriverManager.getConnection(olap4jUrl);
    } else {
        connection = (OlapConnection) DriverManager.getConnection(olap4jUrl, username, password);
    }
    OlapWrapper wrapper = connection;
    olapConnection = wrapper.unwrap(OlapConnection.class);
    try {
        if (!Utils.isEmpty(catalogName)) {
            olapConnection.setCatalog(catalogName);
        }
    } catch (SQLException e) {
        throw new OlapException("Error setting catalog for MDX statement: '" + catalogName + "'");
    }
    OlapStatement stmt = olapConnection.createStatement();
    if (!Utils.isEmpty(mdx)) {
        CellSet tmp = stmt.executeOlapQuery(mdx);
        result = tmp;
    } else {
        throw new Exception("Error executing empty MDX query");
    }
}
Also used : OlapStatement(org.olap4j.OlapStatement) OlapWrapper(org.olap4j.OlapWrapper) SQLException(java.sql.SQLException) OlapConnection(org.olap4j.OlapConnection) OlapException(org.olap4j.OlapException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) OlapException(org.olap4j.OlapException) CellSet(org.olap4j.CellSet)

Example 2 with OlapWrapper

use of org.olap4j.OlapWrapper in project mondrian by pentaho.

the class FileRepository method getConnection.

OlapConnection getConnection(CatalogInfo catalogInfo, MondrianServer server, String roleName, Properties props) throws SQLException {
    String connectString = catalogInfo.olap4jConnectString;
    // Save the server for the duration of the call to 'getConnection'.
    final LockBox.Entry entry = MondrianServerRegistry.INSTANCE.lockBox.register(server);
    final Properties properties = new Properties();
    properties.setProperty(RolapConnectionProperties.Instance.name(), entry.getMoniker());
    if (roleName != null) {
        properties.setProperty(RolapConnectionProperties.Role.name(), roleName);
    }
    properties.putAll(props);
    // the ClassLoader.
    try {
        ClassResolver.INSTANCE.forName(MondrianOlap4jDriver.class.getName(), true);
    } catch (ClassNotFoundException e) {
        throw new OlapException("Cannot find mondrian olap4j driver.");
    }
    final java.sql.Connection connection = java.sql.DriverManager.getConnection(connectString, properties);
    return ((OlapWrapper) connection).unwrap(OlapConnection.class);
}
Also used : MondrianOlap4jDriver(mondrian.olap4j.MondrianOlap4jDriver) OlapWrapper(org.olap4j.OlapWrapper) LockBox(mondrian.util.LockBox) OlapException(org.olap4j.OlapException) RolapConnectionProperties(mondrian.rolap.RolapConnectionProperties) MondrianProperties(mondrian.olap.MondrianProperties) Properties(java.util.Properties)

Example 3 with OlapWrapper

use of org.olap4j.OlapWrapper in project teiid by teiid.

the class OlapExecutionFactory method unwrap.

private OlapConnection unwrap(Connection conn) throws TranslatorException {
    try {
        OlapWrapper wrapper = conn.unwrap(OlapWrapper.class);
        OlapConnection olapConn = wrapper.unwrap(OlapConnection.class);
        return olapConn;
    } catch (SQLException e) {
        throw new TranslatorException(e);
    }
}
Also used : OlapWrapper(org.olap4j.OlapWrapper) SQLException(java.sql.SQLException) OlapConnection(org.olap4j.OlapConnection) TranslatorException(org.teiid.translator.TranslatorException)

Example 4 with OlapWrapper

use of org.olap4j.OlapWrapper 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)

Aggregations

OlapWrapper (org.olap4j.OlapWrapper)4 OlapConnection (org.olap4j.OlapConnection)3 SQLException (java.sql.SQLException)2 OlapException (org.olap4j.OlapException)2 OlapStatement (org.olap4j.OlapStatement)2 Connection (java.sql.Connection)1 Properties (java.util.Properties)1 MondrianProperties (mondrian.olap.MondrianProperties)1 MondrianOlap4jDriver (mondrian.olap4j.MondrianOlap4jDriver)1 RolapConnectionProperties (mondrian.rolap.RolapConnectionProperties)1 LockBox (mondrian.util.LockBox)1 Test (org.junit.Test)1 CellSet (org.olap4j.CellSet)1 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)1 CommandBuilder (org.teiid.cdk.CommandBuilder)1 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)1 RuntimeMetadataImpl (org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl)1 Command (org.teiid.language.Command)1 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)1 ExecutionContext (org.teiid.translator.ExecutionContext)1