JClass DesktopViews 6.3.0 API
Documentation

com.klg.jclass.datasource
Class BaseDataTable

java.lang.Object
  |
  +--javax.swing.tree.DefaultMutableTreeNode
        |
        +--com.klg.jclass.datasource.DataSourceTreeNode
              |
              +--com.klg.jclass.datasource.BaseDataTable
All Implemented Interfaces:
Cloneable, DataTableAbstractionLayer, DataTableModel, MutableTreeNode, Serializable, TreeNode
Direct Known Subclasses:
DataTable, IdeDataTable

public class BaseDataTable
extends DataSourceTreeNode
implements DataTableModel, DataTableAbstractionLayer

This class provides a default implementation of DataTableModel and DataTableAbstractionLayer interfaces.

Instances of this class provide basic storage, retrieval and manipulation operations on data rows.

This class can be used without extending it. In this case you must create and populate rows "manually". For example,


     BaseDataTable root = new BaseDataTable(rootMetaData);
     data_tree.setRoot((TreeNode) root);
     int row1 = root.addRow();
     root.updateCell(row1, column1, value1);
     root.updateCell(row1, column2, value2); // etc ...
 
Extensions of this class, for example the JClass DataSource jdbc implementation, "automatically" creates/populates data tables based on data returned from datasource queries.

In the case of ide-specific implementaions, they extend this class and override the data storage and retrieval mechanisms.

Users wishing to extend this class should look at overriding some or all of the methods defined in the DataTableAbstractionLayer interface. These are the methods most likely to need overriding.

Each instance of this class has its own cursor which can be navigated independently of the DataModel's global cursor. Only the global cursor (controlled by DataModel.moveToRow) causes commits to occur when the current row is changed. The navigation methods here do not cause the global cursor to change, only this table's private cursor.

See Also:
first(), last(), next(), previous(), beforeFirst(), afterLast(), isAfterLast(), isBeforeFirst(), relative(int), absolute(int), getCurrentBookmark(), DataModel.moveToRow(com.klg.jclass.datasource.DataModelListener, com.klg.jclass.datasource.DataTableModel, long), Serialized Form

Field Summary
protected static long bookmark
           
protected  String currentColumn
           
protected  int cursor
           
protected  Vector eventQueue
           
protected  int initialHashtableSize
           
protected  Hashtable insertedRows
           
protected  Hashtable internalData
           
protected  Hashtable logicallyDeletedRows
           
protected  com.klg.jclass.datasource.MetaDataModel metaData
           
protected  long parentRow
           
protected  Hashtable[] rowCaches
           
protected  Hashtable rowIndexBeforeEvent
           
protected  com.klg.jclass.datasource.StoreModel store
           
protected  Hashtable updatedRows
           
protected  Hashtable userData
           
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Fields inherited from interface com.klg.jclass.datasource.DataTableModel
COMMITTED, CURSOR_BEFORE_FIRST, DELETED, INSERTED, NONEXISTENT, ROOT_BOOKMARK, ROW_NOT_FOUND, UPDATED
 
Constructor Summary
BaseDataTable(com.klg.jclass.datasource.MetaDataModel metaData)
          Root level constructor.
BaseDataTable(com.klg.jclass.datasource.MetaDataModel metaData, long parentRow)
          Constructor to call after root-level BaseDataTable has been created.
 
Method Summary
 void absolute(int ordinal_position)
          Move the cursor to this ordinal position.
 long addInternalRow(Object row)
          Adds an internal row appending it to the end of the in-memory data store.
 long addInternalRow(Object row, int ordinal)
          Adds an internal row inserting it into ordinal position in the in-memory data store.
 long addRow(com.klg.jclass.datasource.DataModelListener originator)
          Adds a row whose status will be INSERTED.
 long addRow(com.klg.jclass.datasource.DataModelListener originator, Object row)
          Adds a populated row whose status will be INSERTED.
 long addRow(com.klg.jclass.datasource.DataModelListener originator, Object row, int status)
          Adds a populated row whose status will be 'status'.
 long addRow(com.klg.jclass.datasource.DataModelListener originator, Object row, int status, int ordinal)
          Adds a populated row whose status will be 'status'.
 void afterLast()
          Position the cursor after the last row.
 void beforeFirst()
          Position the cursor before the first row.
 void cancelAllRowChanges(com.klg.jclass.datasource.DataModelListener originator)
          Cancels all uncommited rows.
 void cancelChanges(com.klg.jclass.datasource.DataModelListener originator, long bookmark)
          Internal method, do not use.
 void cancelRowChanges(com.klg.jclass.datasource.DataModelListener originator, long bookmark)
          Cancels uncommited row changes.
 void clearEventQueue()
          Recursively clear pending events from a transaction.
 Object cloneRow(long bookmark)
          For internal use only.
 boolean columnModified(long bookmark, String col_id)
          Returns true if a column value has been modified.
 void commitAll(com.klg.jclass.datasource.DataModelListener originator)
          Commits all uncommited rows.
 boolean commitRow(com.klg.jclass.datasource.DataModelListener originator, long bookmark)
          Commits the row.
 void commitSubTree(com.klg.jclass.datasource.DataModelListener originator, long subTreeRootBookmark)
          Commit all pending changes in this subtree including this row.
 void conditionallyCommitYourselfAndChildren(com.klg.jclass.datasource.DataModelListener originator)
          Recurse on this node and each of its children and commit all changes in each if commitPolicy does not equal COMMIT_MANUALLY commitAll does not check commit policy before committing.
