com.compomics.util.db
Class DBResultSet

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.compomics.util.db.DBResultSet
All Implemented Interfaces:
Serializable, TableModel

public class DBResultSet
extends AbstractTableModel

This class wraps a DB resultset in an 'offline' object.

Author:
Lennart Martens
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
DBResultSet()
          Default constructor, just creates an empty resultset.
DBResultSet(ResultSet aRS)
          This constructor takes a ResultSet from which the data is read.
DBResultSet(ResultSet aRS, boolean aNullReplace)
          This constructor takes a ResultSet from which the data is read.
 
Method Summary
 Class getColumnClass(int columnIndex)
          Returns Object.class regardless of columnIndex.
 int getColumnCount()
          This method reports on the number of columns in the resultset.
 String getColumnName(int column)
          Returns a default name for the column using spreadsheet conventions: A, B, C, ...
 String[] getColumnNames()
          This method reports on all the columnn ames.
 Object[][] getData()
          This method reports on the data stored in the resultset.
 int getRowCount()
          This method reports on the number of rows in the resultset.
 Object getValueAt(int rowIndex, int columnIndex)
          Returns the value for the cell at columnIndex and rowIndex.
 void writeToCSVFile(Writer out, String aSeparator)
          This method allows the caller to write the current dataset to the specified Writer.
 void writeToHTMLTable(Writer out, int aBorderstyle)
          This method allows the caller to write the current dataset to the specified Writer.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBResultSet

public DBResultSet()
Default constructor, just creates an empty resultset.


DBResultSet

public DBResultSet(ResultSet aRS)
            throws SQLException
This constructor takes a ResultSet from which the data is read. This ResultSet will not be closed by this constructor, so it remains available and the closing is up to the caller! Nullreplace is FALSE for this constructor!

Parameters:
aRS - ResultSet from which to read the data. Closing the ResultSet is up to the caller!!
Throws:
SQLException - whenever reading the resultset failed.

DBResultSet

public DBResultSet(ResultSet aRS,
                   boolean aNullReplace)
            throws SQLException
This constructor takes a ResultSet from which the data is read. This ResultSet will not be closed by this constructor, so it remains available and the closing is up to the caller! Notice that the null replace flag allows you to replace 'null' values returned by the DB to the String "(null)".

Parameters:
aRS - ResultSet from which to read the data. Closing the ResultSet is up to the caller!!
aNullReplace - boolean to indicate whether 'null' values returned by the DB should be converted into "(null)" Strings ('true') or not ('false').
Throws:
SQLException - whenever reading the resultset failed.
Method Detail

getColumnNames

public String[] getColumnNames()
This method reports on all the columnn ames.

Returns:
String[] with all the column names.

getData

public Object[][] getData()
This method reports on the data stored in the resultset.

Returns:
Object[][] with the data.

getColumnCount

public int getColumnCount()
This method reports on the number of columns in the resultset.

Returns:
int with the columncount.

getRowCount

public int getRowCount()
This method reports on the number of rows in the resultset.

Returns:
int with the rowcount.

getValueAt

public Object getValueAt(int rowIndex,
                         int columnIndex)
Returns the value for the cell at columnIndex and rowIndex.

Parameters:
rowIndex - the row whose value is to be queried
columnIndex - the column whose value is to be queried
Returns:
the value Object at the specified cell

getColumnClass

public Class getColumnClass(int columnIndex)
Returns Object.class regardless of columnIndex.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel
Parameters:
columnIndex - the column being queried
Returns:
the Object.class

getColumnName

public String getColumnName(int column)
Returns a default name for the column using spreadsheet conventions: A, B, C, ... Z, AA, AB, etc. If column cannot be found, returns an empty string.

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel
Parameters:
column - the column being queried
Returns:
a string containing the default name of column

writeToCSVFile

public void writeToCSVFile(Writer out,
                           String aSeparator)
                    throws IOException
This method allows the caller to write the current dataset to the specified Writer. Note that flushing and closing the writer is up to the caller.

Parameters:
out - Writer to print to. Note that flushing and closing this writer is up to the caller.
aSeparator - String with the separator character(s) to use.
Throws:
IOException - when something goes wrong.

writeToHTMLTable

public void writeToHTMLTable(Writer out,
                             int aBorderstyle)
                      throws IOException
This method allows the caller to write the current dataset to the specified Writer. Note that flushing and closing the writer is up to the caller.

Parameters:
out - Writer to print to. Note that flushing and closing this writer is up to the caller.
aBorderstyle - int with the HTML table border tag style for the table.
Throws:
IOException - when something goes wrong.


Copyright © 2012. All Rights Reserved.