Elexis API documentation
Version 2.1.6 as of December 11 2011

com.healthmarketscience.jackcess
Class Table

java.lang.Object
  extended by com.healthmarketscience.jackcess.Table
All Implemented Interfaces:
java.lang.Iterable<java.util.Map<java.lang.String,java.lang.Object>>

public class Table
extends java.lang.Object
implements java.lang.Iterable<java.util.Map<java.lang.String,java.lang.Object>>

A single database table

Is not thread-safe.

Author:
Tim McCune

Nested Class Summary
 class Table.RowState
          Maintains the state of reading a row of data.
 
Field Summary
static byte TYPE_SYSTEM
          Table type code for system tables
static byte TYPE_USER
          Table type code for user tables
 
Method Summary
static int addDataPageRow(java.nio.ByteBuffer dataPage, int rowSize, JetFormat format, int rowFlags)
          Updates free space and row info for a new row of the given size in the given data page.
 void addRow(java.lang.Object... row)
          Add a single row to this table and write it to disk Note, if this table has an auto-number column, the value written will be put back into the given row array.
 void addRows(java.util.List<? extends java.lang.Object[]> rows)
          Add multiple rows to this table, only writing to disk after all rows have been written, and every time a data page is filled.
 java.lang.Object[] asRow(java.util.Map<java.lang.String,java.lang.Object> rowMap)
          Converts a map of columnName -> columnValue to an array of row values appropriate for a call to addRow(Object...).
 java.lang.Object[] asUpdateRow(java.util.Map<java.lang.String,java.lang.Object> rowMap)
          Converts a map of columnName -> columnValue to an array of row values appropriate for a call to updateCurrentRow(Object...).
static short cleanRowStart(short rowStart)
           
 Table.RowState createRowState()
           
 void deleteCurrentRow()
          Delete the current row (retrieved by a call to getNextRow()).
 void deleteRow(Table.RowState rowState, RowId rowId)
          Delete the row on which the given rowState is currently positioned.
 java.lang.String display()
           
 java.lang.String display(long limit)
           
 boolean doUseBigIndex()
           
static short findRowEnd(java.nio.ByteBuffer buffer, int rowNum, JetFormat format)
           
static short findRowStart(java.nio.ByteBuffer buffer, int rowNum, JetFormat format)
           
static java.util.List<Column> getAutoNumberColumns(java.util.Collection<Column> columns)
           
 Column getColumn(java.lang.String name)
           
 int getColumnCount()
           
 java.util.List<Column> getColumns()
           
 Database getDatabase()
           
 ErrorHandler getErrorHandler()
          Gets the currently configured ErrorHandler (always non-null).
 JetFormat getFormat()
           
 Index getIndex(java.lang.String name)
           
 java.util.List<Index> getIndexes()
           
 int getMaxColumnCount()
           
 java.lang.String getName()
           
 java.util.Map<java.lang.String,java.lang.Object> getNextRow()
           
 java.util.Map<java.lang.String,java.lang.Object> getNextRow(java.util.Collection<java.lang.String> columnNames)
           
 PageChannel getPageChannel()
           
 java.util.Map<java.lang.String,java.lang.Object> getRow(Table.RowState rowState, RowId rowId, java.util.Collection<java.lang.String> columnNames)
          Reads some columns from the given row.
 int getRowCount()
           
static int getRowEndOffset(int rowNum, JetFormat format)
           
static int getRowSpaceUsage(int rowSize, JetFormat format)
           
static int getRowStartOffset(int rowNum, JetFormat format)
           
 java.lang.Object getRowValue(Table.RowState rowState, RowId rowId, Column column)
          Reads a single column from the given row.
static boolean isDeletedRow(short rowStart)
           
static boolean isOverflowRow(short rowStart)
           
 java.util.Iterator<java.util.Map<java.lang.String,java.lang.Object>> iterator()
          Calls reset on this table and returns an unmodifiable Iterator which will iterate through all the rows of this table.
 java.util.Iterator<java.util.Map<java.lang.String,java.lang.Object>> iterator(java.util.Collection<java.lang.String> columnNames)
          Calls reset on this table and returns an unmodifiable Iterator which will iterate through all the rows of this table, returning only the given columns.
static java.nio.ByteBuffer positionAtRowData(Table.RowState rowState, RowId rowId)
          Sets the position and limit in a new buffer using the given rowState according to the given row number and row end, following overflow row pointers as necessary.
static java.nio.ByteBuffer positionAtRowHeader(Table.RowState rowState, RowId rowId)
          Sets a new buffer to the correct row header page using the given rowState according to the given rowId.
 void reset()
          After calling this method, getNextRow will return the first row in the table
