在pentaho 5.2中获得olap4j连接的例外情况

时间:2015-03-04 16:56:49

标签: java spring pentaho mondrian olap4j

我有两个Pentaho插件。在GWT中制作的一个在5.0-5.2中工作并返回我需要的所有尺寸。现在我需要重构而不用gwt。我将连接代码放在我的新REST服务中,代码在pentaho 5.0中运行良好但在5.2中失败。我相信问题不在代码中,但我试图理解为什么如果在gwt服务中运行良好,它会失败。

    MondrianProperties pr = MondrianProperties.instance();

    // Customize Mondrian to get connection
    pr.setProperty("mondrian.rolap.ignoreInvalidMembers", "true");
    pr.setProperty("mondrian.rolap.ignoreInvalidMembersDuringQuery", "true");
    pr.DataSourceResolverClass.setString("org.pentaho.platform.web.servlet.PentahoDataSourceResolver");

    Properties props = MondrianPropertyLoader.loadProperties();
    for(String property: props.stringPropertyNames()) {
        pr.setProperty(property, props.getProperty(property));
    }

    url = "jdbc:mondrian:Catalog=" + catalogDefinition + ";Datasource=" + dataSource; // + props;
    Class.forName("mondrian.olap4j.MondrianOlap4jDriver");

    // In Pentaho 5.2 RESTService fail
    // ---------------------------------
    OlapConnection connection = (OlapConnection) DriverManager.getConnection(url, "", "");
    // ---------------------------------

    final OlapWrapper wrapper = connection;
    OlapConnection tmpolapConnectionStx = (OlapConnection) wrapper.unwrap(OlapConnection.class);
    olapConnection = tmpolapConnectionStx;

    //Roles stuff
    setRoles(connection.getAvailableRoleNames());

    connection = null;
    Class.forName("mondrian.olap4j.MondrianOlap4jDriver");

    url += ";Role=" + getStringRoles();
    connection = (OlapConnection) DriverManager.getConnection(url, "", "");
    final OlapWrapper wrapper2 = connection;
    tmpolapConnectionStx = null;
    tmpolapConnectionStx = (OlapConnection) wrapper2.unwrap(OlapConnection.class);
    if (tmpolapConnectionStx == null) {
        throw new Exception("Connection is null");
    }
    olapConnection = tmpolapConnectionStx;
    this.initialized = true;

以前的代码对于两者都是相同的,但Pentaho 5.2中的新服务就行了

OlapConnection connection =(OlapConnection)DriverManager.getConnection ...

失败并使用此网址抛出以下异常

JDBC:蒙德里安:目录=蒙德里安:/的sampleData;数据源=的sampleData;提供者:蒙德里安; EnableXmla:假

JDBC:蒙德里安:目录=蒙德里安:/的sampleData;数据源=的sampleData