static com.klg.jclass.datasource.DataTableModel createDataTableModelFromProviderData(com.klg.jclass.datasource.MetaDataModel metaData, long parentRow, Object[][] data)
          Build a DataTableModel from the matrix returned the the ProviderModel.
 Object createNewRow()
          Creates a new row, called by addRow().
 com.klg.jclass.datasource.DataTableModel createTable(com.klg.jclass.datasource.DataModelListener originator, long bookmark, TreeNode child)
          Creates and returns the DataTable which corresponds to the specifed row of this parent for the indicated child MetaData object.
 void deleteCacheChildren(com.klg.jclass.datasource.DataModelListener originator)
          Deletes the subtree of DataTables with this DataTable as its root, as well as itself.
 void deleteRow(com.klg.jclass.datasource.DataModelListener originator, long bookmark)
          Deletes a row.
 boolean fireDataModelEvent(com.klg.jclass.datasource.DataModelEvent event)
          Lets listeners of the data model know this table has changed.
 boolean fireOriginatorDataModelEvent(com.klg.jclass.datasource.DataModelEvent event)
          Fire this event only to the originator.
 boolean first()
          Position this table's cursor on the first row.
 void getAncestors(Vector ancestors)
          Returns a list of this DataTable's ancestor bookmarks.
 Object getCell(long bookmark, String col_id)
          For internal use only.
 long getCurrentBookmark()
          Returns the bookmark of the current row.
 int getCursor()
          Gets the cursor of the data table.
 Object getDeletedRow(long bookmark)
          Return the logically deleted row.
 long[] getDeletedRowBookmarks()
          Retrun a long array of logically deleted row bookmarks.
 long[] getInsertedRowBookmarks()
          Return a long array of inserted row bookmarks.
 Object getInternalData(Object user)
          For internal use only.
 com.klg.jclass.datasource.MetaDataModel getMetaData()
          Returns the MetaData for this DataTable.
protected  long getNextBookmark()
          Returns the next unique row identifier.
 Object getOriginalRow(long bookmark)
          Given a bookmark, returns the original row as it was before any changes where made.
 long getParentBookmark()
          Returns the bookmark of the parent row for this table.
 Object getResultData(long bookmark, String col_id)
          Returns a value for a given row/column.
 long getRootAncestorBookmark(long bookmark)
          Recurses up the tree and determines the row number of the ultimate ancestor.
 int getRowCount()
          Returns the number of rows in this DataTable.
 Object getRowFromCache(long bookmark)
          Returns a row Object from the store.
 long getRowIdentifier(int row_index)
          Returns an int which will uniquely identify this row.
 int getRowIndex(long bookmark)
          Given a bookmark, return the zero-relative row index in this table
 int getRowStatus(long bookmark)
          Returns the status of a row, and will be one of INSERTED, UPDATED, DELETED, COMMITTED, NONEXISTENT.
 com.klg.jclass.datasource.DataTableModel getTable(long bookmark, TreeNode node)
          Searches the existing children of this node for a child node which matches the input criteria.
 long[] getUpdatedRowBookmarks()
          Return a long array of updated row bookmarks.
 Object getUserData(Object user)
          Gets user data.
 boolean hasValueChanged(Object newValue, Object oldValue)
          Return true if the newValue is different than the oldValue
 boolean isAfterLast()
          Return true if the cursor is positioned afte the last row.
 boolean isBeforeFirst()
          Return true if the cursor is positioned before first row.
 boolean isModified()
          Does this DataTableModel contain any pending inserts, updates or deletes?
 boolean isSubTreeModified(long subTreeRootBookmark)
          Does the subtree rooted at subTreeRootBookmark contain modified nodes? Modified means this row or at least one of its child nodes has pending insert, update or delete changes.
 boolean isTableOrChildrenModified()
          Are there any modifications to this table or any of its child nodes?
 boolean last()
          Positions this table's cursor on the last row.
 com.klg.jclass.datasource.DataTableModel materializeTable(com.klg.jclass.datasource.DataModelListener originator, long bookmark, TreeNode node)
          Called by DataTableModel.createTable to create a new table based on the input criteria.
 void moveCursorToRow(long bookmark)
          Move the cursor to the row indicated by the bookmark.
 void moveToRow(long bookmark)
          For internal use only.
 boolean next()
          Advances the cursor by one row.
 boolean originalCellWasNull(int idx, Vector columns, Object[] original_row)
          Returns true if the original cell value is null.
 boolean prepareCellUpdate(com.klg.jclass.datasource.DataModelListener originator, long bookmark, String column_id)
          If column is not in logically deleted row, and is not a virtual column and permissions on its table don't disallow edits and no listeners cancel this event, return true, false otherwise.
 boolean previous()
          Positions this table's cursor to the previous row.
 void processEventQueue(com.klg.jclass.datasource.DataModelListener originator)
          Recursive flushing of pending events from a transaction.
protected  boolean recursivelyDeleteChildren(com.klg.jclass.datasource.BaseDataTable node, com.klg.jclass.datasource.DataModelListener originator)
          Checks recursively to determine if any listener objects to the deletion of the passed subtree.
 void refreshRow(long bookmark)
          Re-reads a row from the originating data source.
 void relative(int rows)
          Move the cursor forward or backward by "n" rows from the current position.
 void removeRowFromInsertedTable(long bookmark)
          Removes a row from the insertedRows table.
protected  void removeRowFromLogicallyDeletedTable(long bookmark)
          Removes a row from the logicallyDeletedRows table.
