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: * @(#)PieDataSetCreator.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.Timestamp;
035: import java.sql.ResultSet;
036: import java.sql.ResultSetMetaData;
037: import java.sql.SQLException;
038: import java.sql.Types;
039: import java.util.Iterator;
040: import java.util.List;
041: import java.util.Properties;
042: import java.util.logging.Logger;
043: import org.jfree.data.general.Dataset;
044: import org.jfree.data.general.DefaultPieDataset;
045:
046: /**
047: *
048: * @author rdwivedi
049: */
050: public class PieDataSetCreator extends DataSetCreator {
051:
052: private static Logger mLogger = Logger
053: .getLogger(PieDataSetCreator.class.getName());
054: private DefaultPieDataset dataset = null;
055:
056: public PieDataSetCreator() {
057:
058: }
059:
060: public Dataset getDefaultDataSet() {
061: return dataset;
062: }
063:
064: public void processResultSet(ResultSet resultSet)
065: throws ChartException {
066: dataset = new DefaultPieDataset();
067: try {
068: ResultSetMetaData metaData = resultSet.getMetaData();
069:
070: int columnCount = metaData.getColumnCount();
071: if (columnCount != 2) {
072: throw new ChartException(
073: "Invalid sql generated. PieDataSet requires 2 columns only");
074: }
075:
076: int columnType = metaData.getColumnType(2);
077: double value = Double.NaN;
078: while (resultSet.next()) {
079: Comparable key = resultSet.getString(1);
080: switch (columnType) {
081: case Types.NUMERIC:
082: case Types.REAL:
083: case Types.INTEGER:
084: case Types.DOUBLE:
085: case Types.FLOAT:
086: case Types.DECIMAL:
087: case Types.BIGINT:
088: value = resultSet.getDouble(2);
089: dataset.setValue(key, value);
090: break;
091:
092: case Types.DATE:
093: case Types.TIME:
094: case Types.TIMESTAMP:
095: Timestamp date = resultSet.getTimestamp(2);
096: value = date.getTime();
097: dataset.setValue(key, value);
098: break;
099:
100: default:
101: throw new ChartException("Unknown data type "
102: + columnType);
103: //break;
104: }
105: }
106: } catch (SQLException e) {
107: throw new ChartException(e);
108: }
109:
110: }
111:
112: public String getQuery() throws ChartException {
113: return null;
114: }
115:
116: }
|