mondrian 源码解读(一)-部署mondrian项目

mondrian是什么?

mondrian是一款基于java的开源的多维分析olap服务器。更多资料请移步mondrian官方网站:http://community.pentaho.com/projects/mondrian/。

如何部署mondrian?

在mondrian官方文档中,已经有详细的步骤了,请移步:http://mondrian.pentaho.com/documentation/developers_guide.php

可能部署的时候会有点问题,我将我遇到的问题分享给大家:

一,构建mondrian

将源码下载下来后,使用ant构建时,可能有些jar包下载不下来,大家就翻墙吧。

二,安装数据库

直接使用Access数据库最简单,只需要使用access连接MondrianFoodMart.mdb文件就可以了。但是access的sql查询工具太不好用了(也有可能是我不会使),后面我就换成oracle数据库了。

使用oracle数据库的时候要注意,由于在执行FoodMartLoader.bat的时候出错了,查了下他依赖的包并不完整,需要自己手动添加依赖包,并且构建mondrian.jar的时候需要将test文件夹也构建进去。现将我的依赖配置贴出来。

rem example script for MondrianFoodMartLoader

@echo on
set CP=E:\code\github\mondrian\lib\ommons-dbcp.jar;..E:\code\github\mondrian\lib\commons-collections.jar;
set CP=%CP%;E:\code\github\mondrian\lib\commons-pool.jar
set CP=%CP%;E:\code\github\mondrian\lib\eigenbase-properties.jar;E:\code\github\mondrian\lib\eigenbase-resgen.jar;E:\code\github\mondrian\lib\eigenbase-xom.jar
set CP=%CP%;E:\code\github\mondrian\lib\javacup.jar;
set CP=%CP%;E:\code\github\mondrian\lib\olap4j.jar;
set CP=%CP%;E:\code\github\mondrian\lib\commons-logging.jar;
set CP=%CP%;E:\code\github\mondrian\test-lib\test.jar
set CP=%CP%;E:\code\github\mondrian\test-lib\mondrian.jar
set CP=%CP%;E:\code\github\mondrian\lib\log4j.jar
set CP=%CP%;E:\code\github\mondrian\test-lib\ojdbc-14.jar




java -Xms100m -Xmx500m -cp "%CP%" mondrian.test.loader.MondrianFoodMartLoader -tables -data -indexes -inputFile="E:\code\github\mondrian\demo\FoodMartCreateData.sql" -jdbcDrivers=oracle.jdbc.OracleDriver -outputJdbcURL="jdbc:oracle:thin:@172.16.101.128:1521:visu" -outputJdbcUser=mondrian -outputJdbcPassword=mondrian

三,运行测试用例提示找不到MondrianResource

由于本地环境是中文的,没有构建中文resource,所有我在下图中加了一个文件MondrianResource_zh_CN,并修改了一个地方MondrianResource.xml。

//MondrianResource_zh_CN 源代码
public class MondrianResource_zh_CN extends MondrianResource{
    public MondrianResource_zh_CN() throws IOException {
    }
}

四,运行时没有打印sql日志

将mondrian跟目录下的log4j.properties和log4j.xml放到src目录下,并修改你想要的输出级别即可。

开始探索mondrian源码

到现在已经成功部署了mondrian源码,运行BasicQueryTest的测试用例,查看mondrian是如何运作的。将RolapUtil.executeQuery() 方法加上断点,你就可以查看mondrian执行的每一条sql了。