protected  void removeRowFromOriginalRowTable(long bookmark)
          Removes a row from the originalRow cache table.
 void removeRowFromUpdatedTable(long bookmark)
          Removes a row from the updatedRows table.
 com.klg.jclass.datasource.DataTableModel requeryLevel()
          Requeries the data for the root level DataTable.
 void requeryRow(com.klg.jclass.datasource.DataModelListener originator, long bookmark)
          Re-reads a row from the originating data source.
 void requeryRowAndDetails(com.klg.jclass.datasource.DataModelListener originator, long bookmark)
          Requeries a DataTable row and deletes all children from the cache.
 void requeryTable(com.klg.jclass.datasource.DataModelListener originator)
          Requery all rows in this table and collapse its child nodes.
 void restoreRow(long bookmark)
          For internal use only.
 void saveRow(long bookmark)
          Saves row changes to originating data source.
 void setInternalData(Object user, Object data)
          For internal use only.
 void setRowDirty(long bookmark)
          Clone the row and add it to the table of updated rows so its status will now be UPDATED, but only if the row is not already in the INSERTED table.
 void setUserData(Object user, Object data)
          Sets user data.
 void setValueAt(long bookmark, String col_id, Object value)
          For internal use only.
 boolean tableIsAncestor(com.klg.jclass.datasource.DataTableModel table)
          Given a DataTable, returns whether it is an ancestor of (or equal to) itself
 void updateCell(com.klg.jclass.datasource.DataModelListener originator, long bookmark, String column_id, Object value)
          Updates a cell.
 
Methods inherited from class com.klg.jclass.datasource.DataSourceTreeNode
getChildren, getFirstChild, getIterator, getIterator, getIterator, getIterator, getLastChild, getNextChild, getPreviousChild, hasChildren, insert, isChildOf, toString
 
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, children, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstLeaf, getIndex, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

metaData

protected com.klg.jclass.datasource.MetaDataModel metaData

parentRow

protected long parentRow

store

protected com.klg.jclass.datasource.StoreModel store

initialHashtableSize

protected int initialHashtableSize

updatedRows

protected Hashtable updatedRows

insertedRows

protected Hashtable insertedRows

rowIndexBeforeEvent

protected Hashtable rowIndexBeforeEvent

rowCaches

protected Hashtable[] rowCaches

cursor

protected int cursor

logicallyDeletedRows

protected Hashtable logicallyDeletedRows

userData

protected Hashtable userData

internalData

protected Hashtable internalData

eventQueue

protected Vector eventQueue

bookmark

protected static long bookmark

currentColumn

protected String currentColumn
Constructor Detail

BaseDataTable

public BaseDataTable(com.klg.jclass.datasource.MetaDataModel metaData)
Root level constructor. Should be called only once to set the data table which will be the root of the data table tree. Subsequent nodes should be created using the constructor below.

Parameters:
metaData - the MetaDataModel which provides the column structure for this data table.

BaseDataTable

public BaseDataTable(com.klg.jclass.datasource.MetaDataModel metaData,
                     long parentRow)
Constructor to call after root-level BaseDataTable has been created. These tables will be sub-root level nodes in the data table tree.

Parameters:
metaData - the MetaDataModel which provides the column structure for this data table.
parentRow - an int indicating to which parent bookmark this data table relates.
Method Detail

getRowCount

public int getRowCount()
Returns the number of rows in this DataTable.

Specified by:
getRowCount in interface DataTableModel
Returns:
the number of rows in this table

getRowStatus

public int getRowStatus(long bookmark)
Returns the status of a row, and will be one of INSERTED, UPDATED, DELETED, COMMITTED, NONEXISTENT.

Specified by:
getRowStatus in interface DataTableModel
Parameters:
bookmark - a unique long indicating for which row status should be retrieved
Returns:
an int indicating one of INSERTED, UPDATED, DELETED,COMMITTED, or NONEXISTENT.

getRowIdentifier

public long getRowIdentifier(int row_index)
Returns an int which will uniquely identify this row. Facilitates sorting: index changes, identifier remains constant.

Specified by:
getRowIdentifier in interface DataTableModel
Returns:
a bookmark a unique long to identify this row from now on

getResultData

public Object getResultData(long bookmark,
                            String col_id)
                     throws DataModelException
Returns a value for a given row/column.

Specified by:
getResultData in interface DataTableModel
Parameters:
bookmark - a unique long representing a row
col_id - a unique String representing a column
Returns:
Object which is the value at bookmark/column_identifier
Throws:
DataModelException - If get fails.

createTable

public com.klg.jclass.datasource.DataTableModel createTable(com.klg.jclass.datasource.DataModelListener originator,
                                                            long bookmark,
                                                            TreeNode child)
                                                     throws DataModelException
Creates and returns the DataTable which corresponds to the specifed row of this parent for the indicated child MetaData object. Always returns a non-null DataTable. Creates new bookmarks for all returned rows. Calls getTable and returns the existing table if one exists, otherwise the table is created.

To provide data you can either subclass this class and override this method to return a DataTableModel, or you can set the ProviderModel for this table's MetaDataModel. The creation of data is then delegated to this class. If set, this method calls that class.

Specified by:
createTable in interface DataTableModel
Parameters:
originator - the DataModelListener which initiated this action
bookmark - a long which uniquely identifies a row
child - the MetaDataModel object which will drive the next query
Returns:
the child DataTableModel of results
Throws:
DataModelException - If createTable() fails.
See Also:
getTable(long, javax.swing.tree.TreeNode)

createDataTableModelFromProviderData

public static com.klg.jclass.datasource.DataTableModel createDataTableModelFromProviderData(com.klg.jclass.datasource.MetaDataModel metaData,
                                                                                            long parentRow,
                                                                                            Object[][] data)
Build a DataTableModel from the matrix returned the the ProviderModel.


getTable

public com.klg.jclass.datasource.DataTableModel getTable(long bookmark,
                                                         TreeNode node)
Searches the existing children of this node for a child node which matches the input criteria. Returns that node if it exists, null otherwise.

