public class IlvJDBCDataSource extends IlvSwingTableDataSource
IlvSwingTableDataSource.Mapping
COLUMN_SERIES, ROW_SERIES
Constructor and Description |
---|
IlvJDBCDataSource()
Creates a new
IlvJDBCDataSource object in read-only mode. |
IlvJDBCDataSource(boolean readOnly)
Creates a new
IlvJDBCDataSource object. |
IlvJDBCDataSource(ResultSet resultSet)
Creates a new
IlvJDBCDataSource object attached to resultSet
with no defined column for X abscissa and no data labels column. |
IlvJDBCDataSource(ResultSet resultSet,
int xColumnIndex,
int dataLabelsColumnIndex)
Creates a new
IlvJDBCDataSource object attached to the
specified result set using the specified column index for the x-values
and the data labels. |
IlvJDBCDataSource(String databaseURL,
String user,
String passwd,
String driverName,
String query,
int xColumnIndex,
int dataLabelsColumnIndex)
Creates a new
IlvJDBCDataSource object. |
IlvJDBCDataSource(String databaseURL,
String user,
String passwd,
String driverName,
String query,
int xColumnIndex,
int dataLabelsColumnIndex,
boolean readOnly)
Creates a new
IlvJDBCDataSource object. |
IlvJDBCDataSource(String databaseURL,
String user,
String passwd,
String driverName,
String query,
Object[] queryParameters,
int xColumnIndex,
int dataLabelsColumnIndex,
boolean readOnly)
Creates a new
IlvJDBCDataSource object. |
Modifier and Type | Method and Description |
---|---|
void |
addProperties(Properties properties)
Add properties to configure the JDBC driver
|
protected IlvDataSet[] |
buildDataSets(ResultSet resultSet)
Builds the data sets from the specified
ResultSet . |
protected int[] |
computeColumnType(ResultSet resultSet)
Returns an array of the types of every columns of the given
ResultSet . |
protected Connection |
createConnection()
Creates the connection.
|
void |
endConnection()
Closes the current connection.
|
void |
executeQuery()
Executes the query according to the current configuration.
|
protected void |
finalize()
Ensures that the current connection is closed when there are no more
references to this object.
|
String |
formatDataLabel(String label)
Returns the data label to be used for a table cell value.
|
protected Connection |
getConnection()
Returns the connection used by the data source.
|
String |
getConnectionParams()
Returns the Bean connection parameters.
|
String |
getDatabaseURL()
Returns the database URL.
|
IlvDataConverter |
getDataConverter(int col)
Returns an
IlvDataConverter object to convert data for the
specified column. |
String |
getDriverClassname()
Returns the driver classname.
|
protected Class<?> |
getJavaType(int sqlType)
Returns the type of the Java object corresponding to the specified
built-in SQL type.
|
String |
getPassword()
Returns the user password.
|
String |
getQuery()
Returns the query string, potentially with question marks as placeholders
for the parameters.
|
Object[] |
getQueryParameters()
Returns the parameters of the query, or
null or an empty array
if there are none. |
String |
getUserName()
Returns the user name.
|
boolean |
isReadOnly()
Returns whether this model is read-only.
|
protected boolean |
isReady()
Returns whether all the parameters are properly initialized.
|
boolean |
isTimeSeries(int index)
Returns whether the specified column or row (depending on the type
of this data source) represents a time series.
|
void |
setConnectionParams(String params)
Sets the Bean connection parameters.
|
void |
setDatabaseURL(String databaseURL)
Sets the database URL.
|
void |
setDataLabelsIndex(int index)
Sets the data labels index.
|
void |
setDriverClassname(String classname)
Sets the driver classname.
|
void |
setPassword(String password)
Sets the user password.
|
void |
setQuery(String query)
Sets the query string.
|
void |
setQueryParameters(Object[] queryParameters)
Sets the query parameters.
|
void |
setResultSet(ResultSet resultSet)
Sets the given result set as the new data source with no
defined columns for X abscissa and data labels.
|
void |
setResultSet(ResultSet resultSet,
int xColumnIndex,
int labelsColumnIndex)
Sets the given result set as the new data source
using the given columns for x-values and data labels.
|
void |
setResultSet(ResultSet resultSet,
String xColumnName,
String labelsColumnName)
Sets the given result set as the new data source
using the specified columns for the x-values and data labels.
|
void |
setTableModel(TableModel tableModel)
Sets the table model associated with this data source.
|
void |
setUserName(String userName)
Sets the user name.
|
void |
setXSeriesIndex(int index)
Sets the xseries column index.
|
getDataConverter, getDataLabelsIndex, getDefaultConverter, getLocale, getMapping, getSeriesType, getTableModel, getULocale, getUndefValue, getXSeriesIndex, setDataConverter, setDataSets, setDefaultConverter, setLocale, setMapping, setSeriesType, setULocale, setUndefValue, tableChanged
addDataSet, addDataSet, addDataSourceListener, containsDataSet, endBatch, fireDataSourceEvent, getDataSet, getDataSetByName, getDataSetCount, getDataSetIndex, getDataSetIterator, getDataSetList, getDataSets, initDataSets, removeDataSourceListener, setDataSet, startBatch
public IlvJDBCDataSource()
IlvJDBCDataSource
object in read-only mode.public IlvJDBCDataSource(boolean readOnly)
IlvJDBCDataSource
object.readOnly
- if true
the model is read-only otherwise modifications
are allowed and will automatically be committed back to the database.public IlvJDBCDataSource(String databaseURL, String user, String passwd, String driverName, String query, int xColumnIndex, int dataLabelsColumnIndex)
IlvJDBCDataSource
object. This constructor does
not execute the query. You have to call explicitly the
executeQuery()
method to initialize the data sets.databaseURL
- The database URL.user
- The user name.passwd
- The user password.driverName
- The JDBC driver classname to load.query
- The query to execute. In this query, every parameter should be
validated, to prevent SQL injection attacks.xColumnIndex
- The index of the xseries column. The first column is 0,
the second is 1... Passing -1 means no specific xseries should be used.dataLabelsColumnIndex
- The index of the data labels column.
The first column is 0, the second is 1... Passing -1 means no
data labels column should be used.executeQuery()
public IlvJDBCDataSource(String databaseURL, String user, String passwd, String driverName, String query, int xColumnIndex, int dataLabelsColumnIndex, boolean readOnly)
IlvJDBCDataSource
object. This constructor does
not execute the query. You have to call explicitly the
executeQuery()
method to initialize the data sets.databaseURL
- The database URL.user
- The user name.passwd
- The user password.driverName
- The JDBC driver classname to load.query
- The query to execute. In this query, every parameter should be
validated, to prevent SQL injection attacks.xColumnIndex
- The index of the xseries column. The first column is 0,
the second is 1... Passing -1 means no specific xseries should be used.dataLabelsColumnIndex
- The index of the data labels column.
The first column is 0, the second is 1... Passing -1 means no
data labels column should be used.readOnly
- if true
the model is read-only otherwise modifications
are allowed and will automatically be committed back to the database.executeQuery()
public IlvJDBCDataSource(String databaseURL, String user, String passwd, String driverName, String query, Object[] queryParameters, int xColumnIndex, int dataLabelsColumnIndex, boolean readOnly)
IlvJDBCDataSource
object. This constructor does
not execute the query. You have to call explicitly the
executeQuery()
method to initialize the data sets.databaseURL
- The database URL.user
- The user name.passwd
- The user password.driverName
- The JDBC driver classname to load.query
- The query to execute, with a question mark placeholder for
each parameter.queryParameters
- Parameters of the query.xColumnIndex
- The index of the xseries column. The first column is 0,
the second is 1... Passing -1 means no specific xseries should be used.dataLabelsColumnIndex
- The index of the data labels column.
The first column is 0, the second is 1... Passing -1 means no
data labels column should be used.readOnly
- if true
the model is read-only otherwise modifications
are allowed and will automatically be committed back to the database.executeQuery()
public IlvJDBCDataSource(ResultSet resultSet) throws SQLException
IlvJDBCDataSource
object attached to resultSet
with no defined column for X abscissa and no data labels column.SQLException
- The connection to the database has failed.public IlvJDBCDataSource(ResultSet resultSet, int xColumnIndex, int dataLabelsColumnIndex) throws SQLException
IlvJDBCDataSource
object attached to the
specified result set using the specified column index for the x-values
and the data labels.xColumnIndex
- The index of the xseries column. The first column is 0,
the second is 1... Passing -1 means no specific x-series should be used.dataLabelsColumnIndex
- The index of the data labels column.
The first column is 0, the second is 1... Passing -1 means no
data labels column should be used.SQLException
- The connection to the database has failed.public void setConnectionParams(String params) throws SQLException
SQLException
- If a database access error occurs.public String getConnectionParams()
public String getDatabaseURL()
setDatabaseURL(java.lang.String)
public void setDatabaseURL(String databaseURL)
databaseURL
- The database URL. This string should be formatted
according to the database specifications.public String getDriverClassname()
setDriverClassname(java.lang.String)
public void setDriverClassname(String classname)
classname
- The classname of the driver to use.public String getQuery()
public void setQuery(String query)
setQueryParameters(Object[])
public Object[] getQueryParameters()
null
or an empty array
if there are none.null
.public void setQueryParameters(Object[] queryParameters)
queryParameters
- An array of parameter objects. It should have as many
elements as there are question mark placeholders in
the getQuery()
string.public String getUserName()
public void setUserName(String userName)
public String getPassword()
public void setPassword(String password)
public void addProperties(Properties properties)
properties
- The set of properties added to configure the JDBC driverpublic void setXSeriesIndex(int index)
setXSeriesIndex
in class IlvSwingTableDataSource
index
- The xseries column or row index depending on the series
type. A value equals to -1 means that no specific xseries should be used.public void setDataLabelsIndex(int index)
setDataLabelsIndex
in class IlvSwingTableDataSource
index
- The data labels column or row index depending on the series
type. A value of -1 means that no data labels are available.protected Connection getConnection() throws SQLException, IllegalArgumentException
createConnection()
.
May return null
if the connection fails.SQLException
- If a database access error occurs.IllegalArgumentException
- If one or several parameters required
to establish the connection have not been properly initialized (including
errors during jdbc driver instantiation).createConnection()
protected Connection createConnection() throws SQLException, IllegalArgumentException
DriverManager.getConnection()
.IllegalStateException
- One or several parameters required for
the connection have not been properly initialized.SQLException
- If a database access error occurs.IllegalArgumentException
- If one or several parameters required
to establish the connection have not been properly initialized (including
errors during JDBC driver instantiation).protected boolean isReady()
protected void finalize() throws Throwable
public void endConnection() throws SQLException
SQLException
- If a database access error occurs.public void executeQuery() throws SQLException, IllegalArgumentException
IllegalArgumentException
- One or several parameters required for
the connection have not been properly initialized.SQLException
- If a database access error occurs.public void setResultSet(ResultSet resultSet) throws SQLException
SQLException
- If a database access error occurs.public void setResultSet(ResultSet resultSet, String xColumnName, String labelsColumnName) throws SQLException
SQLException
- If a database access error occurs.public void setResultSet(ResultSet resultSet, int xColumnIndex, int labelsColumnIndex) throws SQLException
resultSet
- The result set containing the data.xColumnIndex
- The index of the x-series column. The first column is 0,
the second is 1... Passing -1 means no specific x-series should be used.labelsColumnIndex
- The index of the data labels column.
The first column is 0, the second is 1... Passing -1 means no specific x-series should
be used.SQLException
- If a database access error occurs.setXSeriesIndex(int)
protected IlvDataSet[] buildDataSets(ResultSet resultSet) throws SQLException
ResultSet
.SQLException
protected int[] computeColumnType(ResultSet resultSet) throws SQLException
ResultSet
.
The default implementation invokes ResultSetMetaData.getColumnType()
for
each column.resultSet
- The result set to compute the column types.null
and must
be of the same length than the result set column count.SQLException
public IlvDataConverter getDataConverter(int col)
IlvDataConverter
object to convert data for the
specified column. The default implementation returns the default data
converter associated with the Java type mapped on the SQL type of the
specified column, as returned by the getJavaType
method.getDataConverter
in class IlvSwingTableDataSource
col
- The column index. The first column is 0, the second is 1, and so on.IlvSwingTableDataSource.getDefaultConverter(java.lang.Class<?>)
,
getJavaType(int)
protected Class<?> getJavaType(int sqlType)
ResultSet.getObject()
method, as indicated in
the JDBC specification.public boolean isTimeSeries(int index)
ROW_SERIES
and
COLUMN_SERIES
data source:
COLUMN_SERIES
, it returns true
if
the class returned by getTableModel().getColumnClass(idx)
is
an instance of java.util.Date
. It returns false
otherwise.ROW_SERIES
, it returns true
if
the class returned by getTableModel().getColumnClass(0)
is
an instance of java.util.Date
. It returns false
otherwise (that is, it tests only the type of the first column of the model.isTimeSeries
in class IlvSwingTableDataSource
index
- The index of the column or rows.public final boolean isReadOnly()
public void setTableModel(TableModel tableModel)
setTableModel
in class IlvSwingTableDataSource
public final String formatDataLabel(String label)
formatDataLabel
in class IlvSwingTableDataSource
label
- A value from the table model.© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.