: Class IndexTable_Hash

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## ModSQL
Class IndexTable_Hash

    java.lang.Object
      |
      +--ModSQL.IndexTable
            |
            +--ModSQL.IndexTable_Hash

All Implemented Interfaces:
  DatabaseIndex, DatabaseTableBase

class IndexTable_Hash
extends IndexTable

Implementation of DatabaseTable for tables that are indexed by the ModSQL driver using a hash table.

This index can be accessed just as the original table is accessed. Access to the column that is indexed will be fast while access to other columns will be slower as data must be loaded from the original table.

Author:
  chris.studholme@utoronto.ca

Field Summary
`protected boolean` | `after_last`
`protected boolean` | `before_first`
`protected BufferedInputStream` | `buffer`
`static int` | `BUFFERSIZE`
`protected int` | `columnindex`
`protected int` | `columntype`
`protected long` | `current_count`
`protected Object` | `current_data`
`protected int` | `current_index`
`protected Iterator` | `current_iterator`
`protected IndexTableRowset` | `current_rowset`
`protected FileInputStream` | `file`
`protected ObjectInputStream` | `istream`
`protected HashMap` | `map`
`protected int` | `rows_to_read`
`protected DatabaseTable` | `table`
`static int` | `TYPE`
`static int` | `VERSION`

Constructor Summary
`IndexTable_Hash(DatabaseTable table, String filename)` Constructor.

Method Summary
`void` | `afterLast()` Moves the table cursor to a position after the last row in the table.
`void` | `beforeFirst()` Moves the table cursor to a position before the first row in the table.
`void` | `close()` In some cases, it is desirable to immediately release a DatabaseTable's database and other resources instead of waiting for this to happen when it is automatically closed; the close method provides this immediate release.
`void` | `commitUpdates()` ModSQL will always call this method after performing a series of updateObject() calls on a particular row.
`(package private) static void` | `createIndex(DatabaseManager tablemanager, String tablename, int columnindex)` Create new index.
`(package private) static void` | `createIndex(DatabaseManager tablemanager, String tablename, String columnname)` Create new index.
`(package private) static void` | `createIndex(DatabaseTable table, int columnindex)` Create new index.
`void` | `deleteRow()` Delete the current row from the table and the underlying database.
`protected void` | `finalize()` Close index.
`boolean` | `findNext(int column, Object data)` Old version of findNext() above that requires a column index.
`boolean` | `findNext(Object data)` Finds the next row that has the specified data in the indexed column.
`long` | `getDistinctCount()` Returns the number of distinct values stored in the indexed column in the underlying table.
`long` | `getNullCount()` Returns the number of null values stored in the indexed column in the underlying table.
`Object` | `getObject(int column)` Get the value of a column in the current row as a Java object.
`long` | `getRowCount()` This method is expected to return the total number of rows in the database.
`Object` | `getRowId()` Get database specific rowid value.
`boolean` | `isAfterLast()` Determine if the table cursor is positioned after the last row in the table.
`boolean` | `isBeforeFirst()` Determine if the table cursor is positioned before the first row in the table.
`boolean` | `next()` A DatabaseTable is initially positioned before its first row; the first call to next makes the first row the current row; the second call makes the second row the current row, etc.
`void` | `updateObject(int column, Object x)` Update a column with an Object value.

Methods inherited from class ModSQL.IndexTable
`getIndexFilename, isIndexAvailable, openIndex`

Methods inherited from class java.lang.Object
`, clone, equals, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait`

Field Detail

### TYPE

    public static final int TYPE

### VERSION

    public static final int VERSION

### BUFFERSIZE

    public static final int BUFFERSIZE

### file

    protected FileInputStream file

### buffer

    protected BufferedInputStream buffer

### istream

    protected ObjectInputStream istream

### table

    protected DatabaseTable table

### columnindex

    protected int columnindex

### columntype

    protected int columntype

### map

    protected HashMap map

### rows_to_read

    protected int rows_to_read

### before_first

    protected boolean before_first

### after_last

    protected boolean after_last

### current_iterator

    protected Iterator current_iterator

### current_data

    protected Object current_data