static boolean rowFitsOnDataPage(int rowLength, java.nio.ByteBuffer dataPage, JetFormat format)
          Returns true if a row of the given size will fit on the given data page, false otherwise.
 void setErrorHandler(ErrorHandler newErrorHandler)
          Sets a new ErrorHandler.
 java.lang.String toString()
           
 void updateCurrentRow(java.lang.Object... row)
          Updates the current row to the new values.
 void updateRow(Table.RowState rowState, RowId rowId, java.lang.Object... row)
          Update the row on which the given rowState is currently positioned.
static int writeTableDefinition(java.util.List<Column> columns, PageChannel pageChannel, JetFormat format, java.nio.charset.Charset charset)
          Writes a new table defined by the given columns to the database.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_SYSTEM

public static final byte TYPE_SYSTEM
Table type code for system tables

See Also:
Constant Field Values

TYPE_USER

public static final byte TYPE_USER
Table type code for user tables

See Also:
Constant Field Values
Method Detail

getName

public java.lang.String getName()
Returns:
The name of the table

doUseBigIndex

public boolean doUseBigIndex()

getMaxColumnCount

public int getMaxColumnCount()

getColumnCount

public int getColumnCount()

getDatabase

public Database getDatabase()

getFormat

public JetFormat getFormat()

getPageChannel

public PageChannel getPageChannel()

getErrorHandler

public ErrorHandler getErrorHandler()
Gets the currently configured ErrorHandler (always non-null). This will be used to handle all errors unless overridden at the Cursor level.


setErrorHandler

public void setErrorHandler(ErrorHandler newErrorHandler)
Sets a new ErrorHandler. If null, resets to using the ErrorHandler configured at the Database level.


createRowState

public Table.RowState createRowState()

getColumns

public java.util.List<Column> getColumns()
Returns:
All of the columns in this table (unmodifiable List)

getColumn

public Column getColumn(java.lang.String name)
Returns:
the column with the given name

getIndexes

public java.util.List<Index> getIndexes()
Returns:
All of the Indexes on this table (unmodifiable List)

getIndex

public Index getIndex(java.lang.String name)
Returns:
the index with the given name

reset

public void reset()
After calling this method, getNextRow will return the first row in the table


deleteCurrentRow

public void deleteCurrentRow()
                      throws java.io.IOException
Delete the current row (retrieved by a call to getNextRow()).

Throws:
java.io.IOException

deleteRow

public void deleteRow(Table.RowState rowState,
                      RowId rowId)
               throws java.io.IOException
Delete the row on which the given rowState is currently positioned.

Throws:
java.io.IOException

getNextRow

public java.util.Map<java.lang.String,java.lang.Object> getNextRow()
                                                            throws java.io.IOException
Returns:
The next row in this table (Column name -> Column value)
Throws:
java.io.IOException

getNextRow

public java.util.Map<java.lang.String,java.lang.Object> getNextRow(java.util.Collection<java.lang.String> columnNames)
                                                            throws java.io.IOException
Parameters:
columnNames - Only column names in this collection will be returned
Returns:
The next row in this table (Column name -> Column value)
Throws:
java.io.IOException

getRowValue

public java.lang.Object getRowValue(Table.RowState rowState,
                                    RowId rowId,
                                    Column column)
                             throws java.io.IOException
Reads a single column from the given row.

Throws:
java.io.IOException

getRow

public java.util.Map<java.lang.String,java.lang.Object> getRow(Table.RowState rowState,
                                                               RowId rowId,
                                                               java.util.Collection<java.lang.String> columnNames)
                                                        throws java.io.IOException
Reads some columns from the given row.

Parameters:
columnNames - Only column names in this collection will be returned
Throws:
java.io.IOException

positionAtRowHeader

public static java.nio.ByteBuffer positionAtRowHeader(Table.RowState rowState,
                                                      RowId rowId)
                                               throws java.io.IOException
Sets a new buffer to the correct row header page using the given rowState according to the given rowId. Deleted state is determined, but overflow row pointers are not followed.

Returns:
a ByteBuffer of the relevant page, or null if row was invalid
Throws:
java.io.IOException

positionAtRowData

public static java.nio.ByteBuffer positionAtRowData(Table.RowState rowState,
                                                    RowId rowId)
                                             throws java.io.IOException
Sets the position and limit in a new buffer using the given rowState according to the given row number and row end, following overflow row pointers as necessary.

Returns:
a ByteBuffer narrowed to the actual row data, or null if row was invalid or deleted
Throws:
java.io.IOException

iterator

public java.util.Iterator<java.util.Map<java.lang.String,java.lang.Object>> iterator()
Calls reset on this table and returns an unmodifiable Iterator which will iterate through all the rows of this table. Use of the Iterator follows the same restrictions as a call to getNextRow.

Specified by:
iterator in interface java.lang.Iterable<java.util.Map<java.lang.String,java.lang.Object>>
Throws:
java.lang.IllegalStateException - if an IOException is thrown by one of the operations, the actual exception will be contained within