Specified by:
getTable in interface DataTableModel
Parameters:
bookmark - a long which uniquely identifies a row
Returns:
the DataTable with matching bookmark and MetaDataModel otherwise, null.
See Also:
createTable(com.klg.jclass.datasource.DataModelListener, long, javax.swing.tree.TreeNode)

getMetaData

public com.klg.jclass.datasource.MetaDataModel getMetaData()
Returns the MetaData for this DataTable.

Specified by:
getMetaData in interface DataTableModel
Returns:
MetaData associated with this DataTable

getParentBookmark

public long getParentBookmark()
Returns the bookmark of the parent row for this table. This is the immediate parent of this table.

Specified by:
getParentBookmark in interface DataTableModel
Returns:
the bookmark of the parent row for this DataTable
See Also:
getRootAncestorBookmark(long), getAncestors(java.util.Vector)

addRow

public long addRow(com.klg.jclass.datasource.DataModelListener originator)
            throws DataModelException
Adds a row whose status will be INSERTED. Adds a blank row into which the user can input column data. The record is appended to this ResultSet. The record is saved to datasource when the user commits the surrounding transaction.

Fires BEFORE_INSERT_ROW and upon a successful row add AFTER_INSERT_ROW.

Specified by:
addRow in interface DataTableModel
Parameters:
originator - the DataModelListener which initiated this action
Throws:
DataModelException - If row fails to be added.

addRow

public long addRow(com.klg.jclass.datasource.DataModelListener originator,
                   Object row,
                   int status)
            throws DataModelException
Adds a populated row whose status will be 'status'. Adds a pre-populated row whose status is dictated by the 'status' parameter.

Fires BEFORE_INSERT_ROW and upon a successful row add AFTER_INSERT_ROW.

Specified by:
addRow in interface DataTableModel
Parameters:
row - an Object as defined by the interface, but used as an array by this implementation.
status - an int, one of,
  • DataTableModel.COMMITTED
  • DataTableModel.DELETED
  • DataTableModel.INSERTED
Throws:
DataModelException - If row fails to be added.

addRow

public long addRow(com.klg.jclass.datasource.DataModelListener originator,
                   Object row,
                   int status,
                   int ordinal)
            throws DataModelException
Adds a populated row whose status will be 'status'. Adds a pre-populated row whose status is dictated by the 'status' parameter.

Fires BEFORE_INSERT_ROW and upon a successful row add AFTER_INSERT_ROW.

Specified by:
addRow in interface DataTableModel
Parameters:
row - an Object as defined by the interface, but used as an array by this implementation.
status - an int, one of,
  • DataTableModel.COMMITTED
  • DataTableModel.DELETED
  • DataTableModel.INSERTED
ordinal - the index position into which the row should be inserted
Throws:
DataModelException - If row fails to be added.

addRow

public long addRow(com.klg.jclass.datasource.DataModelListener originator,
                   Object row)
            throws DataModelException
Adds a populated row whose status will be INSERTED. Adds a pre-populated row. The record is appended to this ResultSet. The record is saved to datasource when the user commits the surrounding transaction.

Fires BEFORE_INSERT_ROW and upon a successful row add AFTER_INSERT_ROW.

Specified by:
addRow in interface DataTableModel
Parameters:
originator - the DataModelListener which initiated this action
row - an Object as defined by the interface, but used as an array by this implementation.
Throws:
DataModelException - If row fails to be added.

deleteRow

public void deleteRow(com.klg.jclass.datasource.DataModelListener originator,
                      long bookmark)
               throws DataModelException
Deletes a row. Depending upon the commit policy the row will either be immediately and permanently deleted from the view and the datasource (commit policy == COMMIT_LEAVING_RECORD), or will simply be logically deleted.

In the case of a logical delete, if the showDeletedRows has been set to false, the row will disappear from the display. It will be deleted permanently upon commit, or restored on cancel or requery. The default is for logically deleted rows to be shown.

Any pending changes to the row are automatically undone before any deletion.

Specified by:
deleteRow in interface DataTableModel
Parameters:
originator - the DataModelListener which initiated this action
bookmark - a unique long indicating the row to be deleted.
Throws:
DataModelException - If the logical delete fails.
See Also:
MetaDataModel.getShowDeletedRows(), MetaDataModel.setShowDeletedRows(boolean), MetaDataModel.setCommitPolicy(int), MetaDataModel.getCommitPolicy()

updateCell

public void updateCell(com.klg.jclass.datasource.DataModelListener originator,
                       long bookmark,
                       String column_id,
                       Object value)
                throws DataModelException
Updates a cell. User has modified a cell. Call this method to inform this data source of that change. This method will then fire a DataTableEvent to inform listeners about this change. getRowStatus() will report this row as UPDATED.

Specified by:
updateCell in interface DataTableModel
Parameters:
originator - the DataModelListener which initiated this action
bookmark - a unique long indicating in which row the change was made
value - the Object to be placed in the cell
column_id - a unique String indicating in which column the change occurred.
Throws:
DataModelException - If a cell update fails.
See Also:
DataTableAbstractionLayer.setValueAt(long, java.lang.String, java.lang.Object)

commitRow

public boolean commitRow(com.klg.jclass.datasource.DataModelListener originator,
                         long bookmark)
                  throws DataModelException
Commits the row. Writes the row (new and/or modified) to datasource. Calls saveRow(), an implmentation specific method to save a row.

Specified by:
commitRow in interface DataTableModel
Parameters:
originator - the DataModelListener which initiated this action
bookmark - a unique long indicating which row to commit to the datasource.
Returns:
true if the commit succeeded, false if failed or was cancelled.
Throws:
DataModelException - If commit fails.
See Also:
saveRow(long)

commitAll

public void commitAll(com.klg.jclass.datasource.DataModelListener originator)
               throws DataModelException
