JComponentPack 1.5.0

com.zfqjava.swing.model
Class ResultSetTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.zfqjava.swing.model.ResultSetTableModel
All Implemented Interfaces:
Pageable, Reloadable, Serializable, TableModel
Direct Known Subclasses:
RowSetTableModel

public class ResultSetTableModel
extends AbstractTableModel
implements Reloadable, Pageable

ResultSetTableModel provides a ResultSet table model.

The TableModel methods use the model row index, all other methods use the data row index of the ResultSet, but it is 0 based.
The page index also is 0 based.
All row index must be >= 0, and all first index must be <= last index.

See Also:
Serialized Form

Field Summary
static int CHANGE_CELL
          Identifies the update or insert policy.
static int CHANGE_PAGE
          Identifies the update or insert policy.
static int CHANGE_ROW
          Identifies the update or insert policy.
protected  SwingPropertyChangeSupport changeSupport
          If any PropertyChangeListeners have been registered, the changeSupport field describes them.
static int OFF
          Identifies the update or insert policy.
static int UNKNOWN_COUNT
          Identifies the unknown for page or all row count.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
ResultSetTableModel()
          Empty ResultSetTableModel
ResultSetTableModel(ResultSet rs)
          Constructs a ResultSetTableModel with a rs.
ResultSetTableModel(ResultSet rs, boolean sync)
          Constructs a ResultSetTableModel with a rs.
ResultSetTableModel(ResultSet rs, boolean sync, int pageSize)
          Constructs a ResultSetTableModel with a rs.
ResultSetTableModel(ResultSet rs, int pageSize)
          Constructs a ResultSetTableModel with a rs.
ResultSetTableModel(String sql, String url, String username, String password)
          Constructs a ResultSetTableModel with a SQL query command.
ResultSetTableModel(String sql, String url, String username, String password, boolean sync)
          Constructs a ResultSetTableModel with a SQL query command.
ResultSetTableModel(String sql, String url, String username, String password, boolean sync, int pageSize)
          Constructs a ResultSetTableModel with a SQL query command.
ResultSetTableModel(String sql, String url, String username, String password, int pageSize)
          Constructs a ResultSetTableModel with a SQL query command.
 
Method Summary
 void acceptChanges()
          Propagates all row update, insert and delete changes to the underlying data source.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a PropertyChangeListener to the listener list.
 void close()
          Close the database connection.
 int dataToModelRow(int dataRow)
          Converts the ResultSet row index to the model row index.
 void deleteRow()
          Deletes the data row at the specified current row index.
 void deleteRow(int rowIndex)
          Deletes the data row at the specified row index.
 void deleteRow(int firstRow, int lastRow)
          Deletes the data row from firstRow to lastRow
protected  void firePropertyChange(String propertyName, int oldValue, int newValue)
           