iterator

public java.util.Iterator<java.util.Map<java.lang.String,java.lang.Object>> iterator(java.util.Collection<java.lang.String> columnNames)
Calls reset on this table and returns an unmodifiable Iterator which will iterate through all the rows of this table, returning only the given columns. Use of the Iterator follows the same restrictions as a call to getNextRow.

Throws:
java.lang.IllegalStateException - if an IOException is thrown by one of the operations, the actual exception will be contained within

writeTableDefinition

public static int writeTableDefinition(java.util.List<Column> columns,
                                       PageChannel pageChannel,
                                       JetFormat format,
                                       java.nio.charset.Charset charset)
                                throws java.io.IOException
Writes a new table defined by the given columns to the database.

Returns:
the first page of the new table's definition
Throws:
java.io.IOException

asRow

public java.lang.Object[] asRow(java.util.Map<java.lang.String,java.lang.Object> rowMap)
Converts a map of columnName -> columnValue to an array of row values appropriate for a call to addRow(Object...).


asUpdateRow

public java.lang.Object[] asUpdateRow(java.util.Map<java.lang.String,java.lang.Object> rowMap)
Converts a map of columnName -> columnValue to an array of row values appropriate for a call to updateCurrentRow(Object...).


addRow

public void addRow(java.lang.Object... row)
            throws java.io.IOException
Add a single row to this table and write it to disk

Note, if this table has an auto-number column, the value written will be put back into the given row array.

Parameters:
row - row values for a single row. the row will be modified if this table contains an auto-number column, otherwise it will not be modified.
Throws:
java.io.IOException

addRows

public void addRows(java.util.List<? extends java.lang.Object[]> rows)
             throws java.io.IOException
Add multiple rows to this table, only writing to disk after all rows have been written, and every time a data page is filled. This is much more efficient than calling addRow multiple times.

Note, if this table has an auto-number column, the values written will be put back into the given row arrays.

Parameters:
rows - List of Object[] row values. the rows will be modified if this table contains an auto-number column, otherwise they will not be modified.
Throws:
java.io.IOException

updateCurrentRow

public void updateCurrentRow(java.lang.Object... row)
                      throws java.io.IOException
Updates the current row to the new values.

Note, if this table has an auto-number column(s), the existing value(s) will be maintained, unchanged.

Parameters:
row - new row values for the current row.
Throws:
java.io.IOException

updateRow

public void updateRow(Table.RowState rowState,
                      RowId rowId,
                      java.lang.Object... row)
               throws java.io.IOException
Update the row on which the given rowState is currently positioned.

Throws:
java.io.IOException

getRowCount

public int getRowCount()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

display

public java.lang.String display()
                         throws java.io.IOException
Returns:
A simple String representation of the entire table in tab-delimited format
Throws:
java.io.IOException

display

public java.lang.String display(long limit)
                         throws java.io.IOException
Parameters:
limit - Maximum number of rows to display
Returns:
A simple String representation of the entire table in tab-delimited format
Throws:
java.io.IOException

addDataPageRow

public static int addDataPageRow(java.nio.ByteBuffer dataPage,
                                 int rowSize,
                                 JetFormat format,
                                 int rowFlags)
Updates free space and row info for a new row of the given size in the given data page. Positions the page for writing the row data.

Returns:
the row number of the new row

isDeletedRow

public static boolean isDeletedRow(short rowStart)

isOverflowRow

public static boolean isOverflowRow(short rowStart)

cleanRowStart

public static short cleanRowStart(short rowStart)

findRowStart

public static short findRowStart(java.nio.ByteBuffer buffer,
                                 int rowNum,
                                 JetFormat format)

getRowStartOffset

public static int getRowStartOffset(int rowNum,
                                    JetFormat format)

findRowEnd

public static short findRowEnd(java.nio.ByteBuffer buffer,
                               int rowNum,
                               JetFormat format)

getRowEndOffset

public static int getRowEndOffset(int rowNum,
                                  JetFormat format)

getRowSpaceUsage

public static int getRowSpaceUsage(int rowSize,
                                   JetFormat format)

getAutoNumberColumns

public static java.util.List<Column> getAutoNumberColumns(java.util.Collection<Column> columns)
Returns:
the "AutoNumber" columns in the given collection of columns.

rowFitsOnDataPage

public static boolean rowFitsOnDataPage(int rowLength,
                                        java.nio.ByteBuffer dataPage,
                                        JetFormat format)
                                 throws java.io.IOException
Returns true if a row of the given size will fit on the given data page, false otherwise.

Throws:
java.io.IOException

Elexis API documentation
Version 2.1.6 as of December 11 2011

Copyright 2005-2011 by Gerry Weirich, Elexis