### current_rowset

    protected IndexTableRowset current_rowset

### current_index

    protected int current_index

### current_count

    protected long current_count

Constructor Detail

### IndexTable_Hash

    public IndexTable_Hash(DatabaseTable table,
                           String filename)
                    throws DatabaseException

  Constructor. Open existing hash table.
  Parameters:
    `table` - open table to index
    `filename` - path to index file
  Throws:
    `DatabaseException` - if there is a problem with the index

Method Detail

### finalize

    protected void finalize()

  Close index.
  Overrides:
    `finalize` in class `Object`

### close

    public final void close()

  Description copied from interface: `DatabaseTableBase`

  In some cases, it is desirable to immediately release a DatabaseTable's database and other resources instead of waiting for this to happen when it is automatically closed; the close method provides this immediate release.

  Note: A DatabaseTable is automatically closed by the Statement that generated it when that Statement is closed, re-executed, or is used to retrieve the next result from a sequence of multiple results. A DatabaseTable is also automatically closed when it is garbage collected.

  Following copied from interface: `ModSQL.DatabaseTableBase`
  Throws:
    `DatabaseException` - if a database-access error occurs

### getRowCount

    public long getRowCount()

  Description copied from interface: `DatabaseTableBase`
  This method is expected to return the total number of rows in the database. This value is used by ModSQL for query optimization purposes. If the count cannot be easily determined, the database should return -1 to indicate that the count is unknown.
  Following copied from interface: `ModSQL.DatabaseTableBase`
  Returns:
    number of rows in table, or -1 for unknown
  Throws:
    `DatabaseException` - if a database-access error occurs

### getDistinctCount

    public long getDistinctCount()

  Description copied from interface: `DatabaseIndex`
  Returns the number of distinct values stored in the indexed column in the underlying table. This method may return an approximation.
  Following copied from interface: `ModSQL.DatabaseIndex`
  Returns:
    number of distinct values
  Throws:
    `DatabaseException` - if a database-access error occurs

### getNullCount

    public long getNullCount()

  Description copied from interface: `DatabaseIndex`
  Returns the number of null values stored in the indexed column in the underlying table. This method may return an approximation.
  Following copied from interface: `ModSQL.DatabaseIndex`
  Returns:
    number of null values
  Throws:
    `DatabaseException` - if a database-access error occurs

### next

    public boolean next()
                 throws DatabaseException

  Description copied from interface: `DatabaseTableBase`
  A DatabaseTable is initially positioned before its first row; the first call to next makes the first row the current row; the second call makes the second row the current row, etc.
  Following copied from interface: `ModSQL.DatabaseTableBase`
  Returns:
    true if the new current row is valid; false if there are no more rows
  Throws:
    `DatabaseException` - if a database-access error occurs

### findNext

    public boolean findNext(Object data)
                     throws DatabaseException

  Description copied from interface: `DatabaseIndex`
  Finds the next row that has the specified data in the indexed column. Returns false if no such row could be found. The search always begins at the next row in the database and continues to the last row in the database.
  Following copied from interface: `ModSQL.DatabaseIndex`
  Parameters:
    `data` - desired data
  Returns:
    true if the new current row is valid; false otherwise
  Throws:
    `DatabaseException` - if a database-access error occurs

### findNext

    public boolean findNext(int column,
                            Object data)
                     throws DatabaseException

  Old version of findNext() above that requires a column index. Do not use this method directly.
  Throws:
    `DatabaseException` - if there is a problem with the index

### deleteRow

    public void deleteRow()
                   throws DatabaseException

  Description copied from interface: `DatabaseTableBase`
  Delete the current row from the table and the underlying database. Cannot be called when on a newly inserted row.
  Following copied from interface: `ModSQL.DatabaseTableBase`
  Throws:
    `DatabaseException` - if a database-access error occurs

### isBeforeFirst

    public boolean isBeforeFirst()

  Description copied from interface: `DatabaseTableBase`
  Determine if the table cursor is positioned before the first row in the table.
  Following copied from interface: `ModSQL.DatabaseTableBase`
  Returns:
    true if before the first row, false otherwise
  Throws:
    `DatabaseException` - if a database-access error occurs