Commits all uncommited rows. Call commitRow for each new and/or modified row in this DataTable.

Specified by:
commitAll in interface DataTableModel
Parameters:
originator - the DataModelListener which initiated this action
Throws:
DataModelException - If commit of any row fails.
See Also:
DataModel.updateAll(com.klg.jclass.datasource.DataModelListener)

conditionallyCommitYourselfAndChildren

public void conditionallyCommitYourselfAndChildren(com.klg.jclass.datasource.DataModelListener originator)
                                            throws DataModelException
Recurse on this node and each of its children and commit all changes in each if commitPolicy does not equal COMMIT_MANUALLY commitAll does not check commit policy before committing.

Specified by:
conditionallyCommitYourselfAndChildren in interface DataTableModel
Parameters:
originator - the DataModelListener which initiated this action
Throws:
DataModelException - If commit fails.

cancelAllRowChanges

public void cancelAllRowChanges(com.klg.jclass.datasource.DataModelListener originator)
                         throws DataModelException
Cancels all uncommited rows. Restore original cell values for each uncommited row, undelete logically deleted rows.

Specified by:
cancelAllRowChanges in interface DataTableModel
Parameters:
originator - the DataModelListener which initiated this action
Throws:
DataModelException - If the changes can't be canceled.

cancelRowChanges

public void cancelRowChanges(com.klg.jclass.datasource.DataModelListener originator,
                             long bookmark)
                      throws DataModelException
Cancels uncommited row changes. Restore original cell values for this row.

Specified by:
cancelRowChanges in interface DataTableModel
Parameters:
originator - the DataModelListener which initiated this action
bookmark - a unique long which identifies this row
Throws:
DataModelException - If the changes can't be canceled.
See Also:
DataTableAbstractionLayer.restoreRow(long), DataTableModel.requeryRow(com.klg.jclass.datasource.DataModelListener, long)

getRootAncestorBookmark

public long getRootAncestorBookmark(long bookmark)
Recurses up the tree and determines the row number of the ultimate ancestor.

Specified by:
getRootAncestorBookmark in interface DataTableModel
Parameters:
bookmark - a unique long for which the ultimate ancestor bookmark is to be determined
Returns:
A long indicating the bookmark of this DataTable's ultimate ancestor.
See Also:
DataTableModel.getAncestors(java.util.Vector)

getAncestors

public void getAncestors(Vector ancestors)
Returns a list of this DataTable's ancestor bookmarks. The list is ordered from the root ancestor down to the node above this one.

Specified by:
getAncestors in interface DataTableModel
Parameters:
ancestors - the Vector to be populated with ancestor bookmarks
Returns:
a Vector of ancestor bookmarks.

requeryRowAndDetails

public void requeryRowAndDetails(com.klg.jclass.datasource.DataModelListener originator,
                                 long bookmark)
                          throws DataModelException
Requeries a DataTable row and deletes all children from the cache. Calls requeryRow(). Refetches all rows in this DataTable from the originating data source and deletes all child nodes from the cache.

Specified by:
requeryRowAndDetails in interface DataTableModel
Parameters:
originator - the DataModelListener which initiated this action
Returns:
this data table model
Throws:
DataModelException - If requery from server fails.
See Also:
requeryRow(com.klg.jclass.datasource.DataModelListener, long)

requeryLevel

public com.klg.jclass.datasource.DataTableModel requeryLevel()
                                                      throws DataModelException
Requeries the data for the root level DataTable. An implementation specific method to requery the root level node.

Specified by:
requeryLevel in interface DataTableModel
Returns:
this data table model
Throws:
DataModelException - If requery from server fails.

first

public boolean first()
Position this table's cursor on the first row.

Specified by:
first in interface DataTableModel

last

public boolean last()
Positions this table's cursor on the last row.

Specified by:
last in interface DataTableModel

next

public boolean next()
Advances the cursor by one row. Returns true if there was a row to move forward to. Otherwise, remains on last row.

Specified by:
next in interface DataTableModel
Returns:
true if move to next row succeeded.

previous

public boolean previous()
Positions this table's cursor to the previous row. Returns true if the move succeeds, false otherwise in which case it will stay on the first row.

Specified by:
previous in interface DataTableModel
Returns:
true if successful, false otherwise.

beforeFirst

public void beforeFirst()
Position the cursor before the first row.

Specified by:
beforeFirst in interface DataTableModel

afterLast

public void afterLast()
Position the cursor after the last row.

Specified by:
afterLast in interface DataTableModel

isBeforeFirst

public boolean isBeforeFirst()
Return true if the cursor is positioned before first row.

Specified by:
isBeforeFirst in interface DataTableModel
Returns:
true if cursor is positioned before first row, false otherwise.

isAfterLast

public boolean isAfterLast()
Return true if the cursor is positioned afte the last row.

Specified by:
isAfterLast in interface DataTableModel
Returns:
true if the cursor is positioned after the last row, false otherwise.
See Also:
DataTableModel.getCurrentBookmark()

relative

public void relative(int rows)
              throws DataModelException
Move the cursor forward or backward by "n" rows from the current position. Positive numbers move forward, negative backwards.

Specified by:
relative in interface DataTableModel
Throws:
DataModelException - If move fails.
See Also:
DataTableModel.getCurrentBookmark()

absolute

public void absolute(int ordinal_position)
              throws DataModelException
Move the cursor to this ordinal position. Ordinal positions start at 1.

Specified by:
absolute in interface DataTableModel
Parameters:
ordinal_position - an int indicating to which row to move
Throws:
DataModelException - If the operation fails.
See Also:
DataTableModel.getCurrentBookmark()

getCurrentBookmark

public long getCurrentBookmark()
                        throws DataModelException
Returns the bookmark of the current row.

