ModSQL
Class SelectTable

java.lang.Object
  |
  +--ModSQL.SelectTable
All Implemented Interfaces:
DatabaseTable, DatabaseTableBase

class SelectTable
extends Object
implements DatabaseTable

Wrapper for a Select object to make it look like a DatabaseTable. This class is used when a SELECT statement appears as a subquery in the FROM section of some other SELECT statement.

Author:
chris.studholme@utoronto.ca
See Also:
Select

Field Summary
private  boolean afterlast
          Are we after the last row?
private  boolean beforefirst
          Are we before the first row?
private  String name
          Name of table.
private  Table query
          Query that generated the table.
private  long rownum
          Current row number.
 
Constructor Summary
SelectTable(Table query, String name)
          Query should already be optimized before using this constructor.
 
Method Summary
 boolean absolute(Object id)
          Move to an absolute rowid in the table.
 void addColumn(String name, int type, int maxlen)
          Add a new column.
 void addRow()
          Add a new row.
 void afterLast()
          Set current row to after last row in table.
 void beforeFirst()
          Reset current row to before the first row in table.
 void close()
          Close the query.
 void commitUpdates()
          Commit column updates.
 void deleteRow()
          Delete current row.
protected  void finalize()
          Close table.
 int findColumn(String name)
          Find a column with the specified name.
 int getColumnCount()
          Number of columns in table.
 int getColumnDisplaySize(int column)
          Get maximum size of column.
 String getColumnLabel(int column)
          Get column label.
 String getColumnName(int column)
          Get name of column.
 int getColumnType(int column)
          Get column type.
 Object getObject(int column)
          Get the value of a column in the current row as a Java object.
 long getRowCount()
          Number of rows.
 Object getRowId()
          Returns the rowid for the current row.
 String getTableName()
          Name of table.
 long getTableSignature()
          Table signature.
 long getTableSize()
          Size of table in bytes.
 boolean isAfterLast()
          Are we after the last row?
 boolean isBeforeFirst()
          Are we before the first row?
 boolean isIndexAvailable(int column)
          Is an index available? Indices are not supported for tables generated from a query so this method just returns null.
 boolean isReadOnly()
          Is table readonly?
 boolean next()
          Advance to next row in table.
 DatabaseIndex openIndex(int column)
          Open an index on the table.
 String toString()
          Human readable description of table.
 void updateObject(int column, Object x)
          Update value of column.
 
Methods inherited from class java.lang.Object
, clone, equals, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

query

private Table query
Query that generated the table.

name

private String name
Name of table.

beforefirst

private boolean beforefirst
Are we before the first row?

afterlast

private boolean afterlast
Are we after the last row?

rownum

private long rownum
Current row number.
Constructor Detail

SelectTable

public SelectTable(Table query,
                   String name)
Query should already be optimized before using this constructor.
Parameters:
query - optimized query to generate table
name - name of table
Method Detail

finalize

protected void finalize()
Close table. Just calls close() below.
Overrides:
finalize in class Object

close

public final void close()
Close the query.
Specified by:
close in interface DatabaseTableBase
Following copied from interface: ModSQL.DatabaseTableBase
Throws:
DatabaseException - if a database-access error occurs

openIndex

public DatabaseIndex openIndex(int column)
Open an index on the table. Indices are not supported for tables generated from a query so this method just returns null.
Specified by:
openIndex in interface DatabaseTable
Parameters:
column - open index for desired column
Returns:
null

isIndexAvailable

public boolean isIndexAvailable(int column)
Is an index available? Indices are not supported for tables generated from a query so this method just returns null.
Specified by:
isIndexAvailable in interface DatabaseTable
Parameters:
column - desired index
Returns:
false

isReadOnly

public boolean isReadOnly()
Is table readonly?
Specified by:
isReadOnly in interface DatabaseTable
Returns:
true

getTableSize

public long getTableSize()
Size of table in bytes.
Specified by:
getTableSize in interface DatabaseTable
Returns:
-1 (unknown)

getTableSignature

public long getTableSignature()
Table signature.
Specified by:
getTableSignature in interface DatabaseTable
Returns:
0

getTableName

public String getTableName()
Name of table.
Specified by:
getTableName in interface DatabaseTable
Returns:
table name

getColumnCount

public int getColumnCount()
                   throws DatabaseException
Number of columns in table.
Specified by:
getColumnCount in interface DatabaseTable
Returns:
number of columns
Throws:
DatabaseException - is the query fails

