01: /*
02: * (C) Copyright 2000 - 2003 Nabh Information Systems, Inc.
03: *
04: * This program is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU General Public License
06: * as published by the Free Software Foundation; either version 2
07: * of the License, or (at your option) any later version.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: *
18: */
19:
20: package com.nabhinc.portlet.chart;
21:
22: import javax.portlet.PortletConfig;
23: import javax.portlet.PortletException;
24:
25: import org.jfree.data.AbstractDataset;
26:
27: /**
28: *
29: *
30: * @author Padmanabh Dabke
31: * (c) 2002, 2003 Nabh Information Systems, Inc. All Rights Reserved.
32: */
33: public abstract class BaseJDBCDataset extends AbstractDataset implements
34: ChartDataSource {
35:
36: public static final String DATA_SOURCE_INIT_PARAM = "dataSource";
37: public static final String SQL_INIT_PARAM = "sql";
38:
39: /**
40: * JNDI name of the data source
41: */
42: protected String bjdsDataSource = null;
43:
44: /**
45: * SQL query
46: */
47: protected String bjdsSQL = null;
48:
49: public abstract void executeQuery() throws PortletException;
50:
51: public abstract void createDummyData();
52:
53: public void retrieveChartData() throws PortletException {
54: if (bjdsSQL != null)
55: executeQuery();
56: else
57: createDummyData();
58: }
59:
60: /**
61: * Initalizes data and executes database query to populate the dataset.
62: * @param datasource Database datasource, e.g. jdbc/sbtour
63: * @param config SQL query command.
64: */
65: public void init(PortletConfig config) throws PortletException {
66:
67: // Get data source configuration.
68: bjdsDataSource = config
69: .getInitParameter(DATA_SOURCE_INIT_PARAM);
70: if (bjdsDataSource == null) {
71:
72: throw new PortletException(
73: "Missing required chart data source init parameter: "
74: + DATA_SOURCE_INIT_PARAM);
75:
76: }
77: bjdsSQL = config.getInitParameter(SQL_INIT_PARAM);
78:
79: }
80: }
|