harmonic.mz.data
Class TableNode

java.lang.Object
  |
  +--harmonic.mz.data.ModelNode
        |
        +--harmonic.mz.data.TableNode
All Implemented Interfaces:
java.awt.event.ActionListener, DataNode, Documentable, java.util.EventListener, Interpolater, harmonic.meshGeom.math.MarkableObject, NodeListener

public class TableNode
extends ModelNode

For storeing data in a relational database style. The function setColumns() should be called directly upon creation of this class. Then rows may be added and querried.

The following column types are supported:

More efficient storage (an array of primatives) is used if the primative types are specified.

A node serializer must be given for every column of Object type. This is used in creation of XML files.

Note that this table is not ment to keep rows ordered. There are no insert operations to add rows at specific row indicies. Row indicies may change after calles to pack().

Typical use of the table would use one column as a "primary key" for finding out what row index corisponds to a row with a field of a certain value, using selectUniqueRow().

Note on the setting functions: they do not cause value changed events to be sent. The caller must manually call ModelNode.valChanged() after changing all the rows it intends to change.


Field Summary
 
Fields inherited from class harmonic.mz.data.ModelNode
_fileRoot_, _thread_, ATTRIB_CONTROL_WIDGET, ATTRIB_LISTABLE, ATTRIB_PRESENTABLE, ATTRIB_PRIVATE, ATTRIB_REMOVEABLE, ATTRIB_RENAMEABLE, ATTRIB_SHOW_CONTEXT_MENU, ATTRIB_TYPE_FILTER, ATTRIB_USERGROUP, ATTRIB_VALUE_GROUP, ATTRIB_VE_LISTENER, bCustomCS, bDebug, bValid, name
 
Constructor Summary
TableNode()
           
 
Method Summary
 void addColumn(java.lang.Class type, java.lang.String name, NodeSerializer nsa, boolean bTransient)
          Add a column after current last column.
 int addRow()
          Adds a row.
 void allocateRows(int count)
          Build an initial allocation of rows.
 int columnCount()
          Returns number of columns
 int columnIndex(java.lang.String name)
          Returns column index for name.
static boolean compareColumns(TableNode a, int columnA, TableNode b, int columnB)
           
static boolean compareRows(TableNode a, int rowA, TableNode b, int rowB)
          Returns true if rows are the same.
 ModelNode createCopy()
          Overrideable function to create and return a copy of this node Default version uses introspection to create a new copy using the newInstance() function, which requires a no argument public constructor.
 void fromXMLNodes(XMLTransferNode[] xmlNodes)
          Override of ModelNode XML system.
 boolean getBoolean(int iRow, int iColumn)
          Returns boolean value at row index and column index, assuming column is a boolean type A ClassCastException is thrown otherwise.
 java.lang.String getColumnName(int iColumn)
           
 NodeSerializer getColumnSerializer(int iColumn)
           
 boolean getColumnTransientness(int iColumn)
          A transient column will not be saved to files, and can be skipped durring cloning and comparison functions.
 java.lang.Class getColumnType(int iColumn)
           
 boolean getColumnVisibility(int iColumn)
           
 double getDouble(int iRow, int iColumn)
          Returns double value at row index and column index, assuming column is a double type A ClassCastException is thrown otherwise.
 float getFloat(int iRow, int iColumn)
          Returns float value at row index and column index, assuming column is a float type A ClassCastException is thrown otherwise.
 int getInt(int iRow, int iColumn)
          Returns int value at row index and column index, assuming column is a int type A ClassCastException is thrown otherwise.
 long getLong(int iRow, int iColumn)
          Returns long value at row index and column index, assuming column is a long type A ClassCastException is thrown otherwise.
 java.lang.Object getObject(int iRow, int iColumn)
          Returns object value at row index and column index, assuming column is a object type A ClassCastException is thrown otherwise.
 java.lang.String getString(int iRow, int iColumn)
          Returns String value at row index and column index, assuming column is a String type A ClassCastException is thrown otherwise.
 XMLTransferNode[] getXMLNodes()
          Override of ModelNode XML system.
 void pack()
          Rebuilds data arrays, removing elements that have been marked removed.
 void printRow(java.io.PrintStream out, int iRow)
           
 void purgeFinal()
          Called by database when node is intended to never come back, such as when a file is closed or node is deleted out of the undo system.
 void reallocateRows(int count)
          Adds new rows, keeping the old values it can.
 void removeRow(int iRow)
          Removes row by marking it as removed.
 int rowCount()
          Returns the number of good rows.
 int selectUniqueRow(java.lang.Object value, int iColumn)
          Finds row index where data cell matches value for the given column.
 void setBoolean(int iRow, int iColumn, boolean value)
          Sets value at row index and column index, assuming column is a boolean type A ClassCastException is thrown otherwise.
 void setBooleanColumnValues(int iColumn, boolean value)
          Set all values of column
 boolean setColumnIndexing(int iColumn)
           
 void setColumnIndexing(int iColumn, boolean b)
           
 void setColumns(java.lang.Class[] types, java.lang.String[] names, NodeSerializer[] nsa)
          Must be called before any other operation is done on table.
 void setColumnSerializer(int iColumn, NodeSerializer ns)
          NodeSerializer can be null for all types except for Object.
 void setColumnTransientness(int iColumn, boolean b)
          A transient column will not be saved to files, and can be skipped durring cloning and comparison functions.
 void setDouble(int iRow, int iColumn, double value)
          Sets value at row index and column index, assuming column is a double type A ClassCastException is thrown otherwise.
 void setDoubleColumnValues(int iColumn, double value)
          Set all values of column
 void setFloat(int iRow, int iColumn, float value)
          Sets value at row index and column index, assuming column is a float type A ClassCastException is thrown otherwise.
 void setFloatColumnValues(int iColumn, float value)
          Set all values of column
 void setInt(int iRow, int iColumn, int value)
          Sets value at row index and column index, assuming column is a int type A ClassCastException is thrown otherwise.
 void setIntColumnValues(int iColumn, int value)
          Set all values of column
 void setLong(int iRow, int iColumn, long value)
          Sets value at row index and column index, assuming column is a long type A ClassCastException is thrown otherwise.
 void setLongColumnValues(int iColumn, long value)
          Set all values of column
 void setObject(int iRow, int iColumn, java.lang.Object value)
          Sets value at row index and column index, assuming column is a Object type A ClassCastException is thrown otherwise.
 void setObjectColumnValues(int iColumn, java.lang.Object value)
          Set all values of column
 void setString(int iRow, int iColumn, java.lang.String value)
          Sets value at row index and column index, assuming column is a String type A ClassCastException is thrown otherwise.
 void setStringColumnValues(int iColumn, java.lang.String value)
          Set all values of column
 