ERROR [PentahoDataSourceResolver] PentahoXmlaServlet.ERROR_0002 - IDatasourceService.UNABLE_TO_INSTANTIATE_OBJECT
org.pentaho.platform.api.data.DBDatasourceServiceException: DatasourceService.ERROR_0003 - Unable to get jndi datasource
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.NonPooledOrJndiDatasourceService.retrieve(NonPooledOrJndiDatasourceService.java:69)
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.BaseDatasourceService.getDataSource(BaseDatasourceService.java:69)
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.DynamicallyPooledOrJndiDatasourceService.resolveDatabaseConnection(DynamicallyPooledOrJndiDatasourceService.java:37)
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.NonPooledOrJndiDatasourceService.retrieve(NonPooledOrJndiDatasourceService.java:51)
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.BaseDatasourceService.getDataSource(BaseDatasourceService.java:69)
    at org.pentaho.platform.web.servlet.PentahoDataSourceResolver.lookup(PentahoDataSourceResolver.java:43)
    at mondrian.rolap.RolapConnection.createDataSource(RolapConnection.java:429)
    at mondrian.rolap.RolapConnection.<init>(RolapConnection.java:135)
    at mondrian.rolap.RolapConnection.<init>(RolapConnection.java:91)
    at mondrian.olap.DriverManager.getConnection(DriverManager.java:113)
    at mondrian.olap.DriverManager.getConnection(DriverManager.java:69)
    at mondrian.olap4j.MondrianOlap4jConnection.<init>(MondrianOlap4jConnection.java:157)
    at mondrian.olap4j.FactoryJdbc4Plus$AbstractConnection.<init>(FactoryJdbc4Plus.java:323)
    at mondrian.olap4j.FactoryJdbc41Impl$MondrianOlap4jConnectionJdbc41.<init>(FactoryJdbc41Impl.java:118)
    at mondrian.olap4j.FactoryJdbc41Impl.newConnection(FactoryJdbc41Impl.java:32)
    at mondrian.olap4j.MondrianOlap4jDriver.connect(MondrianOlap4jDriver.java:134)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at com.olaphelper.provider.HelperConnection.connect(HelperConnection.java:101)
    at com.olaphelper.provider.HelperConnection.isConnected(HelperConnection.java:55)
    at com.olaphelper.api.rest.OlapResources.getCubeDimensions(OlapResources.java:98)
    at com.olaphelper.api.rest.OlapResources$$FastClassByCGLIB$$767f2eeb.invoke(<generated>)
    . . .
Caused by: org.pentaho.platform.api.data.DBDatasourceServiceException: javax.naming.NameNotFoundException: El nombre SampleData no este asociado a este contexto
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.PooledDatasourceHelper.getJndiDataSource(PooledDatasourceHelper.java:378)
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.BaseDatasourceService.getJndiDataSource(BaseDatasourceService.java:99)
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.NonPooledOrJndiDatasourceService.retrieve(NonPooledOrJndiDatasourceService.java:67)
    ... 108 more
Caused by: javax.naming.NameNotFoundException: El nombre SampleData no este asociado a este contexto
    at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.PooledDatasourceHelper.getJndiDataSource(PooledDatasourceHelper.java:339)
    ... 110 more
mondrian.olap.MondrianException: Mondrian Error:Internal error: Error while looking up data source (SampleData)
    at mondrian.resource.MondrianResource$_Def0.ex(MondrianResource.java:977)
    at mondrian.olap.Util.newInternal(Util.java:2404)
    at mondrian.rolap.RolapConnection.createDataSource(RolapConnection.java:431)
    at mondrian.rolap.RolapConnection.<init>(RolapConnection.java:135)
    at mondrian.rolap.RolapConnection.<init>(RolapConnection.java:91)
    at mondrian.olap.DriverManager.getConnection(DriverManager.java:113)
    at mondrian.olap.DriverManager.getConnection(DriverManager.java:69)
    at mondrian.olap4j.MondrianOlap4jConnection.<init>(MondrianOlap4jConnection.java:157)
    at mondrian.olap4j.FactoryJdbc4Plus$AbstractConnection.<init>(FactoryJdbc4Plus.java:323)
    at mondrian.olap4j.FactoryJdbc41Impl$MondrianOlap4jConnectionJdbc41.<init>(FactoryJdbc41Impl.java:118)
    at mondrian.olap4j.FactoryJdbc41Impl.newConnection(FactoryJdbc41Impl.java:32)
    at mondrian.olap4j.MondrianOlap4jDriver.connect(MondrianOlap4jDriver.java:134)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at com.olaphelper.provider.HelperConnection.connect(HelperConnection.java:101)
    at com.olaphelper.provider.HelperConnection.isConnected(HelperConnection.java:55)
    at com.olaphelper.api.rest.OlapResources.getCubeDimensions(OlapResources.java:98)
    at com.olaphelper.api.rest.OlapResources$$FastClassByCGLIB$$767f2eeb.invoke(<generated>)
    . . .
