KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > olap > JRMondrianQueryExecuter


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * 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 JavaDoc;
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 /**
45  * @author Lucian Chirita (lucianc@users.sourceforge.net)
46  * @version $Id: JRMondrianQueryExecuter.java 1472 2006-11-09 19:16:52 +0200 (Thu, 09 Nov 2006) lucianc $
47  */

48 public class JRMondrianQueryExecuter extends JRAbstractQueryExecuter
49 {
50     private static final Log log = LogFactory.getLog(JRMondrianQueryExecuter.class);
51     
52     private Connection connection;
53     private Result result;
54
55     public JRMondrianQueryExecuter(JRDataset dataset, Map JavaDoc parametersMap)
56     {
57         super(dataset, parametersMap);
58         
59         connection = (Connection) getParameterValue(JRMondrianQueryExecuterFactory.PARAMETER_MONDRIAN_CONNECTION);
60
61         if (connection == null)
62         {
63             log.warn("The supplied mondrian.olap.Connection object is null.");
64         }
65         
66         parseQuery();
67     }
68
69     protected String JavaDoc getParameterReplacement(String JavaDoc parameterName)
70     {
71         return String.valueOf(getParameterValue(parameterName));
72     }
73
74     public JRDataSource createDatasource() throws JRException
75     {
76         JRDataSource dataSource = null;
77         
78         String JavaDoc queryStr = getQueryString();
79         if (connection != null && queryStr != null)
80         {
81             if (log.isDebugEnabled())
82             {
83                 log.debug("MDX query: " + queryStr);
84             }
85             
86             Query query = connection.parseQuery(queryStr);
87             result = connection.execute(query);
88             
89             dataSource = new JRMondrianDataSource(dataset, result);
90         }
91
92         return dataSource;
93     }
94
95     public void close()
96     {
97         if (result != null)
98         {
99             result.close();
100             result = null;
101         }
102     }
103
104     public boolean cancelQuery() throws JRException
105     {
106         return false;
107     }
108 }
109
Popular Tags