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.MQLTableModel;
022:
023: import javax.swing.table.TableModel;
024: import java.util.Locale;
025:
026: /**
027: * User: mdamour
028: * Date: 06.03.2007
029: * Time: 17:52:39
030: */
031: public class MQLDataFactory implements ExtendedDataFactory {
032: @NotNull
033: private String queryName;
034: @NotNull
035: private String xmiFile;
036: @NotNull
037: private String query;
038: @NotNull
039: private Locale locale;
040: private boolean limitRows;
041: private int maxRows;
042:
043: public MQLDataFactory(@NotNull
044: Locale locale, @NotNull
045: String queryName, @NotNull
046: String xmiFile, @NotNull
047: String query, boolean limitRows, int maxRows) {
048: this .limitRows = limitRows;
049: this .maxRows = maxRows;
050: //noinspection ConstantConditions
051: if (locale == null) {
052: throw new IllegalArgumentException(
053: "locale must not be null");
054: }
055: //noinspection ConstantConditions
056: if (queryName == null) {
057: throw new IllegalArgumentException(
058: "queryName must not be null");
059: }
060: //noinspection ConstantConditions
061: if (xmiFile == null) {
062: throw new IllegalArgumentException(
063: "xmiFile must not be null");
064: }
065: //noinspection ConstantConditions
066: if (query == null) {
067: throw new IllegalArgumentException("query must not be null");
068: }
069: this .locale = locale;
070: this .queryName = queryName;
071: this .xmiFile = xmiFile;
072: this .query = query;
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: MQLTableModel mqlTableModel;
096: try {
097: mqlTableModel = new MQLTableModel(locale, xmiFile, query,
098: limitRows, maxRows);
099: } catch (Exception e) {
100: throw new ReportDataFactoryException(e.getMessage(), e);
101: }
102: return mqlTableModel;
103: }
104:
105: }
|