ModSQL
Class ColumnValue

java.lang.Object
  |
  +--ModSQL.ColumnValue
All Implemented Interfaces:
Function

public class ColumnValue
extends Object
implements Function

This object is used to retrieve the value of specific of a database table.

Author:
chris.studholme@utoronto.ca

Field Summary
protected  int column
          Index of column within table.
private  boolean index_checked
          Set to true if an index was searched for.
private  boolean indexed
          Set to true if this column is indexed.
private  TableReader reader
          TableReader managing the table we get data from.
protected  int table
          Index of table in TableReader.
private  int type
          Column type (one of java.sql.Types values).
private  Object value
          Value of column (valid if value_valid==true).
private  boolean value_valid
          Set to true if the value is valid.
 
Fields inherited from interface ModSQL.Function
MATCH_BEGINS, MATCH_EQU, MATCH_GT, MATCH_GTE, MATCH_LT, MATCH_LTE, MATCH_NE
 
Constructor Summary
ColumnValue(TableReader reader, int table, int column)
          Constructor.
 
Method Summary
 void addParameter(Function item)
          Adds a parameter to the list of parameters.
 Object evaluate(boolean aggregate)
          Return the value of the column in the current row.
 Object evaluate(int match_op, Object match_value)
          Return the value of the column in the current row.
 void evaluateOrder(int index, int order)
          Specify the order in which the parameters should be evaluated.
 int getMaxResultSize()
          Return the maximum number of characters that this function expects to return in a String object.
 Function getParameter(int index)
          Get a particular parameter.
 int getParameterCount()
          Number of parameters.
 int getSQLType()
          Return the SQL type of the value that this function expects to return.
 void invalidate()
          Invalidate cached value.
 boolean isAggregate()
          Determine if this function will return a value that is an aggregate of many database rows.
 boolean isConstant()
          Determine if this function returns a constant value.
 void optimize()
          This implementation only sets the type variable.
 void registerWith(Object o)
          This method is used by the TableReader object when ordering parameters.
 void reset()
          Reset aggregate function.
 void setValue(Object v)
          Set cached value and mark the value as valid.
 String toString()
          Returns "table_alias.column_name".
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

reader

private TableReader reader
TableReader managing the table we get data from.

table

protected int table
Index of table in TableReader.

column

protected int column
Index of column within table.

index_checked

private boolean index_checked
Set to true if an index was searched for.

indexed

private boolean indexed
Set to true if this column is indexed.

value_valid

private boolean value_valid
Set to true if the value is valid.

value

private Object value
Value of column (valid if value_valid==true).

type

private int type
Column type (one of java.sql.Types values).
Constructor Detail

ColumnValue

public ColumnValue(TableReader reader,
                   int table,
                   int column)
Constructor.
Parameters:
reader - TableReader managing table
table - index of table in reader
column - index of column in table
Method Detail

getParameterCount

public int getParameterCount()
Number of parameters. ColumnValue does not support parameters so this method always returns 0.
Specified by:
getParameterCount in interface Function
Returns:
0

getParameter

public Function getParameter(int index)
Get a particular parameter. ColumnValue does not support parameters.
Specified by:
getParameter in interface Function
Parameters:
index - index of parameter to get
Returns:
parameter (function)
Throws:
IndexOutOfBoundsException - in all cases

addParameter

public void addParameter(Function item)
                  throws SQLException
Adds a parameter to the list of parameters. ColumnValue does not support parameters.
Specified by:
addParameter in interface Function
Parameters:
item - function to add
Throws:
SQLException - in all cases

evaluateOrder

public void evaluateOrder(int index,
                          int order)
Specify the order in which the parameters should be evaluated. ColumnValue does not support parameters.
Specified by:
evaluateOrder in interface Function
Parameters:
index - index of parameter
order - number indicating order in which parameter is evaluated
Throws:
IndexOutOfBoundsException - in all cases

registerWith

public void registerWith(Object o)
                  throws SQLException

This method is used by the TableReader object when ordering parameters. The TableReader object will call this method with a TableReader.TableAccess object to find out which columns are accessed by each parameter and whether those columns are indexed or not.

Objects of any other type are ignored.

Specified by:
registerWith in interface Function
Parameters:
o - object to register with
Throws:
SQLException - if an error occurs

optimize

public void optimize()
              throws SQLException
This implementation only sets the type variable.
Specified by:
optimize in interface Function
Throws:
SQLException - if an error occurs

isConstant

public boolean isConstant()
Determine if this function returns a constant value. ColumnValues are never constant.
Specified by:
isConstant in interface Function
Returns:
false

isAggregate

public boolean isAggregate()
Determine if this function will return a value that is an aggregate of many database rows. ColumnValues are never aggregate.
Specified by:
isAggregate in interface Function
Returns:
false

getSQLType

public int getSQLType()
               throws SQLException
Return the SQL type of the value that this function expects to return. The data returned by the function must either be of this type, or null.
Specified by:
getSQLType in interface Function
Returns:
SQL type of data to be returned
Throws:
SQLException - if an error occurs

getMaxResultSize

public int getMaxResultSize()
                     throws SQLException
Return the maximum number of characters that this function expects to return in a String object. If the function does not expect to return a String object or if it cannot guess a maximum value, -1 should be returned.
Specified by:
getMaxResultSize in interface Function
Returns:
maximum size of String returned or -1 if unknown
Throws:
SQLException - if an error occurs

toString

public String toString()
Returns "table_alias.column_name". If the table does not have an alias, "table_name.column_name" is returned.
Overrides:
toString in class Object
Returns:
human readable description of column

invalidate

public void invalidate()
Invalidate cached value.

setValue

public void setValue(Object v)
Set cached value and mark the value as valid.
Parameters:
v - value to set

reset

public void reset()
Reset aggregate function. This method does nothing.
Specified by:
reset in interface Function
Following copied from interface: ModSQL.Function
Throws:
SQLException - if an error occurs

evaluate

public Object evaluate(boolean aggregate)
                throws SQLException,
                       EndOfTable

Return the value of the column in the current row. If the value of the column has been cached and is valid, that value is returned. Otherwise, a value is read from the TableReader, and if the TableReader is forced to advance to the next row in the database, EndOfTable may be thrown.

If aggregate is true, an exception is thrown.

Specified by:
evaluate in interface Function
Parameters:
aggregate - true to return final aggregate value
Returns:
result object
Throws:
SQLException - if an error occurs
EndOfTable - if the end of the table is reached

evaluate

public Object evaluate(int match_op,
                       Object match_value)
                throws SQLException,
                       EndOfTable

Return the value of the column in the current row. If the value of the column has been cached and is valid, that value is returned. Otherwise, a value is read from the TableReader, and if the TableReader is forced to advance to the next row in the database, EndOfTable may be thrown.

If the TableReader is read from and match_op is MATCH_EQU, an attempt is made to find a row in the database where the column constains match_value. An index may be used to speed up this search. This method makes no guarantee that such a value can be found and may return some other value (even in cases where the desired row exists).

Specified by:
evaluate in interface Function
Parameters:
match_op - how desired value is matched
match_value - value to match to
Returns:
result object
Throws:
SQLException - if an error occurs
EndOfTable - if the end of the table is reached