01: /*
02: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
07: *
08: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
09: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
10: * the license for the specific language governing your rights and limitations.
11: *
12: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
13: */
14: package org.pentaho.reportdesigner.crm.report.tests.mondrian;
15:
16: import mondrian.olap.Axis;
17: import mondrian.olap.Connection;
18: import mondrian.olap.DriverManager;
19: import mondrian.olap.Member;
20: import mondrian.olap.Position;
21: import mondrian.olap.Query;
22: import mondrian.olap.Result;
23: import org.jetbrains.annotations.NotNull;
24:
25: import java.util.List;
26:
27: /**
28: * User: Martin
29: * Date: 22.07.2006
30: * Time: 15:31:31
31: */
32: @SuppressWarnings({"ALL"})
33: public class MondrianTest {
34: public static void main(@NotNull
35: String[] args) {
36: String mondrianFile = MondrianTest.class.getResource(
37: "SampleData.mondrian.xml").toString();
38: System.out.println("mondrianFile = " + mondrianFile);
39: String qs = "with member [Measures].[Variance Percent] as '([Measures].[Variance] / [Measures].[Budget])', format_string = IIf(((([Measures].[Variance] / [Measures].[Budget]) * 100.0) > 2.0), \"|#.00%|style='green'\", IIf(((([Measures].[Variance] / [Measures].[Budget]) * 100.0) < 0.0), \"|#.00%|style='red'\", \"#.00%\"))\n"
40: + "select Crossjoin({[Region].[All Regions].[Central], [Region].[All Regions].[Eastern], [Region].[All Regions].[Southern], [Region].[All Regions].[Western]}, {[Measures].[Actual], [Measures].[Budget]}) ON columns,\n"
41: + " Hierarchize(Union({[Department].[All Departments]}, [Department].[All Departments].Children)) ON rows\n"
42: + "from [Quadrant Analysis]";
43: Connection connection = DriverManager
44: .getConnection(
45: "provider=mondrian; JdbcDrivers=org.hsqldb.jdbcDriver; Jdbc=jdbc:hsqldb:hsql://localhost/sampledata; Catalog=http://localhost:8080/pentaho/GetMondrianModel?model=samples/reporting/SampleData.mondrian.xml; user=pentaho_user; password=password",
46: null, false);
47: Query query = connection.parseQuery(qs);
48:
49: Result result = connection.execute(query);
50: Axis[] axes = result.getAxes();
51: List<Position> positions = axes[0].getPositions();
52: for (int i = 0; i < positions.size(); i++) {
53: Position position = positions.get(i);
54: for (int j = 0; j < position.size(); j++) {
55: Member member = position.get(j);
56: System.out.println("member = " + member);
57: String caption = member.getHierarchy().getCaption();
58: System.out.println("caption = " + caption);
59:
60: String name = member.getHierarchy().getName();
61: System.out.println("name = " + name);
62: }
63: }
64:
65: System.out.println("result = " + result);
66:
67: }
68: }
|