protected  void firePropertyChange(String propertyName, Object oldValue, Object newValue)
          Supports reporting bound property changes.
 void firstPage()
           
 void firstRow()
          Goto the fist row.
 int getAllRowCount()
          Returns all row count.
 int getAutoInsertPolicy()
          Returns the auto insert policy.
 int getAutoUpdatePolicy()
          Returns the auto update policy.
 Class getColumnClass(int columnIndex)
           
 int getColumnCount()
           
 String getColumnName(int columnIndex)
           
 String getCommand()
          Returns the command.
 String getCountCommand()
           
 int getCurrentAllRowCount()
           
 int getFirstRowIndex()
          Returns the first row index in current page.
 int[] getKeyColumns()
          Returns the primary key columns.
 int getPageCount()
          Returns the page count.
 int getPageIndex()
          Returns the current page index.
 int getPageSize()
          Returns the page size.
 String getPassword()
          Returns the password
 PropertyChangeListener[] getPropertyChangeListeners()
          Returns an array of all the PropertyChangeListeners added to this ResultSetTableModel with addPropertyChangeListener().
 int getRowCount()
           
 int getRowIndex()
          Returns the current row index.
 String getTableName()
          Returns the table name for updating.
 String getUrl()
          Returns the url.
 String getUsername()
          Returns the user name.
 Object getValueAt(int rowIndex, int columnIndex)
           
 boolean hasNextPage()
           
 boolean hasPreviousPage()
           
 void insertRow()
          Inserts the data row.
 boolean isCellEditable(int rowIndex, int columnIndex)
           
 boolean isFirstPage()
           
 boolean isLastPage()
           
 void lastPage()
           
 void lastRow()
          Goto the last row.
 int modelToDataRow(int modelRow)
          Converts the model row index to the ResultSet row index.
 void moveToInsertRow()
          Move the cursor to the insert row.
 void nextPage()
          Show the next page.
 void nextRow()
          Goto the next row.
 void previousPage()
          Show the previous page.
 void previousRow()
          Goto the previous row.
 void refreshCell(int rowIndex, int columnIndex)
          Refreshs the cell at the specified row and column index.
 void refreshCell(int firstRow, int lastRow, int firstColumn, int lastColumn)
          Refreshs the cell at the specified row and column index.
 void refreshRow()
          Refreshs the data row at the specified current row index.
 void refreshRow(int rowIndex)
          Refreshs the data row at the specified row index.
 void refreshRow(int firstRow, int lastRow)
          Refreshs the data row from firstRow to lastRow
 void reload()
          Reloads all record from database.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes a PropertyChangeListener from the listener list.
 void setAllRowCount(int allRowCount)
           
 void setAutoInsertPolicy(int insertPolicy)
          Sets the auto insert policy.
 void setAutoUpdatePolicy(int updatePolicy)
          Sets the auto update policy.
 void setCommand(String sql)
          Sets the command.
 void setCountCommand(String countCommand)
           
 void setKeyColumns(int[] keyColumns)
          Sets the primary key columns.
 void setPageIndex(int pageIndex)
          Sets the page index.
 void setPassword(String password)
          Sets the password
 void setRowIndex(int rowIndex)
          Sets the row index.
 void setTableName(String tableName)
          Sets the table name for updating.
 void setUrl(String url)
          Sets the url.
 void setUsername(String username)
          Sets the user name.
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
           
 void updateCell(int rowIndex, int columnIndex)
          Updates the cell at the specified row and column index.
 void updateCell(int firstRow, int lastRow, int firstColumn, int lastColumn)
          Updates the cell at the specified row and column index.
 void updateRow()
          Updates the data row at the specified current row index.
 void updateRow(int rowIndex)
          Updates the data row at the specified row index.
 void updateRow(int firstRow, int lastRow)
          Updates the data row from firstRow to lastRow
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHANGE_CELL

public static final int CHANGE_CELL
Identifies the update or insert policy. Update or insert the row when change the cell value.

See Also:
acceptChanges(), Constant Field Values

CHANGE_ROW

public static final int CHANGE_ROW
Identifies the update or insert policy. Update or insert the row when change the row index.

See Also:
acceptChanges(), Constant Field Values

CHANGE_PAGE

public static final int CHANGE_PAGE
Identifies the update or insert policy. Update or insert the row when change the page index.

See Also:
acceptChanges(), Constant Field Values

OFF

public static final int OFF
Identifies the update or insert policy. The will disable the auto update or insert mode

See Also:
acceptChanges(), Constant Field Values

UNKNOWN_COUNT

public static final int UNKNOWN_COUNT
Identifies the unknown for page or all row count.

See Also:
getPageCount(), getAllRowCount(), Constant Field Values

changeSupport

protected SwingPropertyChangeSupport changeSupport
If any PropertyChangeListeners have been registered, the changeSupport field describes them.

Constructor Detail

ResultSetTableModel

public ResultSetTableModel()
Empty ResultSetTableModel

Since:
JDataTable 1.1

ResultSetTableModel

public ResultSetTableModel(String sql,
                           String url,
                           String username,
                           String password)
Constructs a ResultSetTableModel with a SQL query command.

Parameters:
sql - the SQL command
url - the JDBC url for connection
username - the user name for connection
password - the password for connection
Since:
JDataGrid 1.3

ResultSetTableModel

public ResultSetTableModel(String sql,
                           String url,
                           String username,
                           String password,
                           int pageSize)
Constructs a ResultSetTableModel with a SQL query command.

Parameters:
sql - the SQL command
url - the JDBC url for connection
username - the user name for connection
password - the password for connection
pageSize - the page size for the record
Since:
JDataGrid 1.3

ResultSetTableModel

public ResultSetTableModel(String sql,
                           String url,
                           String username,
                           String password,
                           boolean sync)
Constructs a ResultSetTableModel with a SQL query command.