Methods inherited from class harmonic.mz.data.ModelNode
actionPerformed, addAll, addAlphaed, addField, addField, addField, addFields, addNetworkInput, addNetworkOutput, addNode, addNodeListener, addNodeListener, addNodes, addNodes, addToCurrent, addToGlobals, addToNetworkEditor, addToTemps, addWithUndo, allFieldsAreFinal, applyDataTransfer, areFieldsValid, assignFromMetaFields, assignFromXMLAttributes, assignFromXMLString, assignToMetaFields, assignToXMLAttributes, assignToXMLString, at, bind, canSelect, castSelection, checkFileRead, checkNetworkInput, childCount, clean, clearAttrib, clearNotified, compare, copyFrom, createControlWidget, createXMLElement, deepCopy, defeatNodeEvents, disableEvents, enableEvents, expectedValidationTime, fileRoot, finalize, findFieldElement, findNode, getAttrib, getBound, getCatagory, getControlWidget, getCurrentNames, getDataTransfer, getDataTransferTypes, getDeleted, getDirectInputs, getDirectOutputs, getEffectors, getEntryListener, getErrorState, getFilterType, getFullName, getHandles, getInstanceURL, getInterpolater, getIsLeaf, getListable, getMark, getMetaFields, getName, getNodeChildren_V, getNodeChildren, getNodeID, getNodeParent, getObjectRep, getPresentable, getPrivate, getReferencePoolName, getRemoteOwner, getRemoveable, getRenameable, getSaveable, getSavedChildren, getSelect, getSeparateDirectInputs, getSeparateDirectOutputs, getSequenced, getSerialNo, getTags, getTentativeSelect, getTransformable, getTransformableParent, getTransient, getTreeName, getTypeImage, getTypeURL, getUnfoldedChildren, getUpdateTime, getUserGroup, getValidates, getValue, hasDependants, hasExternalRef, hashKey, hasValidationLock, hideControlWidget, indexOf, initControlWidget, insertNode, interpolate_Linear, interpolate_Quadratic, invalidate, isField, isFinal, isInSubtree, isInTree, isLinked, isNotified, isPurged, isSet, isTemporary, isValid, linkedTo, linksChildren, makeContextMenu, makeFixed, makePrototype, makeReferenced, makeUnreferenced, makeVisibleInGUI, markNotified, mayValidate, nodeChanged, notifyListeners, postAssignFromXMLElement, preAssignToXMLElement, printChildren, printTags, printTree, printTree, purge, pythonString, remove, removeAll, removeAll, removeHandles, removeNetworkInput, removeNetworkOutput, removeNode, removeNode, removeNode, removeNodeListener, replace, selfNodeChanged, set, setActualName, setAttrib, setBound, setCatagory, setChildrenExcept, setCoordSystem, setCurrentControlWidget, setCurrentNames, setDeleted, setEntryListener, setErrorState, setFromPrototype, setIsField, setIsLeaf, setIsSet, setListable, setMark, setMetaFields, setName, setNodeParent, setPresentable, setPrivate, setRemoteOwner, setRemoveable, setRenameable, setSaveable, setSelect, setSelect, setSequenced, setSerialNo, setTentativeSelect, setTentativeSelect, setToLink, setTransient, setTransientChildren, setUpdateTime, setUserGroup, setValidates, setValidationLock, setValue, setValueGroup, showControlWidget, showControlWidget, showControlWidget, showHandles, startRename, tag, toString, unlinkListeners, unmarkNotified, untag, updateBindable, valChanged, valChanged, validate, valueString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TableNode

