net.sourceforge.openforecast.input
Class ResultSetBuilder

java.lang.Object
  extended by net.sourceforge.openforecast.input.AbstractBuilder
      extended by net.sourceforge.openforecast.input.ResultSetBuilder
All Implemented Interfaces:
Builder

public class ResultSetBuilder
extends AbstractBuilder

Defines a Builder that can be used to construct a DataSet from a ResultSet. This class makes for a quick and easy "import" of data from a JDBC data source such as an Oracle database.

WARNING: This class has not been tested. It has been made available as a starting point for anyone interested in implementing this kind of Builder. It should work fine but, like I said, has not been tested. If you use this class and fine it works, as is, let me know (and perhaps I can remove this message). Alternatively, if you find any changes are necessary, please submit them for inclusion in the project.

Each record in the result set is assumed to define one data point. The last value on each row is assumed to represent the dependent variable. For example, if the independent variables are represented by x1, x2, x3 and so on, and the dependent variable is represented by y, then a row should be of the form:

  x1, x2, ..., xi, y
 

For example, the following represents data points (1,3), (2,5), (3,6), and (4,7):

  1, 3
  2, 5
  3, 6
  4, 7
 

where the values 3, 5, 6 and 7 are the observed values of the dependent variable corresponding to the associated values of the independent variables with the values 1, 2, 3, and 4 respectively. The independent variables will be given the column names as defined by the query.

For example, consider the following query:

  SELECT period, sales_revenue FROM sales_summary
 
This would create a series of data points with the single independent variable, period. The sales_revenue column is assumed to represent the dependent variable (for which we don't currently use the name).

Since:
0.4
Author:
Steven R. Gould

Constructor Summary
ResultSetBuilder(ResultSet resultSet)
          Constructs a new ResultSetBuilder that reads its input from the given ResultSet.
 
Method Summary
 DataSet build()
          Retrieves a DataSet - a collection of DataPoints - from the current input source.
 
Methods inherited from class net.sourceforge.openforecast.input.AbstractBuilder
addVariable, getNumberOfVariables, getVariableName, setNumberOfVariables, setVariableName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResultSetBuilder

public ResultSetBuilder(ResultSet resultSet)
Constructs a new ResultSetBuilder that reads its input from the given ResultSet. The fields will be named according to the column labels defined by the ResultSet's meta data.

Parameters:
resultSet - the ResultSet containing data to be used to build the DataSet.
Method Detail

build

public DataSet build()
              throws SQLException
Retrieves a DataSet - a collection of DataPoints - from the current input source. The DataSet should contain all DataPoints defined by the input source.

In general, build will attempt to convert all rows in the ResultSet to data points. In this implementation, all columns are assumed to contain numeric data. This restriction may be relaxed at a later date.

Returns:
a DataSet built from the current input source.
Throws:
SQLException - if a database access error occurs.


OpenForecast, Copyright (c) Steven Gould, 2002-2011