Source Code Cross Referenced for PentahoTableDataFactory.java in  » Report » pentaho-report » org » pentaho » plugin » jfreereport » helper » 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 » pentaho report » org.pentaho.plugin.jfreereport.helper 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 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. The Original Code is the Pentaho
007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
008:         *
009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to
011:         * the license for the specific language governing your rights and limitations.
012:         */
013:        package org.pentaho.plugin.jfreereport.helper;
014:
015:        import java.util.HashMap;
016:        import java.util.Iterator;
017:        import javax.swing.table.TableModel;
018:
019:        import org.jfree.report.DataFactory;
020:        import org.jfree.report.DataRow;
021:        import org.jfree.report.ReportDataFactoryException;
022:        import org.jfree.report.util.CloseableTableModel;
023:        import org.pentaho.core.component.IPreparedComponent;
024:        import org.pentaho.commons.connection.IPentahoResultSet;
025:        import org.pentaho.messages.Messages;
026:
027:        /**
028:         * The PentahoTableDataFactory class implements JFreeReport's data factory
029:         * and manages the TableModels provided to JFreeReport.  The primary
030:         * difference between this class and JFreeReport's standard TableDataFactory
031:         * is the "getTableIterator" method, which allows the Platform to clean up and
032:         * table model resources after their use.  Also, we support Pentaho's
033:         * IPreparedComponent interface which allows a prepared component to generate 
034:         * a result set when requested.
035:         * 
036:         * @author Will Gorman
037:         */
038:        public class PentahoTableDataFactory implements  DataFactory, Cloneable {
039:
040:            /** map of tables to keep track of */
041:            private HashMap tables;
042:
043:            private HashMap components;
044:
045:            /**
046:             * default constructor
047:             *
048:             */
049:            public PentahoTableDataFactory() {
050:                this .tables = new HashMap();
051:                this .components = new HashMap();
052:            }
053:
054:            /**
055:             * constructor with one time call to addTable for convenience.
056:             * 
057:             * @param name table name
058:             * @param tableModel instance of table model
059:             */
060:            public PentahoTableDataFactory(final String name,
061:                    final TableModel tableModel) {
062:                this ();
063:                addTable(name, tableModel);
064:            }
065:
066:            /**
067:             * add a table to the map
068:             * 
069:             * @param name table name
070:             * @param tableModel instance of table model
071:             */
072:            public void addTable(final String name, final TableModel tableModel) {
073:                tables.put(name, tableModel);
074:            }
075:
076:            /**
077:             * add a prepared component to the map
078:             * 
079:             * @param name prepared component name
080:             * @param component instance of prepared component
081:             */
082:            public void addPreparedComponent(final String name,
083:                    final IPreparedComponent component) {
084:                components.put(name, component);
085:            }
086:
087:            /**
088:             * remove a table from the map
089:             * 
090:             * @param name table name
091:             */
092:            public void removeTable(final String name) {
093:                tables.remove(name);
094:            }
095:
096:            /**
097:             * Queries a datasource. The string 'query' defines the name of the query. The
098:             * Parameterset given here may contain more data than actually needed.
099:             * <p/>
100:             * The dataset may change between two calls, do not assume anything!
101:             *
102:             * @param query the name of the table.
103:             * @param parameters are ignored for this factory.
104:             * @return the report data or null.
105:             */
106:            public TableModel queryData(final String query,
107:                    final DataRow parameters) {
108:                TableModel model = (TableModel) tables.get(query);
109:                if (model == null) {
110:                    final IPreparedComponent component = (IPreparedComponent) components
111:                            .get(query);
112:                    if (component != null) {
113:                        final HashMap map = new HashMap();
114:                        if (parameters != null) {
115:                            for (int i = 0; i < parameters.getColumnCount(); i++) {
116:                                map.put(parameters.getColumnName(i), parameters
117:                                        .get(i));
118:                            }
119:                        }
120:                        final IPentahoResultSet rs = component
121:                                .executePrepared(map);
122:                        model = new PentahoTableModel(rs);
123:                    }
124:                }
125:                return model;
126:            }
127:
128:            public void open() {
129:
130:            }
131:
132:            public void close() {
133:                final Iterator iter = tables.values().iterator();
134:                while (iter.hasNext()) {
135:                    final TableModel model = (TableModel) iter.next();
136:                    if (model instanceof  CloseableTableModel) {
137:                        final CloseableTableModel closeableTableModel = (CloseableTableModel) model;
138:                        closeableTableModel.close();
139:                    }
140:                }
141:                tables.clear();
142:            }
143:
144:            /**
145:             * Derives a freshly initialized report data factory, which is independend of
146:             * the original data factory. Opening or Closing one data factory must not
147:             * affect the other factories.
148:             *
149:             * @return
150:             */
151:            public DataFactory derive() throws ReportDataFactoryException {
152:                try {
153:                    return (DataFactory) clone();
154:                } catch (CloneNotSupportedException e) {
155:                    throw new ReportDataFactoryException(
156:                            Messages
157:                                    .getErrorString("PentahoTableDataFactory.ERROR_0001_CLONE_SHOULD_NOT_FAIL")); //$NON-NLS-1$
158:                }
159:            }
160:
161:            public Object clone() throws CloneNotSupportedException {
162:                final PentahoTableDataFactory dataFactory = (PentahoTableDataFactory) super 
163:                        .clone();
164:                dataFactory.tables = (HashMap) tables.clone();
165:                return dataFactory;
166:            }
167:
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.