getRowCount

public long getRowCount()
Number of rows.
Specified by:
getRowCount in interface DatabaseTableBase
Returns:
-1 (unknown)

toString

public String toString()
Human readable description of table.
Overrides:
toString in class Object
Returns:
the query

findColumn

public int findColumn(String name)
               throws DatabaseException
Find a column with the specified name.
Specified by:
findColumn in interface DatabaseTable
Parameters:
name - name of column to find
Returns:
index of column (-1 if not found)
Throws:
DatabaseException - if there is a problem with the query

getColumnName

public String getColumnName(int column)
                     throws DatabaseException
Get name of column.
Specified by:
getColumnName in interface DatabaseTable
Parameters:
column - index of column
Returns:
name of column
Throws:
DatabaseException - if there is a problem with the query

getColumnLabel

public String getColumnLabel(int column)
                      throws DatabaseException
Get column label. This method is the same as getColumnName() above.
Specified by:
getColumnLabel in interface DatabaseTable
Parameters:
column - index of column
Returns:
label for column
Throws:
DatabaseException - if there is a problem with the query

getColumnType

public int getColumnType(int column)
                  throws DatabaseException
Get column type.
Specified by:
getColumnType in interface DatabaseTable
Parameters:
column - index of column
Returns:
SQL type of column
Throws:
DatabaseException - if there is a problem with the query

getColumnDisplaySize

public int getColumnDisplaySize(int column)
                         throws DatabaseException
Get maximum size of column.
Specified by:
getColumnDisplaySize in interface DatabaseTable
Parameters:
column - index of column
Returns:
maximum size of column in characters
Throws:
DatabaseException - if there is a problem with the query

addColumn

public void addColumn(String name,
                      int type,
                      int maxlen)
               throws DatabaseException
Add a new column.
Specified by:
addColumn in interface DatabaseTable
Throws:
DatabaseException - always since table is read-only

next

public boolean next()
             throws DatabaseException
Advance to next row in table.
Specified by:
next in interface DatabaseTableBase
Returns:
true if a valid row was found
Throws:
DatabaseException - if there is a problem with the query

deleteRow

public void deleteRow()
               throws DatabaseException
Delete current row.
Specified by:
deleteRow in interface DatabaseTableBase
Throws:
DatabaseException - always since table is read-only

addRow

public void addRow()
            throws DatabaseException
Add a new row.
Specified by:
addRow in interface DatabaseTable
Throws:
DatabaseException - always since table is read-only

isBeforeFirst

public boolean isBeforeFirst()
Are we before the first row?
Specified by:
isBeforeFirst in interface DatabaseTableBase
Returns:
true if table is before the first row

isAfterLast

public boolean isAfterLast()
Are we after the last row?
Specified by:
isAfterLast in interface DatabaseTableBase
Returns:
true if table is after the last row

beforeFirst

public void beforeFirst()
                 throws DatabaseException
Reset current row to before the first row in table.
Specified by:
beforeFirst in interface DatabaseTableBase
Throws:
DatabaseException - if there is a problem with the query

afterLast

public void afterLast()
Set current row to after last row in table.
Specified by:
afterLast in interface DatabaseTableBase
Following copied from interface: ModSQL.DatabaseTableBase
Throws:
DatabaseException - if a database-access error occurs

getRowId

public Object getRowId()
Returns the rowid for the current row.
Specified by:
getRowId in interface DatabaseTableBase
Returns:
rowid object

absolute

public boolean absolute(Object id)
                 throws DatabaseException
Move to an absolute rowid in the table.
Specified by:
absolute in interface DatabaseTable
Parameters:
rowid - id of row to seek
Returns:
true if row was found, false otherwise
Throws:
DatabaseException - always since this method is not supported

getObject

public Object getObject(int column)
                 throws DatabaseException
Get the value of a column in the current row as a Java object.
Specified by:
getObject in interface DatabaseTableBase
Parameters:
column - index of column
Returns:
an Object holding the column value
Throws:
DatabaseException - if there is a problem with the query

updateObject

public void updateObject(int column,
                         Object x)
                  throws DatabaseException
Update value of column.
Specified by:
updateObject in interface DatabaseTableBase
Parameters:
column - index of column to update
x - new column value
Throws:
DatabaseException - always since table is read-only

commitUpdates

public void commitUpdates()
                   throws DatabaseException
Commit column updates.
Specified by:
commitUpdates in interface DatabaseTableBase
Throws:
DatabaseException - always since table is read-only