modrian

           以前一直是用MS Anylize Service的,最近要做的項(xiàng)目是java的,小項(xiàng)目預(yù)算有限,所以想找一個(gè)開源的java的數(shù)據(jù)倉庫解決方案來用用。

            在網(wǎng)上查了一下,發(fā)現(xiàn)了Mondrian。Mondrian是基于JAVA的數(shù)據(jù)倉庫引擎,可以集成到web項(xiàng)目中,這一點(diǎn)最吸引我。另外與他搭配的表現(xiàn)層的方案也有不少選擇,Jpivot是元老,pentaho,openi看起來是后起之秀。不管怎樣,還是先研究一下modrian吧

            網(wǎng)上的中文資源比較少,在csdn上找了一下,只發(fā)現(xiàn)了兩篇比較有用的

          http://dev.csdn.net/develop/article/31/31791.shtm   Mondrian——有影響的“藝術(shù)家”     選擇自 kswaking 的 Blog

          http://dev.csdn.net/develop/article/68/68661.shtm  窮人的通用OLAP方案III--JPivot表現(xiàn)層     選擇自 calvinxiu 的 Blog

          照著做了一下,發(fā)現(xiàn)了一些問題,也有了一些心得。

          一.環(huán)境準(zhǔn)備

          1.1 首先介紹一下環(huán)境

          操作系統(tǒng):Linux

          服務(wù)器:Tomcat 5.5

          數(shù)據(jù)庫:MySQL 5.0.21

          1.2 下載程序。Mondrian在http://mondrian.sourceforge.net 可以下載,最早他是用MS Analyze Service的教程中FoodMart數(shù)據(jù)庫作為demo的,那個(gè)是access的數(shù)據(jù)庫。還好現(xiàn)在他有了Platform-Independent的版本,我就下載了那個(gè)mondrian-2.1.1-derby.zip 解壓縮之后在lib目錄里面有一個(gè)mondrian-embedded.war,把這個(gè)直接放到tomcat的webapps目錄里面就能夠看到mondrian的demo了。不過后面的測(cè)試,我把這個(gè)war解開之后放到webapps里面去,并且目錄把名字改短了點(diǎn)mondrian。啟動(dòng)tomcat,在瀏覽器輸入http://localhost/mondiran 看到了demo。需要說明一下的是,mondrian的發(fā)布包含了Jpivot,用它來做展示層,所以不用再去單獨(dú)下載Jpivot了。

          1.3 數(shù)據(jù)庫建表,在MySQL數(shù)據(jù)庫里面建立table,借用了kswaking的數(shù)據(jù)庫結(jié)構(gòu)

          在這個(gè)tiny的系統(tǒng)中,數(shù)據(jù)庫有3個(gè)表tb_employee(職員表),tb_time(時(shí)間表),tb_salary(薪酬表)。表結(jié)構(gòu)如下:

          drop table tb_employee;

          create table tb_employee

          (

               employee_id     number,             --職員id    

               employee_name   varchar2(10)        --職員姓名

          );

           

          drop table tb_time;

          create table tb_time

          (

              time_id   number,        --時(shí)間id

              the_year char(4),       --

              the_month char(2)        --

          );

           

          drop table tb_salary;

          create table tb_salary

          (

              employee_id number,                --職員id   

              time_id      number,                --時(shí)間id

              salary       number(19,4)           --薪酬

          );

           

          當(dāng)然,為了使系統(tǒng)能夠運(yùn)行,還需要讀者向數(shù)據(jù)庫表中插入一些數(shù)據(jù)。

          二. mondrian測(cè)試

            需要說明的是mondrian使用了MS一樣的MDX語言實(shí)現(xiàn)查詢,這對(duì)于從MS Analyze Services入門的人真是一個(gè)好消息。

          2.1 先編寫schema。

          <?xml version="1.0"?>
            <Schema name="Mondrian">
              <Cube name="CubeTest">
              <Table name="tb_salary"/>

              <Dimension name="Employee" foreignKey="employee_id">
                <Hierarchy hasAll="true" primaryKey="employee_id">
                  <Table name="tb_employee"/>
                  <Level name="employeeID" column="employee_id" uniqueMembers="true">
                     <Property name="employeeName" column="employee_name"/>
                 </Level>
                 </Hierarchy>
              </Dimension>

              <Dimension name="Time" foreignKey="time_id">
                <Hierarchy hasAll="false" primaryKey="time_id">
                  <Table name="tb_time"/>
                  <Level name="year" column="the_year" uniqueMembers="false"/> 
                  <Level name="month" column="the_month" uniqueMembers="false"/>
                </Hierarchy>
              </Dimension>

              <Measure name="Salary" column="salary" aggregator="sum"/>

            </Cube>
          </Schema>

          這個(gè)schema定義了一個(gè)cube,包含兩個(gè)Dimension和一個(gè)Measure。很容易看懂,就不解釋了。
          文件路徑為webapps/mondrian/WEB-INF/queries/mondriantest.xml。

          為了后面的測(cè)試方便,我把文件放到了queries目錄里面。

          因?yàn)橛肕ySQL建表的時(shí)候都用小寫的,所以schema里面的字段名也都用了小寫(我一開始也使用大寫的,結(jié)果出錯(cuò),找不到字段),calvinxiu的文章說如果是Oracle數(shù)據(jù)庫,這里的字段要用大寫。

           

           

          2.2 編寫JSP

           

          <%@ page import="mondrian.olap.*"%>
          <%
            Connection connection = DriverManager.getConnection("Provider=mondrian; Jdbc=jdbc:mysql://localhost/mondrian; JdbcUser=root; JdbcPassword=; Catalog=file:///usr/local/apache-tomcat-5.5.12/webapps/mondrian/WEB-INF/queries/mondriantest.xml; JdbcDriver=com.mysql.jdbc.Driver", null, false);

            String querystr = " select {[Measures].[Salary]} ON COLUMNS, {[Employee].[employeeId].Members} ON ROWS from CubeTest ";

            Query query=connection.parseQuery(querystr);
            Result result = connection.execute(query);
            out.println("get result");
          %>

          可以看到mondrian也使用jdbc來連接數(shù)據(jù)庫的,其中要特別注意的是Catalog指名了schema的位置。

           

          文件路徑webapps/mondrian/mondriantestmdx.jsp

           

          2.3 測(cè)試

          在瀏覽器輸入http://localhost/mondrian/mondriantestmdx.jsp 可以看到顯示的結(jié)果 get result,說明一切正常。

           

           

          到目前為止,我們只測(cè)試了Mondrian,它只負(fù)責(zé)數(shù)據(jù)的提取和組織,所以在畫面上沒有看到任何的數(shù)據(jù),下一篇文章將繼續(xù)研究數(shù)據(jù)的展現(xiàn) - Jpivot。

          posted on 2007-05-17 18:33 leoli 閱讀(519) 評(píng)論(0)  編輯  收藏 所屬分類: java

          導(dǎo)航

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          統(tǒng)計(jì)

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案(17)

          文章分類(86)

          收藏夾(3)

          flex blog

          good site

          java blog

          my friend

          tools

          抓蝦

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 洛南县| 砚山县| 海宁市| 佛教| 洪湖市| 昌吉市| 南昌县| 江安县| 靖边县| 张家川| 甘孜| 中西区| 定边县| 汉阴县| 乌鲁木齐县| 烟台市| 萝北县| 高雄县| 凯里市| 无为县| 寻甸| 丹江口市| 松江区| 晋宁县| 正蓝旗| 大方县| 巴马| 道孚县| 繁峙县| 栾川县| 湄潭县| 广平县| 温州市| 莱阳市| 达州市| 剑川县| 洛南县| 祁连县| 青河县| 白河县| 会泽县|