001: /*
002: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007: *
008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
010: * the license for the specific language governing your rights and limitations.
011: *
012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013: */
014: package org.pentaho.reportdesigner.crm.report.datasetplugin;
015:
016: import org.jetbrains.annotations.NotNull;
017: import org.jetbrains.annotations.Nullable;
018: import org.jfree.report.DataFactory;
019: import org.jfree.report.DataRow;
020: import org.jfree.report.ReportDataFactoryException;
021: import org.pentaho.reportdesigner.crm.report.datasetplugin.multidataset.JNDISource;
022: import org.pentaho.reportdesigner.crm.report.datasetplugin.multidataset.MondrianTableModel;
023:
024: import javax.swing.table.TableModel;
025: import java.io.File;
026:
027: /**
028: * User: mdamour Date: 06.03.2007 Time: 17:52:39
029: */
030: public class MondrianDataFactory implements ExtendedDataFactory {
031: @NotNull
032: private String queryName;
033: @NotNull
034: private String mondrianCubeDefinitionFile;
035: @NotNull
036: private String query;
037: @NotNull
038: JNDISource selectedJNDIDataSource;
039: private boolean limitRows;
040: private int maxRows;
041:
042: public MondrianDataFactory(@NotNull
043: JNDISource selectedJNDIDataSource, @NotNull
044: String queryName, @NotNull
045: String cubeFile, @NotNull
046: String query, boolean limitRows, int maxRows) {
047: this .limitRows = limitRows;
048: this .maxRows = maxRows;
049: //noinspection ConstantConditions
050: if (selectedJNDIDataSource == null) {
051: throw new IllegalArgumentException(
052: "selectedJNDIDataSource must not be null");
053: }
054: // noinspection ConstantConditions
055: if (queryName == null) {
056: throw new IllegalArgumentException(
057: "queryName must not be null");
058: }
059: // noinspection ConstantConditions
060: if (cubeFile == null) {
061: throw new IllegalArgumentException(
062: "xmiFile must not be null");
063: }
064: // noinspection ConstantConditions
065: if (query == null) {
066: throw new IllegalArgumentException("query must not be null");
067: }
068:
069: this .queryName = queryName;
070: this .mondrianCubeDefinitionFile = cubeFile;
071: this .query = query;
072: this .selectedJNDIDataSource = selectedJNDIDataSource;
073: }
074:
075: public boolean canExecuteQuery(@Nullable
076: String query) {
077: return queryName.equals(query);
078: }
079:
080: public void close() {
081: }
082:
083: @NotNull
084: public DataFactory derive() throws ReportDataFactoryException {
085: return this ;
086: }
087:
088: public void open() {
089: }
090:
091: @NotNull
092: public TableModel queryData(@Nullable
093: final String inQuery, @Nullable
094: final DataRow parameters) throws ReportDataFactoryException {
095: MondrianTableModel mdxTableModel;
096: try {
097: mdxTableModel = new MondrianTableModel(
098: selectedJNDIDataSource,
099: new File(mondrianCubeDefinitionFile).toURI()
100: .toURL(), query, limitRows, maxRows);
101: } catch (Exception e) {
102: throw new ReportDataFactoryException(e.getMessage(), e);
103: }
104: return mdxTableModel;
105: }
106:
107: }
|