Package org.jfree.data.jdbc
Class JDBCXYDataset
- java.lang.Object
-
- org.jfree.data.general.AbstractDataset
-
- org.jfree.data.general.AbstractSeriesDataset
-
- org.jfree.data.xy.AbstractXYDataset
-
- org.jfree.data.jdbc.JDBCXYDataset
-
- All Implemented Interfaces:
java.io.ObjectInputValidation
,java.io.Serializable
,java.lang.Cloneable
,java.util.EventListener
,Dataset
,SeriesChangeListener
,SeriesDataset
,RangeInfo
,TableXYDataset
,XYDataset
public class JDBCXYDataset extends AbstractXYDataset implements XYDataset, TableXYDataset, RangeInfo
This class provides anXYDataset
implementation over a database JDBC result set. The dataset is populated via a call to executeQuery with the string sql query. The sql query must return at least two columns. The first column will be the x-axis and remaining columns y-axis values. executeQuery can be called a number of times. The database connection is read-only and no write back facility exists.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String[]
columnNames
Column names.private java.sql.Connection
connection
The database connection.private boolean
isTimeSeries
Is this dataset a timeseries ?private double
maxValue
The maximum y value of the returned result setprivate double
minValue
The minimum y value of the returned result setprivate java.util.ArrayList
rows
Rows.
-
Constructor Summary
Constructors Modifier Constructor Description private
JDBCXYDataset()
Creates a new JDBCXYDataset (initially empty) with no database connection.JDBCXYDataset(java.lang.String url, java.lang.String driverName, java.lang.String user, java.lang.String password)
Creates a new dataset (initially empty) and establishes a new database connection.JDBCXYDataset(java.sql.Connection con)
Creates a new dataset (initially empty) using the specified database connection.JDBCXYDataset(java.sql.Connection con, java.lang.String query)
Creates a new dataset using the specified database connection, and populates it using data obtained with the supplied query.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the database connectionvoid
executeQuery(java.lang.String query)
ExecuteQuery will attempt execute the query passed to it against the existing database connection.void
executeQuery(java.sql.Connection con, java.lang.String query)
ExecuteQuery will attempt execute the query passed to it against the provided database connection.int
getItemCount()
Returns the number of items in all series.int
getItemCount(int seriesIndex)
Returns the number of items in the specified series.Range
getRangeBounds(boolean includeInterval)
Returns the range of the values in this dataset's range.double
getRangeLowerBound(boolean includeInterval)
Returns the minimum y-value in the dataset.double
getRangeUpperBound(boolean includeInterval)
Returns the maximum y-value in the dataset.int
getSeriesCount()
Returns the number of series in the dataset.java.lang.Comparable
getSeriesKey(int seriesIndex)
Returns the key for the specified series.java.lang.Number
getX(int seriesIndex, int itemIndex)
Returns the x-value for the specified series and item.java.lang.Number
getY(int seriesIndex, int itemIndex)
Returns the y-value for the specified series and item.boolean
isTimeSeries()
Returnstrue
if the dataset represents time series data, andfalse
otherwise.void
setTimeSeries(boolean timeSeries)
Sets a flag that indicates whether or not the data represents a time series.-
Methods inherited from class org.jfree.data.xy.AbstractXYDataset
getDomainOrder, getXValue, getYValue
-
Methods inherited from class org.jfree.data.general.AbstractSeriesDataset
indexOf, seriesChanged
-
Methods inherited from class org.jfree.data.general.AbstractDataset
addChangeListener, canEqual, clone, equals, fireDatasetChanged, getGroup, getNotify, hashCode, hasListener, notifyListeners, removeChangeListener, setGroup, setNotify, validateObject
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jfree.data.general.Dataset
addChangeListener, getGroup, removeChangeListener, setGroup
-
Methods inherited from interface org.jfree.data.general.SeriesDataset
indexOf
-
Methods inherited from interface org.jfree.data.xy.XYDataset
getDomainOrder, getXValue, getYValue
-
-
-
-
Field Detail
-
connection
private transient java.sql.Connection connection
The database connection.
-
columnNames
private java.lang.String[] columnNames
Column names.
-
rows
private java.util.ArrayList rows
Rows.
-
maxValue
private double maxValue
The maximum y value of the returned result set
-
minValue
private double minValue
The minimum y value of the returned result set
-
isTimeSeries
private boolean isTimeSeries
Is this dataset a timeseries ?
-
-
Constructor Detail
-
JDBCXYDataset
private JDBCXYDataset()
Creates a new JDBCXYDataset (initially empty) with no database connection.
-
JDBCXYDataset
public JDBCXYDataset(java.lang.String url, java.lang.String driverName, java.lang.String user, java.lang.String password) throws java.sql.SQLException, java.lang.ClassNotFoundException
Creates a new dataset (initially empty) and establishes a new database connection.- Parameters:
url
- URL of the database connection.driverName
- the database driver class name.user
- the database user.password
- the database user's password.- Throws:
java.lang.ClassNotFoundException
- if the driver cannot be found.java.sql.SQLException
- if there is a problem connecting to the database.
-
JDBCXYDataset
public JDBCXYDataset(java.sql.Connection con) throws java.sql.SQLException
Creates a new dataset (initially empty) using the specified database connection.- Parameters:
con
- the database connection.- Throws:
java.sql.SQLException
- if there is a problem connecting to the database.
-
JDBCXYDataset
public JDBCXYDataset(java.sql.Connection con, java.lang.String query) throws java.sql.SQLException
Creates a new dataset using the specified database connection, and populates it using data obtained with the supplied query.- Parameters:
con
- the connection.query
- the SQL query.- Throws:
java.sql.SQLException
- if there is a problem executing the query.
-
-
Method Detail
-
isTimeSeries
public boolean isTimeSeries()
Returnstrue
if the dataset represents time series data, andfalse
otherwise.- Returns:
- A boolean.
-
setTimeSeries
public void setTimeSeries(boolean timeSeries)
Sets a flag that indicates whether or not the data represents a time series.- Parameters:
timeSeries
- the new value of the flag.
-
executeQuery
public void executeQuery(java.lang.String query) throws java.sql.SQLException
ExecuteQuery will attempt execute the query passed to it against the existing database connection. If no connection exists then no action is taken. The results from the query are extracted and cached locally, thus applying an upper limit on how many rows can be retrieved successfully.- Parameters:
query
- the query to be executed.- Throws:
java.sql.SQLException
- if there is a problem executing the query.
-
executeQuery
public void executeQuery(java.sql.Connection con, java.lang.String query) throws java.sql.SQLException
ExecuteQuery will attempt execute the query passed to it against the provided database connection. If connection is null then no action is taken. The results from the query are extracted and cached locally, thus applying an upper limit on how many rows can be retrieved successfully.- Parameters:
query
- the query to be executed.con
- the connection the query is to be executed against.- Throws:
java.sql.SQLException
- if there is a problem executing the query.
-
getX
public java.lang.Number getX(int seriesIndex, int itemIndex)
Returns the x-value for the specified series and item. The implementation is responsible for ensuring that the x-values are presented in ascending order.
-
getY
public java.lang.Number getY(int seriesIndex, int itemIndex)
Returns the y-value for the specified series and item.
-
getItemCount
public int getItemCount(int seriesIndex)
Returns the number of items in the specified series.- Specified by:
getItemCount
in interfaceXYDataset
- Parameters:
seriesIndex
- the series (zero-based index).- Returns:
- The itemCount value
- See Also:
XYDataset
-
getItemCount
public int getItemCount()
Returns the number of items in all series. This method is defined by theTableXYDataset
interface.- Specified by:
getItemCount
in interfaceTableXYDataset
- Returns:
- The item count.
-
getSeriesCount
public int getSeriesCount()
Returns the number of series in the dataset.- Specified by:
getSeriesCount
in interfaceSeriesDataset
- Specified by:
getSeriesCount
in classAbstractSeriesDataset
- Returns:
- The seriesCount value
- See Also:
XYDataset
,Dataset
-
getSeriesKey
public java.lang.Comparable getSeriesKey(int seriesIndex)
Returns the key for the specified series.- Specified by:
getSeriesKey
in interfaceSeriesDataset
- Specified by:
getSeriesKey
in classAbstractSeriesDataset
- Parameters:
seriesIndex
- the series (zero-based index).- Returns:
- The seriesName value
- See Also:
XYDataset
,Dataset
-
close
public void close()
Close the database connection
-
getRangeLowerBound
public double getRangeLowerBound(boolean includeInterval)
Returns the minimum y-value in the dataset.- Specified by:
getRangeLowerBound
in interfaceRangeInfo
- Parameters:
includeInterval
- a flag that determines whether or not the y-interval is taken into account.- Returns:
- The minimum value.
-
getRangeUpperBound
public double getRangeUpperBound(boolean includeInterval)
Returns the maximum y-value in the dataset.- Specified by:
getRangeUpperBound
in interfaceRangeInfo
- Parameters:
includeInterval
- a flag that determines whether or not the y-interval is taken into account.- Returns:
- The maximum value.
-
getRangeBounds
public Range getRangeBounds(boolean includeInterval)
Returns the range of the values in this dataset's range.- Specified by:
getRangeBounds
in interfaceRangeInfo
- Parameters:
includeInterval
- a flag that determines whether or not the y-interval is taken into account.- Returns:
- The range.
-
-