Caused by: org.pentaho.platform.api.data.DBDatasourceServiceException: DatasourceService.ERROR_0003 - Unable to get jndi datasource
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.NonPooledOrJndiDatasourceService.retrieve(NonPooledOrJndiDatasourceService.java:69)
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.BaseDatasourceService.getDataSource(BaseDatasourceService.java:69)
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.DynamicallyPooledOrJndiDatasourceService.resolveDatabaseConnection(DynamicallyPooledOrJndiDatasourceService.java:37)
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.NonPooledOrJndiDatasourceService.retrieve(NonPooledOrJndiDatasourceService.java:51)
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.BaseDatasourceService.getDataSource(BaseDatasourceService.java:69)
    at org.pentaho.platform.web.servlet.PentahoDataSourceResolver.lookup(PentahoDataSourceResolver.java:43)
    at mondrian.rolap.RolapConnection.createDataSource(RolapConnection.java:429)
    ... 102 more
Caused by: org.pentaho.platform.api.data.DBDatasourceServiceException: javax.naming.NameNotFoundException: El nombre SampleData no este asociado a este contexto
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.PooledDatasourceHelper.getJndiDataSource(PooledDatasourceHelper.java:378)
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.BaseDatasourceService.getJndiDataSource(BaseDatasourceService.java:99)
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.NonPooledOrJndiDatasourceService.retrieve(NonPooledOrJndiDatasourceService.java:67)
    ... 108 more
Caused by: javax.naming.NameNotFoundException: El nombre SampleData no este asociado a este contexto
    at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.PooledDatasourceHelper.getJndiDataSource(PooledDatasourceHelper.java:339)
    ... 110 more

两个插件都是相同的pentaho并且具有相同的mondrian属性,所以我不明白它为什么会发生。

2 个答案:

答案 0 :(得分:1)

最近我查看了我的旧代码并删除了plugin.spring.xml中我不需要的一些代码,我的插件工作没有错误。

产生问题的行是以下

<context:property-placeholder location="config/jdbc.properties"/>
<!-- import rest="lib/hibernate.cfg.xml"/ -->

<bean id="dataSource"
      class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close"
      p:driverClassName="${jdbc.driverClassName}"
      p:url="${jdbc.url}"
      p:username="${jdbc.username}"
      p:password="${jdbc.password}"
      p:maxActive="${dbcp.maxActive}"
      p:maxIdle="${dbcp.maxIdle}"
      p:maxWait="${dbcp.maxWait}"
        />

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
      p:dataSource-ref="dataSource"
      p:configurationClass="org.hibernate.cfg.AnnotationConfiguration"
      p:packagesToScan="com.stratebi.stx.console.model">

    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
            <prop key="hibernate.hbm2ddl.auto">${schema.generation}</prop>
            <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
            <prop key="hibernate.connection.url">${jdbc.url}</prop>
            <prop key="hibernate.connection.driver_class">${jdbc.driverClassName}</prop>
            <prop key="hibernate.connection.username">${jdbc.username}</prop>
            <prop key="hibernate.connection.password">${jdbc.password}</prop>
        </props>
    </property>

    <!--property name="annotatedPackages" value="com.stratebi.stx.console" />
    <property name="configLocation" value="config/hibernate.cfg.xml" / -->

    <property name="eventListeners">
        <map>
            <entry key="merge">
                <bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>
            </entry>
        </map>
    </property>
    <property name="annotatedClasses">
        <list>

        </list>
    </property>

</bean>

<tx:annotation-driven transaction-manager="txnManager"/>

<!-- Hibernate transaction manager -->
<bean id="txnManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager"
      p:sessionFactory-ref="sessionFactory"/>

但是我认为真正的问题是由事务管理器或者hibernate生成的,它与Pentaho自己的库发生了冲突,我需要稍后再查看,但是现在错误消失了。

答案 1 :(得分:0)

您正在私人&#39;内创建自己的蒙德里安实例。 classloader空间。似乎它无法正确解析JNDI连接。

尝试更简单的方法并查看Pentaho平台中的IOlapService。