embedding_mondrian.html
来自「基于mondrian 开源框架进行OLAP多维分析」· HTML 代码 · 共 141 行
HTML
141 行
<html><!-- == $Id: //open/mondrian-release/3.0/doc/embedding_mondrian.html#2 $ == This software is subject to the terms of the Common Public License == Agreement, available at the following URL: == http://www.opensource.org/licenses/cpl.html. == Copyright (C) 2005-2007 Julian Hyde == All Rights Reserved. == You must accept the terms of that agreement to use this software. --><head> <link rel="stylesheet" type="text/css" href="stylesheet.css"/> <title>Pentaho Analysis Services: Embedding Mondrian</title></head><body><!-- doc2web start --><!-- page title --><div class="contentheading">Embedding Mondrian in a Java Application</div><!-- end page title --><p>By Will Gorman; last updated April, 2007.</p><hr noshade size="1"><p>This document shows a simple example of embedding mondrian in a java application. The steps include downloading Mondrian, installing a database, writing a simple application, compiling the application, and running the application. </p><h2>Setting up the Environment<a name="setting_up_the_environment"> </a></h2><p>First, you need to download mondrian. You can get the latest releasefrom SourceForge.</p><h3>Download the Latest Release<a name="Download_the_latest_source_release"> </a></h3><p>Download the latest <code>mondrian-<i>version</i>.zip</code> from <a href="http://sourceforge.net/projects/mondrian">SourceForge</a>, and unzip. Now find the <code>mondrian-<i>version</i>-src.zip</code> inside this distribution, and unzip it within the mondrian binary distribution under the "src" directory.</p><h2>Installing the Database<a name="installing_the_database"> </a></h2><p>Before you run this simple example, you must install the standard FoodMart dataset. This is described in the<a href="install.html#2_Set_up_test_data">installation guide</a>.</p><h2>The Source Code<a name="the_source_code"> </a></h2><p>Here is a simple example of embedding mondrian in a java class. A connection is retrieved, a query is generated and finally the query is executed. Open the file SimpleEmbeddedExample.java in the main Mondrian directory and paste the contents below.</p><blockquote><code>import mondrian.olap.*;<br>import java.io.*;<br><br>public class SimpleEmbeddedExample {<br><br> public static void main(String args[]) {<br><br> // First, set up a valid connection string<br> String connStr = "Provider=mondrian;" +<br> "Catalog=demo/FoodMart.xml;" +<br> "JdbcDrivers=com.mysql.jdbc.Driver;" +<br> "Jdbc=jdbc:mysql://localhost/foodmart?user=foodmart&password=foodmart;" +<br> "jdbcUser=foodmart;" +<br> "jdbcPassword=foodmart";<br><br> // Second, set up a valid query string<br> String queryStr = "select " +<br> "{[Measures].[Unit Sales]} on columns, " +<br> "{[Store].[All Stores]} on rows " +<br> "from [Sales]";<br><br> // Third, retrieve a connection from the DriveManager<br> Connection connection = DriverManager.getConnection(connStr, null, true);<br><br> // Fourth, generate a MDX Query object<br> Query query = connection.parseQuery(queryStr);<br><br> // Fifth, execute the query<br> Result result = connection.execute(query);<br><br> // Finally, print out the result<br> StringWriter sw = new StringWriter();<br> PrintWriter pw = new PrintWriter(sw);<br> result.print(pw);<br> pw.flush();<br> System.out.println(sw.toString());<br> }<br><br>}<br><br></code></blockquote><p>Note that you should replace the specific jdbc information with your own JDBC connection properties.</p><h2>Compiling the Example <a name="compiling_the_example"> </a></h2><p>To compile this example via the command line:</p><blockquote><code>javac -cp "lib/mondrian.jar" SimpleEmbeddedExample.java</code></blockquote><h2>Running the Example <a name="compiling the example"> </a></h2><p>Below is the java command line that will execute the SimpleEmbeddedExample class. Note that you must replace $JDBC_DRIVER_JAR_LOCATION with the correct path to your specific JDBC driver.</p><blockquote><code>java -cp ".:src/lib/log4j-1.2.9.jar:src/lib/commons-dbcp.jar:src/lib/commons-pool.jar:src/lib/commons-collections.jar<br>:src/lib/commons-vfs.jar:src/lib/commons-logging.jar:src/lib/commons-math-1.0.jar:src/lib/javacup.jar<br>:src/lib/eigenbase-resgen.jar:src/lib/eigenbase-properties.jar:src/lib/eigenbase-xom.jar:lib/mondrian.jar<br>:$JDBC_DRIVER_JAR_LOCATION" SimpleEmbeddedExample</code></blockquote><p> You should see this output:</p><blockquote><code>log4j:WARN No appenders could be found for logger (mondrian.olap.MondrianProperties).<br>log4j:WARN Please initialize the log4j system properly.<br>Axis #0:<br>{}<br>Axis #1:<br>{[Measures].[Unit Sales]}<br>Axis #2:<br>{[Store].[All Stores]}<br>Row #0: 266,773<br></code></blockquote><p>View <a href="api/mondrian/olap/Result.html">Mondrian's API</a> for more details on traversing the Result object.</p><hr noshade size="1"/><p> Author: Will Gorman; last updated April, 2007.<br/> Version: $Id: //open/mondrian-release/3.0/doc/embedding_mondrian.html#2 $ (<a href="http://p4web.eigenbase.org/open/mondrian/doc/embedding_mondrian.html?ac=1">log </a>)<br/> Copyright (C) 2005-2007 Julian Hyde</p><br /><!-- doc2web end --></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?