Specified by:
getCurrentBookmark in interface DataTableModel
Returns:
the bookmark of the current row.
Throws:
DataModelException - If there are no rows or or an error occurs.
See Also:
DataTableModel.first(), DataTableModel.last(), DataTableModel.next(), DataTableModel.previous(), DataTableModel.beforeFirst(), DataTableModel.afterLast(), DataTableModel.isBeforeFirst(), DataTableModel.isAfterLast(), DataTableModel.relative(int), DataTableModel.absolute(int), DataModel.moveToRow(com.klg.jclass.datasource.DataModelListener, com.klg.jclass.datasource.DataTableModel, long)

getUserData

public Object getUserData(Object user)
Gets user data. Returns the Object which was arbitrarily associated with this table.

Specified by:
getUserData in interface DataTableModel
Parameters:
user - an Object, a reference to the user.
Returns:
the user Object associated with this table.

setUserData

public void setUserData(Object user,
                        Object data)
Sets user data. Allows users to augment this table by associating an arbitrary Object reference with it.

Specified by:
setUserData in interface DataTableModel
Parameters:
user - an Object, a reference to the user.
data - an Object, a reference to an Object.

getInternalData

public Object getInternalData(Object user)
For internal use only. Gets internal data. Return the Object which was arbitrarily associated with this table.

Specified by:
getInternalData in interface DataTableModel
Parameters:
user - an Object, a reference to the user.
Returns:
the internal Object associated with this table.

setInternalData

public void setInternalData(Object user,
                            Object data)
For internal use only. Sets internal data. Allow component writers to augment this table by associating an arbitrary Object reference with it.

Specified by:
setInternalData in interface DataTableModel
Parameters:
user - an Object, a reference to the user.
data - an Object, an arbitrary reference to an Object.

processEventQueue

public void processEventQueue(com.klg.jclass.datasource.DataModelListener originator)
                       throws DataModelException
Recursive flushing of pending events from a transaction.

Specified by:
processEventQueue in interface DataTableModel
Parameters:
originator - the DataModelListener which initiated this action
Throws:
DataModelException - If an exception occurs while flushing events.

clearEventQueue

public void clearEventQueue()
Recursively clear pending events from a transaction. Called when an exception occurs. Events are not dispatched they are simply deleted.

Specified by:
clearEventQueue in interface DataTableModel

moveCursorToRow

public void moveCursorToRow(long bookmark)
                     throws DataModelException
Move the cursor to the row indicated by the bookmark.

Specified by:
moveCursorToRow in interface DataTableModel
Parameters:
bookmark - a long which uniquely identifies a row
Throws:
DataModelException - If cursor move fails.

getCursor

public int getCursor()
Gets the cursor of the data table.

Specified by:
getCursor in interface DataTableModel

getRowIndex

public int getRowIndex(long bookmark)
Given a bookmark, return the zero-relative row index in this table

Specified by:
getRowIndex in interface DataTableModel
Parameters:
bookmark - a long which uniquely identifies a row
Returns:
rowIndex a int which is the ordinal position of the row in this table

deleteCacheChildren

public void deleteCacheChildren(com.klg.jclass.datasource.DataModelListener originator)
                         throws DataModelException
Deletes the subtree of DataTables with this DataTable as its root, as well as itself.

Specified by:
deleteCacheChildren in interface DataTableModel
Parameters:
originator - the DataModelListener which initiated this action
Throws:
DataModelException - If the subtree can't be deleted.
See Also:
MetaDataModel.getCacheChildren()

recursivelyDeleteChildren

protected boolean recursivelyDeleteChildren(com.klg.jclass.datasource.BaseDataTable node,
                                            com.klg.jclass.datasource.DataModelListener originator)
                                     throws DataModelException
Checks recursively to determine if any listener objects to the deletion of the passed subtree.

Parameters:
node - the DataTable to identify the subtree's root
originator - the DataModelListener which initiated this action
Returns:
true if all listeners agreed that all children could be deleted
Throws:
DataModelException - If the subtree can't be deleted.

moveToRow

public void moveToRow(long bookmark)
               throws DataModelException
For internal use only. Move the ide cursor to this row, must be overridden for ide's.

There is only one path from the root to a child node in some subtree. For each meta data level, this method sets the data tables which comprise this path to this table as well as the bookmarks at each level which, when expanded, ultimately lead to this table.

Specified by:
moveToRow in interface DataTableModel
Parameters:
bookmark - a long which uniquely identifies a row.
Throws:
DataModeolException - If move fails.
DataModelException - If move fails.
See Also:
MetaDataModel.getCurrentDataTable(), MetaDataModel.getCurrentBookmark()

isSubTreeModified

public boolean isSubTreeModified(long subTreeRootBookmark)
Does the subtree rooted at subTreeRootBookmark contain modified nodes? Modified means this row or at least one of its child nodes has pending insert, update or delete changes.

Specified by:
isSubTreeModified in interface DataTableModel
Parameters:
subTreeRootBookmark - a long, the bookmark of the row which is the root of the subtree to be checked.
Returns:
true if this subtree contains at least one modified node, false otherwise.

isTableOrChildrenModified

public boolean isTableOrChildrenModified()
Are there any modifications to this table or any of its child nodes?

Specified by:
isTableOrChildrenModified in interface DataTableModel
Returns:
true if there are modifications to this table or any of its child nodes

commitSubTree

public void commitSubTree(com.klg.jclass.datasource.DataModelListener originator,
                          long subTreeRootBookmark)
                   throws DataModelException
Commit all pending changes in this subtree including this row.

Specified by:
commitSubTree in interface DataTableModel
Parameters:
originator - the DataModelListener which initiated this action
subTreeRootBookmark - a long, the bookmark of the row which is the root of the subtree to be checked.
Throws:
DataModelException - If commit fails.

