01: /*
02: * ============================================================================
03: * GNU Lesser General Public License
04: * ============================================================================
05: *
06: * JasperReports - Free Java report-generating library.
07: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
08: *
09: * This library is free software; you can redistribute it and/or
10: * modify it under the terms of the GNU Lesser General Public
11: * License as published by the Free Software Foundation; either
12: * version 2.1 of the License, or (at your option) any later version.
13: *
14: * This library is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17: * Lesser General Public License for more details.
18: *
19: * You should have received a copy of the GNU Lesser General Public
20: * License along with this library; if not, write to the Free Software
21: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22: *
23: * JasperSoft Corporation
24: * 303 Second Street, Suite 450 North
25: * San Francisco, CA 94107
26: * http://www.jaspersoft.com
27: */
28: package net.sf.jasperreports.olap;
29:
30: import java.util.Map;
31:
32: import mondrian.olap.Connection;
33: import mondrian.olap.Query;
34: import mondrian.olap.Result;
35: import net.sf.jasperreports.engine.JRDataSource;
36: import net.sf.jasperreports.engine.JRDataset;
37: import net.sf.jasperreports.engine.JRException;
38: import net.sf.jasperreports.engine.query.JRAbstractQueryExecuter;
39:
40: import org.apache.commons.logging.Log;
41: import org.apache.commons.logging.LogFactory;
42:
43: /**
44: * @author Lucian Chirita (lucianc@users.sourceforge.net)
45: * @version $Id: JRMondrianQueryExecuter.java 1472 2006-11-09 17:16:52Z lucianc $
46: */
47: public class JRMondrianQueryExecuter extends JRAbstractQueryExecuter {
48: private static final Log log = LogFactory
49: .getLog(JRMondrianQueryExecuter.class);
50:
51: private Connection connection;
52: private Result result;
53:
54: public JRMondrianQueryExecuter(JRDataset dataset, Map parametersMap) {
55: super (dataset, parametersMap);
56:
57: connection = (Connection) getParameterValue(JRMondrianQueryExecuterFactory.PARAMETER_MONDRIAN_CONNECTION);
58:
59: if (connection == null) {
60: log
61: .warn("The supplied mondrian.olap.Connection object is null.");
62: }
63:
64: parseQuery();
65: }
66:
67: protected String getParameterReplacement(String parameterName) {
68: return String.valueOf(getParameterValue(parameterName));
69: }
70:
71: public JRDataSource createDatasource() throws JRException {
72: JRDataSource dataSource = null;
73:
74: String queryStr = getQueryString();
75: if (connection != null && queryStr != null) {
76: if (log.isDebugEnabled()) {
77: log.debug("MDX query: " + queryStr);
78: }
79:
80: Query query = connection.parseQuery(queryStr);
81: result = connection.execute(query);
82:
83: dataSource = new JRMondrianDataSource(dataset, result);
84: }
85:
86: return dataSource;
87: }
88:
89: public void close() {
90: if (result != null) {
91: result.close();
92: result = null;
93: }
94: }
95:
96: public boolean cancelQuery() throws JRException {
97: return false;
98: }
99: }
|