### isAfterLast

    public boolean isAfterLast()

  Description copied from interface: `DatabaseTableBase`
  Determine if the table cursor is positioned after the last row in the table.
  Following copied from interface: `ModSQL.DatabaseTableBase`
  Returns:
    true if after the last row, false otherwise
  Throws:
    `DatabaseException` - if a database-access error occurs

### beforeFirst

    public void beforeFirst()
                     throws DatabaseException

  Description copied from interface: `DatabaseTableBase`
  Moves the table cursor to a position before the first row in the table. The next call to next() will set the cursor to the first row in the table (assuming the table has at least one row).
  Following copied from interface: `ModSQL.DatabaseTableBase`
  Throws:
    `DatabaseException` - if a database-access error occurs

### afterLast

    public void afterLast()
                   throws DatabaseException

  Description copied from interface: `DatabaseTableBase`
  Moves the table cursor to a position after the last row in the table. All calls to next() will return false until beforeFirst() is called to reset the table.
  Following copied from interface: `ModSQL.DatabaseTableBase`
  Throws:
    `DatabaseException` - if a database-access error occurs

### getRowId

    public Object getRowId()
                    throws DatabaseException

  Description copied from interface: `DatabaseTableBase`
  Get database specific rowid value. This value can be later used with absolute() to seek to a specific row.
  Following copied from interface: `ModSQL.DatabaseTableBase`
  Returns:
    object representing current row, or null if no current row
  Throws:
    `DatabaseException` - if a database-access error occurs

### getObject

    public Object getObject(int column)
                     throws DatabaseException

  Description copied from interface: `DatabaseTableBase`

  Get the value of a column in the current row as a Java object.

  This method will return the value of the given column as a Java object. The type of the Java object will be the default Java Object type corresponding to the column's SQL type, following the mapping specified in the JDBC spec.

  This method may also be used to read datatabase specific abstract data types.

  Following copied from interface: `ModSQL.DatabaseTableBase`
  Parameters:
    `column` - the first column is 1, the second is 2, ...
  Returns:
    an Object holding the column value
  Throws:
    `DatabaseException` - if a database-access error occurs

### updateObject

    public void updateObject(int column,
                             Object x)
                      throws DatabaseException

  Description copied from interface: `DatabaseTableBase`

  Update a column with an Object value.

  The updateObject() method is used to update column values in the current row, or a newly inserted row.

  Following copied from interface: `ModSQL.DatabaseTableBase`
  Parameters:
    `column` - the first column is 1, the second is 2, ...
    `x` - the new column value
  Throws:
    `DatabaseException` - if a database-access error occurs

### commitUpdates

    public void commitUpdates()
                       throws DatabaseException

  Description copied from interface: `DatabaseTableBase`
  ModSQL will always call this method after performing a series of updateObject() calls on a particular row. If this call is not received before the row is changed or the table is closed, the changes made by updateObject() should be discarded. In the case where addRow() was called before the updateObject() calls, the new row can be discarded as well.
  Following copied from interface: `ModSQL.DatabaseTableBase`
  Throws:
    `DatabaseException` - if a database-access error occurs

### createIndex

    static void createIndex(DatabaseManager tablemanager,
                            String tablename,
                            String columnname)
                     throws SQLException

  Create new index.
  Parameters:
    `tablemanager` - active table manager
    `tablename` - name of table to index
    `columnname` - name of column to index
  Throws:
    `SQLException` - if there is a problem creating the index

### createIndex

    static void createIndex(DatabaseManager tablemanager,
                            String tablename,
                            int columnindex)
                     throws SQLException

  Create new index.
  Parameters:
    `tablemanager` - active table manager
    `tablename` - name of table to index
    `columnindex` - index of column to index
  Throws:
    `SQLException` - if there is a problem creating the index

### createIndex

    static void createIndex(DatabaseTable table,
                            int columnindex)
                     throws SQLException

  Create new index.
  Parameters:
    `table` - open table to index
    `columnindex` - index of column to index
  Throws:
    `SQLException` - if there is a problem creating the index

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD