001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)XYDataSetCreator.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package org.openesb.tools.extchart.jfchart.data;
030:
031: import org.openesb.tools.extchart.exception.ChartException;
032: import org.openesb.tools.extchart.property.ChartConstants;
033:
034: import java.sql.ResultSet;
035: import java.sql.ResultSetMetaData;
036: import java.sql.SQLException;
037: import java.sql.Types;
038: import java.util.Iterator;
039: import java.util.List;
040:
041: import java.util.logging.Logger;
042: import org.jfree.data.general.Dataset;
043: import org.jfree.data.xy.CategoryTableXYDataset;
044:
045: /**
046: *
047: * @author rdwivedi
048: */
049: public class XYDataSetCreator extends DataSetCreator {
050: private static Logger mLogger = Logger
051: .getLogger(XYDataSetCreator.class.getName());
052: private CategoryTableXYDataset dataset = null;
053:
054: /** Creates a new instance of XYDataSetCreator */
055: public XYDataSetCreator() {
056:
057: }
058:
059: public Dataset getDefaultDataSet() {
060: return dataset;
061: }
062:
063: public void processResultSet(ResultSet resultSet)
064: throws ChartException {
065: dataset = new CategoryTableXYDataset();
066: try {
067: ResultSetMetaData metaData = resultSet.getMetaData();
068: int numberOfColumns = metaData.getColumnCount();
069: if (numberOfColumns != 3) {
070: throw new ChartException("There must be 3 columns.");
071: }
072: while (resultSet.next()) {
073: String series = resultSet.getString(1);
074: double x = 0, y = 0;
075: boolean dataOK = true;
076: int columnType = metaData.getColumnType(2);
077: switch (columnType) {
078: case Types.NUMERIC:
079: case Types.REAL:
080: case Types.INTEGER:
081: case Types.DOUBLE:
082: case Types.FLOAT:
083: case Types.DECIMAL:
084: case Types.BIGINT:
085: case Types.SMALLINT:
086: x = resultSet.getDouble(2);
087: break;
088:
089: case Types.NULL:
090: break;
091: default:
092: System.err.println("Unknown data");
093: dataOK = false;
094: break;
095: }
096:
097: columnType = metaData.getColumnType(3);
098: switch (columnType) {
099: case Types.NUMERIC:
100: case Types.REAL:
101: case Types.INTEGER:
102: case Types.DOUBLE:
103: case Types.FLOAT:
104: case Types.DECIMAL:
105: case Types.BIGINT:
106: case Types.SMALLINT:
107: y = resultSet.getDouble(3);
108: break;
109:
110: case Types.NULL:
111: break;
112: default:
113: System.err.println("Unknown data");
114: dataOK = false;
115: break;
116: }
117:
118: if (dataOK) {
119: dataset.add(x, y, series);
120: }
121: }
122: } catch (SQLException e) {
123: throw new ChartException(e);
124: }
125:
126: }
127:
128: public String getQuery() throws ChartException {
129: return null;
130: }
131:
132: }
|