isModified

public boolean isModified()
Does this DataTableModel contain any pending inserts, updates or deletes?

Specified by:
isModified in interface DataTableModel
Returns:
true if there are pending modifications, false otherwise.

getUpdatedRowBookmarks

public long[] getUpdatedRowBookmarks()
Return a long array of updated row bookmarks. These are the rows which have updates pending.

Specified by:
getUpdatedRowBookmarks in interface DataTableModel
Returns:
a long[] of updated row bookmarks

getInsertedRowBookmarks

public long[] getInsertedRowBookmarks()
Return a long array of inserted row bookmarks. These are the rows which are inserted into the data model, but not yet persisted.

Specified by:
getInsertedRowBookmarks in interface DataTableModel
Returns:
a long[] of inserted row bookmarks

getDeletedRowBookmarks

public long[] getDeletedRowBookmarks()
Retrun a long array of logically deleted row bookmarks. These are the rows which are logically deleted, but not yet physically deleted from the originating data source.

Specified by:
getDeletedRowBookmarks in interface DataTableModel
Returns:
a long[] of logically deleted row bookmarks

requeryTable

public void requeryTable(com.klg.jclass.datasource.DataModelListener originator)
                  throws DataModelException
Requery all rows in this table and collapse its child nodes. The default behavior is to call cancelAllRowChanges. This method will need to be overridden to provide custom functionality.

Specified by:
requeryTable in interface DataTableModel
Parameters:
originator - the DataModelListener which initiated this action
Throws:
DataModelException - If requery fails.

cloneRow

public Object cloneRow(long bookmark)
                throws DataModelException
For internal use only. Returns a copy of this row. Used to restore the row when changes are cancelled, or used in the where clause to update the row. Called by updateCell

Specified by:
cloneRow in interface DataTableAbstractionLayer
Parameters:
bookmark - a long uniquely identifying this row.
Returns:
a an Object copy of this row.
Throws:
DataModelException - If clone fails.

setValueAt

public void setValueAt(long bookmark,
                       String col_id,
                       Object value)
                throws DataModelException
For internal use only. Call DataTableModel.updateCell(..) instead. Changes the value of an existing cell. Called by updateCell.

Specified by:
setValueAt in interface DataTableAbstractionLayer
Parameters:
bookmark - a long indicating the row
col_id - a String indicating the column
Throws:
DataModelException - If setValueAt fails.
See Also:
DataTableModel.updateCell(com.klg.jclass.datasource.DataModelListener, long, java.lang.String, java.lang.Object)

restoreRow

public void restoreRow(long bookmark)
For internal use only. Call DataTableModel.cancelRowChanges(..) or DataModel.cancelAll() instead. Restores a row's original values. Called by cancelRowChanges(bookmark). A default implementation which expects a row to be an Object[] array.

Specified by:
restoreRow in interface DataTableAbstractionLayer
Parameters:
bookmark - a long which uniquely identifies a row
See Also:
DataTableModel.cancelRowChanges(com.klg.jclass.datasource.DataModelListener, long), DataModel.cancelAll(com.klg.jclass.datasource.DataModelListener)

createNewRow

public Object createNewRow()
                    throws DataModelException
Creates a new row, called by addRow(). An implementation-specific method for creating a new (blank) row, it must be implemented in the derived class of BaseDataTable.

Specified by:
createNewRow in interface DataTableModel
Returns:
an Object which is the new row just added.
Throws:
DataModelException - If create fails.

refreshRow

public void refreshRow(long bookmark)
                throws DataModelException
Re-reads a row from the originating data source. Called by requeryRow(). An implementation specific method for refetching a row, it must be implemented in the derived class of BaseDataTable.

Specified by:
refreshRow in interface DataTableAbstractionLayer
Parameters:
bookmark - a long which uniquely identifies a row
Throws:
DataModelException - If requery from server fails.
See Also:
DataTableModel.requeryRow(com.klg.jclass.datasource.DataModelListener, long)

saveRow

public void saveRow(long bookmark)
             throws DataModelException
Saves row changes to originating data source. An implementation specific method for writing a row to the data source. Called by commitRow().

Specified by:
saveRow in interface DataTableAbstractionLayer
Parameters:
bookmark - a unique long indicating which row to commit to the datasource.
Throws:
DataModelException - If save fails.
See Also:
DataTableModel.commitRow(com.klg.jclass.datasource.DataModelListener, long)

getCell

public Object getCell(long bookmark,
                      String col_id)
               throws DataModelException
For internal use only. Call DataTableModel.getResultData(..) instead. Returns a value for a given row/column.

Specified by:
getCell in interface DataTableAbstractionLayer
Parameters:
bookmark - a unique long representing a row
col_id - a unique String representing a column
Returns:
an Object which is the value at row/column
Throws:
DataModelException - If get fails.
See Also:
DataTableModel.getResultData(long, java.lang.String)

materializeTable

public com.klg.jclass.datasource.DataTableModel materializeTable(com.klg.jclass.datasource.DataModelListener originator,
                                                                 long bookmark,
                                                                 TreeNode node)
                                                          throws DataModelException
Called by DataTableModel.createTable to create a new table based on the input criteria.

Specified by:
materializeTable in interface DataTableAbstractionLayer
Parameters:
originator - the DataModelListener which initiated this action
bookmark - a long which uniquely identifies a row
node - a MetaDataModel, this tells this table what structure the child table it is creating should have
Throws:
DataModelException - If materializeTable fails.

fireDataModelEvent

public boolean fireDataModelEvent(com.klg.jclass.datasource.DataModelEvent event)
Lets listeners of the data model know this table has changed.

Returns:
true if the action was accepted, false if it was aborted.