public TableNode()
Method Detail

purgeFinal

public void purgeFinal()
Description copied from class: ModelNode
Called by database when node is intended to never come back, such as when a file is closed or node is deleted out of the undo system. Override to purge all memory usded by this node. Its easy to think that just removing the node from the tree would cause it to be garbage collected, but references to nodes can be hard to compleatly remove, so this function exists to minimize the damage of a leaked node.

Specified by:
purgeFinal in interface DataNode
Overrides:
purgeFinal in class ModelNode

setColumns

public void setColumns(java.lang.Class[] types,
                       java.lang.String[] names,
                       NodeSerializer[] nsa)
                throws java.lang.Exception
Must be called before any other operation is done on table. Column types and names must be non-null.

java.lang.Exception

addColumn

public void addColumn(java.lang.Class type,
                      java.lang.String name,
                      NodeSerializer nsa,
                      boolean bTransient)
               throws java.lang.Exception
Add a column after current last column. This is safe to call after rows have been allocated - new column will have same size as others.

java.lang.Exception

setColumnSerializer

public void setColumnSerializer(int iColumn,
                                NodeSerializer ns)
NodeSerializer can be null for all types except for Object. It is required here to define a method of serializing and deserializing table cell value as an ascii string.


setColumnTransientness

public void setColumnTransientness(int iColumn,
                                   boolean b)
A transient column will not be saved to files, and can be skipped durring cloning and comparison functions.


getColumnTransientness

public boolean getColumnTransientness(int iColumn)
A transient column will not be saved to files, and can be skipped durring cloning and comparison functions.


getColumnName

public java.lang.String getColumnName(int iColumn)

getColumnType

public java.lang.Class getColumnType(int iColumn)

getColumnSerializer

public NodeSerializer getColumnSerializer(int iColumn)

getColumnVisibility

public boolean getColumnVisibility(int iColumn)

setColumnIndexing

public boolean setColumnIndexing(int iColumn)

setColumnIndexing

public void setColumnIndexing(int iColumn,
                              boolean b)

allocateRows

public void allocateRows(int count)
Build an initial allocation of rows. This reinitializes the table data and indexing.


reallocateRows

public void reallocateRows(int count)
Adds new rows, keeping the old values it can. No row data is lost if count is greater than the old size. If rows have been removed, the table is repacked first. Indexing information is cleared. Rows are reallocated if needed with a padding of 50% over the required size.


addRow

public int addRow()
Adds a row. Row cell values must be filled in after. Row index is returned, which is the length of the table-1.


removeRow

public void removeRow(int iRow)
Removes row by marking it as removed. No memory is copied or moved untill pack() is called.


pack

public void pack()
Rebuilds data arrays, removing elements that have been marked removed. Any indexing is cleared. After this is called selectUniqueRow() may return a different row index for the select, so don't hang onto these indicies after calles to pack().


selectUniqueRow

public int selectUniqueRow(java.lang.Object value,
                           int iColumn)
Finds row index where data cell matches value for the given column. If column has been specified as index, if the column has not been indexed, it is indexed and then the indexing hashtable is querried. Otherwise the each column value is compared in turn to given value.


rowCount

public int rowCount()
Returns the number of good rows. This count is affected by allocateRows(), reallocateRows(), addRow(), removeRow()


columnCount

public int columnCount()
Returns number of columns


columnIndex

