Source Code Cross Referenced for JDBCCategoryDataset.java in  » Portal » stringbeans-3.5 » com » nabhinc » portlet » chart » 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 » Portal » stringbeans 3.5 » com.nabhinc.portlet.chart 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * (C) Copyright 2000 - 2003 Nabh Information Systems, Inc. 
003:         * 
004:         * This program is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU General Public License 
006:         * as published by the Free Software Foundation; either version 2
007:         * of the License, or (at your option) any later version.
008:         * 
009:         * This program is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of 
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
012:         * GNU General Public License for more details.
013:         * 
014:         * You should have received a copy of the GNU General Public License
015:         * along with this program; if not, write to the Free Software 
016:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
017:         * 
018:         */
019:
020:        package com.nabhinc.portlet.chart;
021:
022:        import java.util.List;
023:
024:        import java.sql.Connection;
025:        import java.sql.PreparedStatement;
026:        import java.sql.ResultSet;
027:        import java.sql.ResultSetMetaData;
028:        import java.util.ArrayList;
029:        import java.util.Vector;
030:
031:        import javax.portlet.PortletException;
032:
033:        import org.jfree.data.CategoryDataset;
034:        import org.jfree.data.DefaultKeyedValues2D;
035:
036:        import com.nabhinc.util.db.DBUtil;
037:
038:        /**
039:         * 
040:         *
041:         * @author Padmanabh Dabke
042:         * (c) 2002, 2003 Nabh Information Systems, Inc. All Rights Reserved.
043:         */
044:        public class JDBCCategoryDataset extends BaseJDBCDataset implements 
045:                CategoryDataset {
046:
047:            private static final long serialVersionUID = -7998356694642329093L;
048:
049:            private String[] jcdsCategoryArray = null;
050:            private String[] jcdsSeriesArray = null;
051:            private DefaultKeyedValues2D jcds2DData = null;
052:
053:            /**
054:             * @see com.nabhinc.portal.charting.BaseJDBCDataSet#executeQuery()
055:             */
056:            public void executeQuery() throws PortletException {
057:                Object xObject = null;
058:                int column = 0;
059:                int currentColumn = 0;
060:                int numberOfColumns = 0;
061:                int numberOfValidColumns = 0;
062:                int columnTypes[] = null;
063:                List categoryNames = new ArrayList();
064:                Vector rows = new Vector();
065:                Number[] newRow;
066:
067:                jcds2DData = new DefaultKeyedValues2D();
068:                Connection connection = null;
069:                ResultSet resultSet = null;
070:                PreparedStatement statement = null;
071:                ResultSetMetaData metaData = null;
072:
073:                try {
074:                    connection = DBUtil.getConnection(bjdsDataSource);
075:                    statement = connection.prepareStatement(bjdsSQL);
076:                    resultSet = statement.executeQuery();
077:                    metaData = resultSet.getMetaData();
078:
079:                    numberOfColumns = metaData.getColumnCount();
080:                    int startColumn = 1;
081:                    boolean preConfiguredCats = false;
082:                    if (jcdsCategoryArray != null) {
083:                        preConfiguredCats = true;
084:                        startColumn = 0;
085:                    }
086:
087:                    if (jcdsSeriesArray == null) {
088:                        jcdsSeriesArray = new String[numberOfColumns
089:                                - startColumn];
090:
091:                        int colCount = 0;
092:                        for (column = startColumn; column < numberOfColumns; column++) {
093:                            jcdsSeriesArray[colCount] = metaData
094:                                    .getColumnLabel(column + 1);
095:                            colCount++;
096:                        }
097:                    }
098:
099:                    int catNum = 0;
100:                    while (resultSet.next()) {
101:
102:                        if (preConfiguredCats) {
103:
104:                            for (int i = 0; i < numberOfColumns; i++) {
105:                                jcds2DData.setValue((Number) resultSet
106:                                        .getObject(i + 1), jcdsSeriesArray[i],
107:                                        jcdsCategoryArray[catNum]);
108:                            }
109:                            catNum++;
110:                        } else {
111:                            /// First column is a category name
112:                            String cat = resultSet.getString(1);
113:                            for (int i = 1; i < numberOfColumns; i++) {
114:                                jcds2DData.setValue((Number) resultSet
115:                                        .getObject(i + 1),
116:                                        jcdsSeriesArray[i - 1], cat);
117:                            }
118:                        }
119:                    }
120:
121:                } catch (Exception ex) {
122:                    throw new PortletException(
123:                            "Encountered database exception.", ex);
124:                } finally {
125:                    DBUtil.close(resultSet);
126:                    DBUtil.close(statement);
127:                    DBUtil.close(connection);
128:                }
129:            }
130:
131:            /**
132:             * @see com.nabhinc.portal.charting.BaseJDBCDataSet#createDummyData()
133:             */
134:            public void createDummyData() {
135:
136:                if (jcds2DData == null) {
137:                    jcds2DData = new DefaultKeyedValues2D();
138:                    jcdsCategoryArray = new String[] { "mon", "tue", "wed",
139:                            "thu", "fri", "sat", "sun" };
140:                    jcdsSeriesArray = new String[] { "test1.jsp", "test2.jsp",
141:                            "test3.jsp", "test4.jsp" };
142:
143:                    for (int i = 0; i < jcdsCategoryArray.length; i++) {
144:                        int lastY = (int) (Math.random() * 1000 + 1000);
145:                        for (int j = 0; j < jcdsSeriesArray.length; j++) {
146:                            final int y = lastY
147:                                    + (int) (Math.random() * 200 - 100);
148:                            lastY = y;
149:                            jcds2DData.setValue(new Integer(y),
150:                                    jcdsSeriesArray[j], jcdsCategoryArray[i]);
151:                        }
152:                    }
153:                }
154:
155:            }
156:
157:            /* (non-Javadoc)
158:             * @see org.jfree.data.KeyedValues2D#getRowKey(int)
159:             */
160:            public Comparable getRowKey(int arg0) {
161:                return jcds2DData.getRowKey(arg0);
162:            }
163:
164:            /* (non-Javadoc)
165:             * @see org.jfree.data.KeyedValues2D#getRowIndex(java.lang.Comparable)
166:             */
167:            public int getRowIndex(Comparable arg0) {
168:                return jcds2DData.getRowIndex(arg0);
169:            }
170:
171:            /* (non-Javadoc)
172:             * @see org.jfree.data.KeyedValues2D#getRowKeys()
173:             */
174:            public List getRowKeys() {
175:                return jcds2DData.getRowKeys();
176:            }
177:
178:            /* (non-Javadoc)
179:             * @see org.jfree.data.KeyedValues2D#getColumnKey(int)
180:             */
181:            public Comparable getColumnKey(int arg0) {
182:                return jcds2DData.getColumnKey(arg0);
183:            }
184:
185:            /* (non-Javadoc)
186:             * @see org.jfree.data.KeyedValues2D#getColumnIndex(java.lang.Comparable)
187:             */
188:            public int getColumnIndex(Comparable arg0) {
189:                return jcds2DData.getColumnIndex(arg0);
190:            }
191:
192:            /* (non-Javadoc)
193:             * @see org.jfree.data.KeyedValues2D#getColumnKeys()
194:             */
195:            public List getColumnKeys() {
196:                return jcds2DData.getColumnKeys();
197:            }
198:
199:            /* (non-Javadoc)
200:             * @see org.jfree.data.KeyedValues2D#getValue(java.lang.Comparable, java.lang.Comparable)
201:             */
202:            public Number getValue(Comparable arg0, Comparable arg1) {
203:                return jcds2DData.getValue(arg0, arg1);
204:            }
205:
206:            /* (non-Javadoc)
207:             * @see org.jfree.data.Values2D#getRowCount()
208:             */
209:            public int getRowCount() {
210:                return jcds2DData.getRowCount();
211:            }
212:
213:            /* (non-Javadoc)
214:             * @see org.jfree.data.Values2D#getColumnCount()
215:             */
216:            public int getColumnCount() {
217:                return jcds2DData.getColumnCount();
218:            }
219:
220:            /* (non-Javadoc)
221:             * @see org.jfree.data.Values2D#getValue(int, int)
222:             */
223:            public Number getValue(int arg0, int arg1) {
224:                return jcds2DData.getValue(arg0, arg1);
225:            }
226:
227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.