fireOriginatorDataModelEvent

public boolean fireOriginatorDataModelEvent(com.klg.jclass.datasource.DataModelEvent event)
Fire this event only to the originator.

Returns:
true if the action was accepted, false if it was aborted.

getNextBookmark

protected long getNextBookmark()
Returns the next unique row identifier.

Returns:
a long to uniquely identify a row across all DataTable instances.

addInternalRow

public long addInternalRow(Object row)
Adds an internal row appending it to the end of the in-memory data store.

THIS METHOD IS NOT INTENDED FOR REGULAR USE. Use addRow() instead. This method is provided as a "back-door" into the datasource and is intended to allow fast population of a datasource during initialization. It does not fire BEFORE_INSERT_ROW nor AFTER_INSERT_ROW nor will the row be flagged as INSERTED.

Parameters:
row - an Object which is the original row.
Returns:
the unique id for this row as a long.

addInternalRow

public long addInternalRow(Object row,
                           int ordinal)
Adds an internal row inserting it into ordinal position in the in-memory data store.

THIS METHOD IS NOT INTENDED FOR REGULAR USE. Use addRow() instead. This method is provided as a "back-door" into the datasource and is intended to allow fast population of a datasource during initialization. It does not fire BEFORE_INSERT_ROW nor AFTER_INSERT_ROW nor will the row be flagged as INSERTED.

Parameters:
row - an Object which is the original row.
ordinal - the index position into which the row should be inserted
Returns:
the unique id for this row as a long.

getRowFromCache

public Object getRowFromCache(long bookmark)
                       throws DataModelException
Returns a row Object from the store.

Parameters:
bookmark - a long uniquely identifying a row.
Returns:
the original row Object from the cache.
Throws:
DataModelException - If row not found in cache.

removeRowFromLogicallyDeletedTable

protected void removeRowFromLogicallyDeletedTable(long bookmark)
Removes a row from the logicallyDeletedRows table. Row has been physically deleted or the delete has been cancelled.

Parameters:
bookmark - a long uniquely identifying a row

removeRowFromUpdatedTable

public void removeRowFromUpdatedTable(long bookmark)
Removes a row from the updatedRows table.

Parameters:
bookmark - a long uniquely identifying a row

removeRowFromInsertedTable

public void removeRowFromInsertedTable(long bookmark)
Removes a row from the insertedRows table.

Parameters:
bookmark - a long uniquely identifying a row

removeRowFromOriginalRowTable

protected void removeRowFromOriginalRowTable(long bookmark)
Removes a row from the originalRow cache table.

Parameters:
bookmark - a long uniquely identifying a row

cancelChanges

public void cancelChanges(com.klg.jclass.datasource.DataModelListener originator,
                          long bookmark)
                   throws DataModelException
Internal method, do not use.

Parameters:
originator - the DataModelListener which initiated this action
bookmark - a long which uniquely identifies a row.
Throws:
DataModelException - If the changes can't be canceled.
See Also:
cancelRowChanges(com.klg.jclass.datasource.DataModelListener, long), deleteRow(com.klg.jclass.datasource.DataModelListener, long), getRowIdentifier(int)

requeryRow

public void requeryRow(com.klg.jclass.datasource.DataModelListener originator,
                       long bookmark)
                throws DataModelException
Re-reads a row from the originating data source. Cancels pending modificatoins to the row, if any. Calls refreshRow(bookmark), which is the implementation specific method to refresh a row.

Specified by:
requeryRow in interface DataTableModel
Parameters:
originator - the DataModelListener which initiated this action
bookmark - a long which uniquely identifies a row
Throws:
DataModelException - If requery from server fails.

originalCellWasNull

public boolean originalCellWasNull(int idx,
                                   Vector columns,
                                   Object[] original_row)
Returns true if the original cell value is null.


columnModified

public boolean columnModified(long bookmark,
                              String col_id)
                       throws DataModelException
Returns true if a column value has been modified.

Parameters:
bookmark - a long uniquely identifying a row
col_id - a unique String representing a column
Returns:
true if this column has been modified.
Throws:
DataModelException - If the operation fails.

hasValueChanged

public boolean hasValueChanged(Object newValue,
                               Object oldValue)
Return true if the newValue is different than the oldValue


getOriginalRow

public Object getOriginalRow(long bookmark)
Given a bookmark, returns the original row as it was before any changes where made.

Parameters:
bookmark - a unique long indicating which row to uncommit
Returns:
the original (unmodified) row

getDeletedRow

public Object getDeletedRow(long bookmark)
Return the logically deleted row.

Parameters:
bookmark - a long which uniquely identifies a row
Returns:
row an Object which is the logically deleted row.

tableIsAncestor

public boolean tableIsAncestor(com.klg.jclass.datasource.DataTableModel table)
Given a DataTable, returns whether it is an ancestor of (or equal to) itself

Specified by:
tableIsAncestor in interface DataTableModel
Parameters:
table - a DataTable which may be an ancestor
Returns:
true if the table is an ancestor

prepareCellUpdate

public boolean prepareCellUpdate(com.klg.jclass.datasource.DataModelListener originator,
                                 long bookmark,
                                 String column_id)
                          throws DataModelException
If column is not in logically deleted row, and is not a virtual column and permissions on its table don't disallow edits and no listeners cancel this event, return true, false otherwise.

Parameters:
originator - the DataModelListener which initiated this action
Throws:
DataModelException - If prepare fails.

setRowDirty

public void setRowDirty(long bookmark)
Clone the row and add it to the table of updated rows so its status will now be UPDATED, but only if the row is not already in the INSERTED table.

Parameters:
bookmark - a long which uniquely identifies a row

Copyright © 2004 Quest Software Inc..
All rights reserved.