|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--ModSQL.TableReader
Keeps track of open tables, referenced columns, and current row being read from joined table.
This class implements the full outer-join of all of the tables involved in a query. The interface allows for the skipping of entire subtree's of tuples and the use of indexed tables to improve query efficiency.
| Inner Class Summary | |
(package private) class |
TableReader.TableAccess
Class to register access to particular tables and whether the tables can be accessed via an indexed column. |
| Field Summary | |
private String[] |
aliases
Aliases for open tables. |
private ArrayList |
columns
Array of referenced columns. |
private int[] |
indexed_column
If table_read entry is an index, this array holds the index of the indexed column (or -1 if table_read entry is not an index). |
private int |
last_read
Index of last table to be read from. |
private TableReader |
parent
Reference to parent TableReader (used in subqueries). |
private ArrayList |
parent_columns
Columns from parent reader referenced in this query. |
private int[] |
read_sequence
Sequence number for read tables (-1 for not read yet). |
private boolean |
row_available
If last_read>=0, then this boolean indicates that rows have been read and are available for all open tables. |
private DatabaseTableBase[] |
table_read
Actual table or index being read. |
private DatabaseTable[] |
tables
Array of open tables. |
| Constructor Summary | |
TableReader(DatabaseTable[] tables,
String[] aliases,
TableReader parent)
Constructor. |
|
| Method Summary | |
static int |
cardinality(BitSet bs)
Implements java.util.BitSet.cardinality(). |
void |
commitUpdates()
Commit updated columns to database. |
void |
deleteRow()
Delete current row. |
boolean |
finishTable()
Closes least-significant table. |
int |
getColumnCount()
Returns total number of referenced columns. |
Object[] |
getColumnValues()
Get values for all referenced columns. |
Object[] |
getColumnValues(int ncolumns)
Get all column values starting at column 0 and ending at column ncolumns-1. |
DatabaseTable |
getDatabaseTable(int table_index)
Get reference to a particular table. |
TableReader |
getParent()
Get parent TableReader, or null if none. |
String |
getTableAlias(int table_index)
Get table alias (or null if none). |
boolean |
isIndexAvailable(int table,
int column)
Check if the specified column of the specified table is indexed. |
Function |
lookupFunction(String description)
Lookup description in list of tables to find a matching column. |
protected void |
next()
Advance to next row. |
void |
optimizeParameterOrder(Function function)
Reorder parameters in function to optimize query efficiency. |
void |
optimizeParameterOrder(Function function,
BitSet tables_read)
Reorder parameters in function to optimize query efficiency. |
boolean |
parentReferenced()
Are parent reader columns referenced here? |
void |
readAllColumns()
Make sure all tables have been read from. |
void |
readAllParentColumns()
Make sure all tables referenced from a parent reader have been read by attempting to fetch values for all referenced columns. |
void |
readAllTables()
Make sure all tables have been read from. |
void |
readColumns(int ncolumns)
Make sure tables have been read by attempting to fetch values for the first ncolumn referenced columns. |
protected Object |
readColumnValue(int table_index,
int column_index)
Read the value of the specified column in the specified table. |
protected Object |
readColumnValue(int table_index,
int column_index,
Object match_value)
Read the value of the specified column in the specified table. |
void |
readParentColumns(int ncolumns)
Make sure tables referenced from a parent reader have been read by attempting to fetch values for the first ncolumns referenced columns from the parent. |
protected void |
readTable(int table_index,
int column_index)
Start reading the specified table. |
void |
reset()
Invalidate all column data and reset tables to before the first row. |
void |
setColumnValues(Object[] values)
Load columns values into respective columns. |
void |
updateColumnValue(int table_index,
int column_index,
Object value)
Update a column in the table. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
private DatabaseTable[] tables
private String[] aliases
private DatabaseTableBase[] table_read
private int[] indexed_column
private int[] read_sequence
private int last_read
private boolean row_available
private ArrayList columns
private TableReader parent
private ArrayList parent_columns
| Constructor Detail |
public TableReader(DatabaseTable[] tables,
String[] aliases,
TableReader parent)
tables - array of open database tablesaliases - aliases of the database tablesparent - parent reader of subquery (null if none)| Method Detail |
public TableReader getParent()
public boolean parentReferenced()
public DatabaseTable getDatabaseTable(int table_index)
public String getTableAlias(int table_index)
public int getColumnCount()
public Function lookupFunction(String description)
throws SQLException
Lookup description in list of tables to find a matching column. The description can be in any one of the following forms: 'alias.column_name', 'table_name.column_name', or 'column_name'.
If a suitable column is found, it is added to the list of referenced columns (if it's not already there).
If a suitable column was not found and this TableReader has a parent, the parent is searched for a matching column.
lookupFunction in interface FunctionProviderdescription - description of column to look forSQLException - if the column was not found
public boolean isIndexAvailable(int table,
int column)
throws SQLException
table - index of tablecolumn - index of column within tableSQLException - if thrown by a database module
public void optimizeParameterOrder(Function function)
throws SQLException
function - the function to optimize by reordering termsSQLException - if an error occurs
public void optimizeParameterOrder(Function function,
BitSet tables_read)
throws SQLException
function - the function to optimize by reordering termstables_read - bitmap indicating which tables have been read fromSQLException - if an error occurs
public Object[] getColumnValues(int ncolumns)
throws SQLException,
EndOfTable
ncolumns - total number of column values to fetchSQLException - if an error occursEndOfTable - if the end of a table has been encountered
public Object[] getColumnValues()
throws SQLException,
EndOfTable
SQLException - if an error occursEndOfTable - if the end of a table has been encountered
public void setColumnValues(Object[] values)
throws SQLException
values - values for each referenced columnSQLException - if an error occurspublic void reset()
protected void next()
throws SQLException,
EndOfTable
SQLException - if an error occursEndOfTable - if the end of a table has been encountered
public boolean finishTable()
throws SQLException
SQLException - if an error occurs
protected void readTable(int table_index,
int column_index)
throws SQLException,
EndOfTable
table_index - index of next table to readcolumn_index - index of column being referenced (-1 for none)SQLException - if an error occursEndOfTable - if the end of a table has been encountered
public void readAllTables()
throws SQLException,
EndOfTable
SQLException - if an error occursEndOfTable - if the end of a table has been encountered
public void readParentColumns(int ncolumns)
throws SQLException,
EndOfTable
ncolumns - number of parent columns to checkSQLException - if an error occursEndOfTable - if the end of a table has been encountered
public void readAllParentColumns()
throws SQLException,
EndOfTable
SQLException - if an error occursEndOfTable - if the end of a table has been encountered
public void readColumns(int ncolumns)
throws SQLException,
EndOfTable
ncolumns - number of columns to checkSQLException - if an error occursEndOfTable - if the end of a table has been encountered
public void readAllColumns()
throws SQLException,
EndOfTable
SQLException - if an error occursEndOfTable - if the end of a table has been encountered
protected Object readColumnValue(int table_index,
int column_index)
throws SQLException,
EndOfTable
table_index - index of tablecolumn_index - index of column within tableSQLException - if an error occursEndOfTable - if the end of a table has been encountered
protected Object readColumnValue(int table_index,
int column_index,
Object match_value)
throws SQLException,
EndOfTable
Read the value of the specified column in the specified table. If it is necessary to advance to the next row of the table, search for a row with match_value in the specified column. This method is not obligated to return match_value. It may just advance to the next row as the above implementation of readColumnValue() does.
Note that the type of object passed in match_value must exactly match the column type as indicated by getSQLType().
table_index - index of tablecolumn_index - index of column within tablematch_value - object value to look forSQLException - if an error occursEndOfTable - if the end of a table has been encountered
public void updateColumnValue(int table_index,
int column_index,
Object value)
throws SQLException
table_index - index of tablecolumn_index - index of column within tablevalue - new value for columnSQLException - if an error occurs
public void commitUpdates()
throws SQLException
SQLException - if an error occurs
public void deleteRow()
throws SQLException
SQLException - if an error occurspublic static int cardinality(BitSet bs)
bs - bits to count
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||