Parameters:
sql - the SQL command
url - the JDBC url for connection
username - the user name for connection
password - the password for connection
sync - the synchronized flag
Since:
JDataGrid 1.3

ResultSetTableModel

public ResultSetTableModel(String sql,
                           String url,
                           String username,
                           String password,
                           boolean sync,
                           int pageSize)
Constructs a ResultSetTableModel with a SQL query command.

Parameters:
sql - the SQL command
url - the JDBC url for connection
username - the user name for connection
password - the password for connection
sync - the synchronized flag
pageSize - the page size for the record
Since:
JDataGrid 1.3

ResultSetTableModel

public ResultSetTableModel(ResultSet rs)
Constructs a ResultSetTableModel with a rs.

Parameters:
rs - the ResultSet

ResultSetTableModel

public ResultSetTableModel(ResultSet rs,
                           boolean sync)
Constructs a ResultSetTableModel with a rs.

Parameters:
rs - the ResultSet
sync - the synchronized flag

ResultSetTableModel

public ResultSetTableModel(ResultSet rs,
                           int pageSize)
Constructs a ResultSetTableModel with a rs.

Parameters:
rs - the ResultSet
pageSize - the page size for the record
Since:
JDataGrid 1.3

ResultSetTableModel

public ResultSetTableModel(ResultSet rs,
                           boolean sync,
                           int pageSize)
Constructs a ResultSetTableModel with a rs.

Parameters:
rs - the ResultSet
sync - the synchronized flag
pageSize - the page size for the record
Since:
JDataGrid 1.3
Method Detail

close

public void close()
Close the database connection.

Since:
JDataGrid 1.5

setUrl

public void setUrl(String url)
Sets the url.

Parameters:
url - the url
Since:
JDataGrid 1.3

getUrl

public String getUrl()
Returns the url.

Returns:
the url
Since:
JDataGrid 1.3

setUsername

public void setUsername(String username)
Sets the user name.

Parameters:
username -
Since:
JDataGrid 1.3

getUsername

public String getUsername()
Returns the user name.

Returns:
the user name
Since:
JDataGrid 1.3

setPassword

public void setPassword(String password)
Sets the password

Parameters:
password - the password
Since:
JDataGrid 1.3

getPassword

public String getPassword()
Returns the password

Returns:
the password
Since:
JDataGrid 1.3

setCommand

public void setCommand(String sql)
Sets the command.

Parameters:
sql - the SQL command
Since:
JDataGrid 1.3

getCommand

public String getCommand()
Returns the command.

Returns:
the SQL command
Since:
JDataGrid 1.3

getCountCommand

public String getCountCommand()
Since:
JDataGrid 2.5.0

setCountCommand

public void setCountCommand(String countCommand)
Since:
JDataGrid 2.5.0

reload

public void reload()
Reloads all record from database.

Specified by:
reload in interface Reloadable

getPageSize

public int getPageSize()
Returns the page size.

Specified by:
getPageSize in interface Pageable
Returns:
the page size
Since:
JDataGrid 1.3

getPageCount

public int getPageCount()
Returns the page count.

Specified by:
getPageCount in interface Pageable
Returns:
the page count
Since:
JDataGrid 1.3

setPageIndex

public void setPageIndex(int pageIndex)
Sets the page index.

Specified by:
setPageIndex in interface Pageable
Parameters:
pageIndex - the page index
Since:
JDataGrid 1.3
See Also:
getPageIndex()

getPageIndex

public int getPageIndex()
Returns the current page index.

Specified by:
getPageIndex in interface Pageable
Returns:
the page index
Since:
JDataGrid 1.3
See Also:
setPageIndex(int)

nextPage

public void nextPage()
Show the next page.

Specified by:
nextPage in interface Pageable
Since:
JDataGrid 1.3

previousPage

public void previousPage()
Show the previous page.

Specified by:
previousPage in interface Pageable
Since:
JDataGrid 1.3

hasNextPage

public boolean hasNextPage()
Specified by:
hasNextPage in interface Pageable

hasPreviousPage

public boolean hasPreviousPage()
Specified by:
hasPreviousPage in interface Pageable

firstPage

public void firstPage()
Specified by:
firstPage in interface Pageable

lastPage

public void lastPage()
Specified by:
lastPage in interface Pageable

isFirstPage

