| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.infoviz.datamodel.SQLTableModel
This class implements java swing Table Model and provides a powerful SQL like interface for queries, updates and deletes. It also provides the facility to create unique constraints on a set columns.
$Id$ $Revision$ $Author$
| Constructor Summary | |
| SQLTableModel()creates an empty model | |
| SQLTableModel(java.util.Map columnNameClassMap)creates a table model using the specified column names and corresponding classes | |
| SQLTableModel(javax.swing.table.TableModel model)converts any TableModel into a SQLTableModel | |
| Method Summary | |
|  void | addColumn(java.lang.String name,
          java.lang.Class columnClass)add a new column to the table | 
|  void | addRow(java.util.List rowValues)adds a row to the table using the values specified | 
|  void | addRow(java.util.Map nameValueMap)adds a row to the table | 
|  void | addTableModelListener(javax.swing.event.TableModelListener l)Adds a listener to the list that is notified each time a change to the data model occurs. | 
|  void | addUniqueConstraint(java.lang.String[] columnNames)makes sure that combination of the column values are unique. | 
|  void | delete(java.lang.String predicate,
       java.util.List bindObjects)deletes all the rows that satisfy the given predicate | 
|  java.lang.Class | getColumnClass(int columnIndex)Returns the most specific superclass for all the cell values in the column. | 
|  int | getColumnCount()Returns the number of columns in the model. | 
|  java.lang.String | getColumnName(int columnIndex)Returns the name of the column at columnIndex. | 
|  int | getRowCount()Returns the number of rows in the model. | 
|  java.lang.Object | getValueAt(int rowIndex,
           int columnIndex)Returns the value for the cell at columnIndexandrowIndex. | 
|  boolean | isCellEditable(int rowIndex,
               int columnIndex)Returns true if the cell at rowIndexandcolumnIndexis editable. | 
|  void | removeColumn(java.lang.String name)removes the column specified | 
|  void | removeTableModelListener(javax.swing.event.TableModelListener l)Removes a listener from the list that is notified each time a change to the data model occurs. | 
|  javax.swing.table.TableModel | select(java.lang.String predicate,
       java.util.List bindObjects)returns a SQLTableModel containing rows/columns matching the specified predicate and binding objects | 
|  void | setValueAt(java.lang.Object aValue,
           int rowIndex,
           int columnIndex)Sets the value in the cell at columnIndexandrowIndextoaValue. | 
|  void | update(java.lang.String predicate,
       java.util.List bindObjects,
       java.util.Map nameValueMap)updates all table rows that satisfy the predicate, with the values specified in nameValueMap | 
| Methods inherited from class java.lang.Object | 
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
public SQLTableModel()
public SQLTableModel(java.util.Map columnNameClassMap)
columnNameClassMap - - key: columnn name, valu: column classpublic SQLTableModel(javax.swing.table.TableModel model)
model - - any TableModel| Method Detail | 
public void addColumn(java.lang.String name,
                      java.lang.Class columnClass)
name - - The name of the column.columnClass - -public void removeColumn(java.lang.String name)
name - - the name of the columnpublic void addRow(java.util.Map nameValueMap)
nameValueMap - -
  
public javax.swing.table.TableModel select(java.lang.String predicate,
                                           java.util.List bindObjects)
returns a SQLTableModel containing rows/columns matching the specified predicate and binding objects
predicate - - very similar to JDBC statements
 example: "employeeNo, employeeName where salary > ? and location = ?" group by designation order by salary
example: "avg(salary > ?) where designation like "%PRESIDENT%"
SQL functions like avg and sum are also supported. todo: create a separate document
bindObjects - - the objects to substitute for the "?"s in the predicate
 example: a list containing Double(40000) and String("New York")
public void addRow(java.util.List rowValues)
rowValues - - the list should contain objects in same order in which columns
 were added to the table. Also, the Class of the objects must match the corresponding
 column Classes
public void update(java.lang.String predicate,
                   java.util.List bindObjects,
                   java.util.Map nameValueMap)
predicate - - very similar to JDBC SQL statements
 example: "employeeSalary > ? and employeeProductivity < ?"
bindObjects - - the objects to be used for the "?"s in the predicate.nameValueMap - - name of the column and corresponding value to use for
 the update
public void delete(java.lang.String predicate,
                   java.util.List bindObjects)
predicate - - very similar to JDBC SQL statements
 example: "employeeSalary > ? and employeeProductivity < ?"
bindObjects - - the objects to be used for the "?"s in the predicate.public void addUniqueConstraint(java.lang.String[] columnNames)
columnNames - - the name of the columns to include in the constraintpublic int getRowCount()
JTable uses this method to determine how many rows it
 should display.  This method should be quick, as it
 is called frequently during rendering.
getRowCount in interface javax.swing.table.TableModelgetColumnCount()public int getColumnCount()
JTable uses this method to determine how many columns it
 should create and display by default.
getColumnCount in interface javax.swing.table.TableModelgetRowCount()public java.lang.String getColumnName(int columnIndex)
columnIndex.  This is used
 to initialize the table's column header name.  Note: this name does
 not need to be unique; two columns in a table can have the same name.
getColumnName in interface javax.swing.table.TableModelcolumnIndex - the index of the column
public java.lang.Class getColumnClass(int columnIndex)
JTable to set up a
 default renderer and editor for the column.
getColumnClass in interface javax.swing.table.TableModelcolumnIndex - the index of the column
public boolean isCellEditable(int rowIndex,
                              int columnIndex)
rowIndex and
 columnIndex
 is editable.  Otherwise, setValueAt on the cell will not
 change the value of that cell.
isCellEditable in interface javax.swing.table.TableModelrowIndex - the row whose value to be queriedcolumnIndex - the column whose value to be queried
setValueAt(java.lang.Object, int, int)
public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
columnIndex and
 rowIndex.
getValueAt in interface javax.swing.table.TableModelrowIndex - the row whose value is to be queriedcolumnIndex - the column whose value is to be queried
public void setValueAt(java.lang.Object aValue,
                       int rowIndex,
                       int columnIndex)
columnIndex and
 rowIndex to aValue.
setValueAt in interface javax.swing.table.TableModelaValue - the new valuerowIndex - the row whose value is to be changedcolumnIndex - the column whose value is to be changedgetValueAt(int, int), 
isCellEditable(int, int)public void addTableModelListener(javax.swing.event.TableModelListener l)
addTableModelListener in interface javax.swing.table.TableModell - the TableModelListenerpublic void removeTableModelListener(javax.swing.event.TableModelListener l)
removeTableModelListener in interface javax.swing.table.TableModell - the TableModelListener| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||