Source Code Cross Referenced for OLAPQueryExecuter.java in  » Report » iReport-2.0.5 » it » businesslogic » ireport » data » olap » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » iReport 2.0.5 » it.businesslogic.ireport.data.olap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2005 - 2008 JasperSoft Corporation.  All rights reserved. 
003:         * http://www.jaspersoft.com.
004:         *
005:         * Unless you have purchased a commercial license agreement from JasperSoft,
006:         * the following license terms apply:
007:         *
008:         * This program is free software; you can redistribute it and/or modify
009:         * it under the terms of the GNU General Public License version 2 as published by
010:         * the Free Software Foundation.
011:         *
012:         * This program is distributed WITHOUT ANY WARRANTY; and without the
013:         * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014:         * See the GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018:         * or write to:
019:         *
020:         * Free Software Foundation, Inc.,
021:         * 59 Temple Place - Suite 330,
022:         * Boston, MA  USA  02111-1307
023:         *
024:         *
025:         *
026:         *
027:         * OLAPQueryExecuter.java
028:         * 
029:         * Created on February 22, 2006, 1:27 PM
030:         *
031:         */
032:
033:        package it.businesslogic.ireport.data.olap;
034:
035:        import bsh.Interpreter;
036:        import it.businesslogic.ireport.IReportConnection;
037:        import it.businesslogic.ireport.JRField;
038:        import it.businesslogic.ireport.JRParameter;
039:        import it.businesslogic.ireport.connection.EJBQLConnection;
040:        import it.businesslogic.ireport.connection.MondrianConnection;
041:        import it.businesslogic.ireport.gui.MainFrame;
042:        import it.businesslogic.ireport.gui.ReportQueryDialog;
043:        import it.businesslogic.ireport.util.Misc;
044:
045:        import java.util.Collection;
046:        import java.util.Enumeration;
047:        import java.util.HashMap;
048:        import java.util.Iterator;
049:        import java.util.List;
050:        import java.util.Map;
051:        import java.util.Set;
052:        import java.util.Vector;
053:
054:        import mondrian.olap.Connection;
055:        import mondrian.olap.Query;
056:        import mondrian.olap.Result;
057:
058:        /**
059:         *
060:         * @author gtoffoli
061:         */
062:        public class OLAPQueryExecuter {
063:
064:            private Interpreter interpreter = null;
065:            private Vector reportParameters = null;
066:            private String queryString = "";
067:            private HashMap queryParameters = new HashMap();
068:
069:            /** Creates a new instance of HQLFieldsReader */
070:            public OLAPQueryExecuter(String queryStr, Vector reportParameters) {
071:
072:                this .setQueryString(queryStr);
073:                this .setReportParameters(reportParameters);
074:
075:            }
076:
077:            public String prepareQuery() throws Exception {
078:                Enumeration enumParams = getReportParameters().elements();
079:
080:                while (enumParams.hasMoreElements()) {
081:
082:                    JRParameter param = (JRParameter) enumParams.nextElement();
083:                    String parameterName = param.getName();
084:
085:                    if (queryString.indexOf("$P!{" + parameterName + "}") > 0) {
086:                        Object paramVal = ReportQueryDialog
087:                                .recursiveInterpreter(getInterpreter(), param
088:                                        .getDefaultValueExpression(),
089:                                        getReportParameters());
090:
091:                        if (paramVal == null) {
092:                            paramVal = "";
093:                        }
094:
095:                        queryString = Misc.string_replace("" + paramVal, "$P!{"
096:                                + parameterName + "}", queryString);
097:                    } else if (getQueryString().indexOf(
098:                            "$P{" + parameterName + "}") > 0) {
099:                        Object paramVal = ReportQueryDialog
100:                                .recursiveInterpreter(getInterpreter(), param
101:                                        .getDefaultValueExpression(),
102:                                        getReportParameters());
103:
104:                        if (paramVal == null) {
105:                            paramVal = "";
106:                        }
107:
108:                        queryString = Misc.string_replace("" + paramVal, "$P!{"
109:                                + parameterName + "}", queryString);
110:                    }
111:                }
112:                return queryString;
113:            }
114:
115:            private Interpreter prepareExpressionEvaluator()
116:                    throws bsh.EvalError {
117:
118:                Interpreter interpreter = new Interpreter();
119:                interpreter.setClassLoader(interpreter.getClass()
120:                        .getClassLoader());
121:                return interpreter;
122:            }
123:
124:            public Interpreter getInterpreter() {
125:
126:                if (interpreter == null) {
127:                    try {
128:                        interpreter = prepareExpressionEvaluator();
129:                    } catch (Exception ex) {
130:
131:                    }
132:                }
133:                return interpreter;
134:            }
135:
136:            public void setInterpreter(Interpreter interpreter) {
137:                this .interpreter = interpreter;
138:            }
139:
140:            public Vector getReportParameters() {
141:                return reportParameters;
142:            }
143:
144:            public void setReportParameters(Vector reportParameters) {
145:                this .reportParameters = reportParameters;
146:            }
147:
148:            public String getQueryString() {
149:                return queryString;
150:            }
151:
152:            public void setQueryString(String queryString) {
153:                this .queryString = queryString;
154:            }
155:
156:            public HashMap getQueryParameters() {
157:                return queryParameters;
158:            }
159:
160:            public void setQueryParameters(HashMap queryParameters) {
161:                this .queryParameters = queryParameters;
162:            }
163:
164:            public Query createOlapQuery() throws Exception {
165:                prepareQuery();
166:
167:                try {
168:                    IReportConnection conn = (IReportConnection) MainFrame
169:                            .getMainInstance().getProperties().get(
170:                                    "DefaultConnection");
171:                    if (!(conn instanceof  MondrianConnection)) {
172:                        throw new Exception(
173:                                "No OLAP (Mondrian) connection selected.");
174:                    }
175:
176:                    Connection mconn = ((MondrianConnection) conn)
177:                            .getMondrianConnection();
178:                    if (mconn == null) {
179:                        throw new Exception(
180:                                "The supplied mondrian.olap.Connection object is null.");
181:                    }
182:
183:                    Query query = mconn.parseQuery(queryString);
184:
185:                    return query;
186:
187:                } catch (Exception ex) {
188:                    ex.printStackTrace();
189:                    throw ex;
190:                } finally {
191:
192:                }
193:            }
194:
195:            public Result executeOlapQuery() throws Exception {
196:                prepareQuery();
197:                try {
198:
199:                    IReportConnection conn = (IReportConnection) MainFrame
200:                            .getMainInstance().getProperties().get(
201:                                    "DefaultConnection");
202:                    if (!(conn instanceof  MondrianConnection)) {
203:                        throw new Exception(
204:                                "No OLAP (Mondrian) connection selected.");
205:                    }
206:
207:                    Connection mconn = ((MondrianConnection) conn)
208:                            .getMondrianConnection();
209:                    if (mconn == null) {
210:                        throw new Exception(
211:                                "The supplied mondrian.olap.Connection object is null.");
212:                    }
213:
214:                    Query query = mconn.parseQuery(queryString);
215:                    Result result = mconn.execute(query);
216:
217:                    return result;
218:
219:                } catch (Exception ex) {
220:                    ex.printStackTrace();
221:                    throw ex;
222:                } finally {
223:
224:                }
225:            }
226:
227:            public Vector getFields(Object obj) {
228:
229:                Vector fields = new Vector();
230:                java.beans.PropertyDescriptor[] pd = org.apache.commons.beanutils.PropertyUtils
231:                        .getPropertyDescriptors(obj.getClass());
232:                for (int nd = 0; nd < pd.length; ++nd) {
233:                    String fieldName = pd[nd].getName();
234:                    if (pd[nd].getPropertyType() != null
235:                            && pd[nd].getReadMethod() != null) {
236:                        String returnType = pd[nd].getPropertyType().getName();
237:                        it.businesslogic.ireport.JRField field = new it.businesslogic.ireport.JRField(
238:                                fieldName, Misc.getJRFieldType(returnType));
239:                        field.setDescription(""); //Field returned by " +methods[i].getName() + " (real type: "+ returnType +")");
240:                        fields.addElement(field);
241:                    }
242:                }
243:
244:                return fields;
245:            }
246:
247:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.