public boolean isFirstPage()
Specified by:
isFirstPage in interface Pageable

isLastPage

public boolean isLastPage()
Specified by:
isLastPage in interface Pageable

setRowIndex

public void setRowIndex(int rowIndex)
Sets the row index.

Parameters:
rowIndex - the row index
Since:
JDataGrid 1.3
See Also:
getRowIndex()

getRowIndex

public int getRowIndex()
Returns the current row index.

Returns:
the row index
Since:
JDataGrid 1.3
See Also:
setRowIndex(int)

getFirstRowIndex

public int getFirstRowIndex()
Returns the first row index in current page.

Returns:
the first row index
Since:
JDataGrid 1.3

getAllRowCount

public int getAllRowCount()
Returns all row count.

Note:This is different with getRowCount when use page mode.

Specified by:
getAllRowCount in interface Pageable
Returns:
all row count in the result set
Since:
JDataGrid 1.3

setAllRowCount

public void setAllRowCount(int allRowCount)
Parameters:
allRowCount -
Since:
JDataGrid 2.5.0

getCurrentAllRowCount

public int getCurrentAllRowCount()
Since:
JDataGrid 2.5.0

nextRow

public void nextRow()
Goto the next row.

Since:
JDataGrid 1.3

lastRow

public void lastRow()
Goto the last row.

Since:
JDataGrid 1.3

previousRow

public void previousRow()
Goto the previous row.

Since:
JDataGrid 1.3

firstRow

public void firstRow()
Goto the fist row.

Since:
JDataGrid 1.3

setAutoUpdatePolicy

public void setAutoUpdatePolicy(int updatePolicy)
Sets the auto update policy.
One of 4 legal values:

Parameters:
updatePolicy - the update policy
Since:
JDataGrid 1.3
See Also:
acceptChanges()

getAutoUpdatePolicy

public int getAutoUpdatePolicy()
Returns the auto update policy.
One of 4 legal values:

Returns:
the update policy
Since:
JDataGrid 1.4
See Also:
acceptChanges()

setAutoInsertPolicy

public void setAutoInsertPolicy(int insertPolicy)
Sets the auto insert policy.
One of 4 legal values:

Parameters:
insertPolicy - the insert policy
Since:
JDataGrid 1.3
See Also:
acceptChanges()

getAutoInsertPolicy

public int getAutoInsertPolicy()
Returns the auto insert policy.
One of 4 legal values:

Returns:
the insert policy
Since:
JDataGrid 1.4
See Also:
acceptChanges()

setTableName

public void setTableName(String tableName)
Sets the table name for updating.

Parameters:
tableName - the table name for updating
Since:
JDataGrid 1.4
See Also:
getTableName()

getTableName

public String getTableName()
Returns the table name for updating.

Returns:
the table name for updating
Since:
JDataGrid 1.4
See Also:
setTableName(java.lang.String)

setKeyColumns

public void setKeyColumns(int[] keyColumns)
Sets the primary key columns.

Parameters:
columns - the primary columns
Since:
JDataGrid 1.4
See Also:
getKeyColumns()

getKeyColumns

public int[] getKeyColumns()
Returns the primary key columns.

Returns:
the primary key columns
Since:
JDataGrid 1.4
See Also:
setKeyColumns(int[])

updateCell

public void updateCell(int rowIndex,
                       int columnIndex)
Updates the cell at the specified row and column index.

Parameters:
rowIndex - the data row index
columnIndex - the data column index
Since:
JDataGrid 1.3

refreshCell

public void refreshCell(int rowIndex,
                        int columnIndex)
Refreshs the cell at the specified row and column index.

Parameters:
rowIndex - the data row index
columnIndex - the data column index
Since:
JDataGrid 1.3

updateCell

public void updateCell(int firstRow,
                       int lastRow,
                       int firstColumn,
                       int lastColumn)
Updates the cell at the specified row and column index.

Parameters:
firstRow - the first row index of the specified cell area
lastRow - the last row index of the specified cell area
firstColumn - the first column index of the specified cell area
lastColumn - the last column index of the specified cell area
Since:
JDataGrid 1.3

refreshCell

public void refreshCell(int firstRow,
                        int lastRow,
                        int firstColumn,
                        int lastColumn)
Refreshs the cell at the specified row and column index.