public int columnIndex(java.lang.String name)
Returns column index for name. This index can be kept for the life time of the table. It corrisponds to the name value given in setColumns().


compareRows

public static boolean compareRows(TableNode a,
                                  int rowA,
                                  TableNode b,
                                  int rowB)
Returns true if rows are the same. Requires tables have the same column types.


compareColumns

public static boolean compareColumns(TableNode a,
                                     int columnA,
                                     TableNode b,
                                     int columnB)

printRow

public void printRow(java.io.PrintStream out,
                     int iRow)

createCopy

public ModelNode createCopy()
Description copied from class: ModelNode
Overrideable function to create and return a copy of this node Default version uses introspection to create a new copy using the newInstance() function, which requires a no argument public constructor. It then uses the set() function to set the pieces of the copy to the original. Note this does not make a deep copy. Use deepCopy() for that.

Overrides:
createCopy in class ModelNode

setFloat

public void setFloat(int iRow,
                     int iColumn,
                     float value)
Sets value at row index and column index, assuming column is a float type A ClassCastException is thrown otherwise.


setFloatColumnValues

public void setFloatColumnValues(int iColumn,
                                 float value)
Set all values of column


getFloat

public float getFloat(int iRow,
                      int iColumn)
Returns float value at row index and column index, assuming column is a float type A ClassCastException is thrown otherwise.


setDouble

public void setDouble(int iRow,
                      int iColumn,
                      double value)
Sets value at row index and column index, assuming column is a double type A ClassCastException is thrown otherwise.


setDoubleColumnValues

public void setDoubleColumnValues(int iColumn,
                                  double value)
Set all values of column


getDouble

public double getDouble(int iRow,
                        int iColumn)
Returns double value at row index and column index, assuming column is a double type A ClassCastException is thrown otherwise.


setInt

public void setInt(int iRow,
                   int iColumn,
                   int value)
Sets value at row index and column index, assuming column is a int type A ClassCastException is thrown otherwise.


setIntColumnValues

public void setIntColumnValues(int iColumn,
                               int value)
Set all values of column


getInt

public int getInt(int iRow,
                  int iColumn)
Returns int value at row index and column index, assuming column is a int type A ClassCastException is thrown otherwise.


setLong

public void setLong(int iRow,
                    int iColumn,
                    long value)
Sets value at row index and column index, assuming column is a long type A ClassCastException is thrown otherwise.


setLongColumnValues

public void setLongColumnValues(int iColumn,
                                long value)
Set all values of column


getLong

public long getLong(int iRow,
                    int iColumn)
Returns long value at row index and column index, assuming column is a long type A ClassCastException is thrown otherwise.


setBoolean

public void setBoolean(int iRow,
                       int iColumn,
                       boolean value)
Sets value at row index and column index, assuming column is a boolean type A ClassCastException is thrown otherwise.


setBooleanColumnValues

public void setBooleanColumnValues(int iColumn,
                                   boolean value)
Set all values of column


getBoolean

public boolean getBoolean(int iRow,
                          int iColumn)
Returns boolean value at row index and column index, assuming column is a boolean type A ClassCastException is thrown otherwise.


setString

public void setString(int iRow,
                      int iColumn,
                      java.lang.String value)
Sets value at row index and column index, assuming column is a String type A ClassCastException is thrown otherwise.


setStringColumnValues

public void setStringColumnValues(int iColumn,
                                  java.lang.String value)
Set all values of column


getString

public java.lang.String getString(int iRow,
                                  int iColumn)
Returns String value at row index and column index, assuming column is a String type A ClassCastException is thrown otherwise.


setObject

public void setObject(int iRow,
                      int iColumn,
                      java.lang.Object value)
Sets value at row index and column index, assuming column is a Object type A ClassCastException is thrown otherwise.


setObjectColumnValues

public void setObjectColumnValues(int iColumn,
                                  java.lang.Object value)
Set all values of column


getObject

public java.lang.Object getObject(int iRow,
                                  int iColumn)
Returns object value at row index and column index, assuming column is a object type A ClassCastException is thrown otherwise.


fromXMLNodes

public void fromXMLNodes(XMLTransferNode[] xmlNodes)
Override of ModelNode XML system.

Specified by:
fromXMLNodes in interface DataNode
Overrides:
fromXMLNodes in class ModelNode

getXMLNodes

public XMLTransferNode[] getXMLNodes()
Override of ModelNode XML system. Create XMLTransferNodes for file saving.

Specified by:
getXMLNodes in interface DataNode
Overrides:
getXMLNodes in class ModelNode