Parameters:
firstRow - the first row index of the specified cell area
lastRow - the last row index of the specified cell area
firstColumn - the first column index of the specified cell area
lastColumn - the last column index of the specified cell area
Since:
JDataGrid 1.3

updateRow

public void updateRow()
Updates the data row at the specified current row index.

Since:
JDataGrid 1.3

updateRow

public void updateRow(int rowIndex)
Updates the data row at the specified row index.

Parameters:
rowIndex - the row index
Since:
JDataGrid 1.3

updateRow

public void updateRow(int firstRow,
                      int lastRow)
Updates the data row from firstRow to lastRow

Parameters:
firstRow - the first row index
lastRow - the last row index
Since:
JDataGrid 1.3

deleteRow

public void deleteRow()
Deletes the data row at the specified current row index.

Since:
JDataGrid 1.3

deleteRow

public void deleteRow(int rowIndex)
Deletes the data row at the specified row index.

Parameters:
rowIndex - the row index
Since:
JDataGrid 1.3

deleteRow

public void deleteRow(int firstRow,
                      int lastRow)
Deletes the data row from firstRow to lastRow

Parameters:
firstRow - the first row index
lastRow - the last row index
Since:
JDataGrid 1.3

refreshRow

public void refreshRow()
Refreshs the data row at the specified current row index.

Since:
JDataGrid 1.3

refreshRow

public void refreshRow(int rowIndex)
Refreshs the data row at the specified row index.

Parameters:
rowIndex - the row index
Since:
JDataGrid 1.3

refreshRow

public void refreshRow(int firstRow,
                       int lastRow)
Refreshs the data row from firstRow to lastRow

Parameters:
firstRow - the first row index
lastRow - the last row index
Since:
JDataGrid 1.3

modelToDataRow

public int modelToDataRow(int modelRow)
Converts the model row index to the ResultSet row index.

Parameters:
modelRow - the mode row index
Returns:
the ResultSet row index for the specified model row index
Since:
JDataGrid 1.3

insertRow

public void insertRow()
Inserts the data row.

Since:
JDataGrid 1.4

moveToInsertRow

public void moveToInsertRow()
Move the cursor to the insert row.

Since:
JDataGrid 1.8

dataToModelRow

public int dataToModelRow(int dataRow)
Converts the ResultSet row index to the model row index.

Parameters:
dataRow - the data row index
Returns:
the model index for the specified ResultSet row index
Since:
JDataGrid 1.3

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface Pageable
Specified by:
getRowCount in interface TableModel

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface TableModel

getColumnName

public String getColumnName(int columnIndex)
Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel

getColumnClass

public Class getColumnClass(int columnIndex)
Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel

getValueAt

public Object getValueAt(int rowIndex,
                         int columnIndex)
Specified by:
getValueAt in interface TableModel

setValueAt

public void setValueAt(Object aValue,
                       int rowIndex,
                       int columnIndex)
Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel

acceptChanges

public void acceptChanges()
Propagates all row update, insert and delete changes to the underlying data source.

Since:
JDataTableBean 1.7

firePropertyChange

protected void firePropertyChange(String propertyName,
                                  int oldValue,
                                  int newValue)

firePropertyChange

protected void firePropertyChange(String propertyName,
                                  Object oldValue,
                                  Object newValue)
Supports reporting bound property changes. This method can be called when a bound property has changed and it will send the appropriate PropertyChangeEvent to any registered PropertyChangeListeners.


addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list. The listener is registered for all properties.

A PropertyChangeEvent will get fired in response to setting a bound property, e.g. setFont, setBackground, or setForeground. Note that if the current component is inheriting its foreground, background, or font from its container, then no event will be fired in response to a change in the inherited property.

Parameters:
listener - The PropertyChangeListener to be added
See Also:
Action#addPropertyChangeListener

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

Parameters:
listener - the PropertyChangeListener to be removed
See Also:
Action#removePropertyChangeListener

getPropertyChangeListeners

public PropertyChangeListener[] getPropertyChangeListeners()
Returns an array of all the PropertyChangeListeners added to this ResultSetTableModel with addPropertyChangeListener().

Returns:
all of the PropertyChangeListeners added or an empty array if no listeners have been added

JComponentPack 1.5.0

Send your Feedback
JComponentPack 1.5.0
Copyright © 2001-2007 Extreme Component, Inc. All rights reserved.