ModSQL
Class LiteralRow

java.lang.Object
  |
  +--ModSQL.AbstractFunction
        |
        +--ModSQL.LiteralRow
All Implemented Interfaces:
Function, RowConstructor

public class LiteralRow
extends AbstractFunction
implements RowConstructor

This class represents a literal row constructor. That is, a row constructor of the form '(value,...)', where each value is of type Function.

Columns are added to the row constructor using the addParameter() method.

Author:
chris.studholme@utoronto.ca

Fields inherited from class ModSQL.AbstractFunction
all_constant, constant_non_null, evaluate_order, evaluate_order_array, out_of_order, parameter_constant, parameter_value, parameters, parameters_array
 
Fields inherited from interface ModSQL.Function
MATCH_BEGINS, MATCH_EQU, MATCH_GT, MATCH_GTE, MATCH_LT, MATCH_LTE, MATCH_NE
 
Constructor Summary
LiteralRow()
          Default constructor (no columns).
LiteralRow(Function first_column)
          Constructor to set first column.
 
Method Summary
 Object evaluate(boolean aggregate)
          Evaluate row.
 Object evaluate(int match_op, Object match_value)
          Evaluate row.
 Object[] evaluateRow(boolean aggregate)
          Evaluate each column of the row and return the results as an array of length equal to the value returned by getColumnCount().
 String functionName()
          Function name is blank (empty String) for row constructors.
 int getColumnCount()
          Returns the number of columns the row has.
 int getMaxResultSize()
          Return the maximum number of characters that this function expects to return in a String object.
 int getMaxResultSize(int column)
          Return the maximum number of characters String values in the specified column will have.
 int getSQLType()
          Return the SQL type of the value that this function expects to return.
 int getSQLType(int column)
          Return the SQL type of the value in the specified column.
 void optimize()
          Prepare the row for use.
 String toString()
          Returns "column1" or "(column1,column2,...)".
 
Methods inherited from class ModSQL.AbstractFunction
addParameter, convertToSQLType, evaluateConstantParameters, evaluateOrder, evaluateParameters, evaluateParameters, getCompatableType, getObjectSQLType, getParameter, getParameterCount, isAggregate, isConstant, postfixParameters, prefixParameters, registerWith, reset
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 
Methods inherited from interface ModSQL.Function
addParameter, evaluateOrder, getParameter, getParameterCount, isAggregate, isConstant, registerWith, reset
 

Constructor Detail

LiteralRow

public LiteralRow()
Default constructor (no columns).

LiteralRow

public LiteralRow(Function first_column)
           throws SQLException
Constructor to set first column.
Parameters:
first_column - Function representing first column
Throws:
SQLException - if an error occurs
Method Detail

optimize

public void optimize()
              throws SQLException
Prepare the row for use. A row constructor must consist of at least one column (otherwise, an exception is thrown). Furthermore, if any of the columns are constant, they are evaluated here.
Specified by:
optimize in interface Function
Overrides:
optimize in class AbstractFunction
Throws:
SQLException - if an error occurs

functionName

public String functionName()
Function name is blank (empty String) for row constructors.
Overrides:
functionName in class AbstractFunction
Following copied from class: ModSQL.AbstractFunction
Returns:
name of function

toString

public String toString()
Returns "column1" or "(column1,column2,...)".
Overrides:
toString in class AbstractFunction
Returns:
human-readable version of row constructor

getColumnCount

public int getColumnCount()

Returns the number of columns the row has. The row will always have at least one column.

This method should only be called after optimize().

Specified by:
getColumnCount in interface RowConstructor
Returns:
number of columns in row

getSQLType

public int getSQLType()
               throws SQLException
Return the SQL type of the value that this function expects to return. This version of this method can only be used if the row has exactly one column. Otherwise, an exception is thrown.
Specified by:
getSQLType in interface Function
Returns:
SQL type of data to be returned
Throws:
SQLException - if an error occurs

getSQLType

public int getSQLType(int column)
               throws SQLException
Return the SQL type of the value in the specified column.
Specified by:
getSQLType in interface RowConstructor
Parameters:
column - column number (starting from zero)
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. This version of this method can only be used if the row has exactly one column. Otherwise, an exception is thrown.
Specified by:
getMaxResultSize in interface Function
Returns:
maximum size of String returned or -1 if unknown
Throws:
SQLException - if an error occurs

getMaxResultSize

public int getMaxResultSize(int column)
                     throws SQLException
Return the maximum number of characters String values in the specified column will have. If the column is not of String type or if the maximum length is not known, -1 should be returned.
Specified by:
getMaxResultSize in interface RowConstructor
Parameters:
column - column number (starting from zero)
Returns:
maximum size of String returned or -1 if unknown
Throws:
SQLException - if an error occurs

evaluate

public Object evaluate(boolean aggregate)
                throws SQLException,
                       EndOfTable
Evaluate row. This version of this method can only be used if the row has exactly one column. Otherwise, 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 thrown by a column

evaluate

public Object evaluate(int match_op,
                       Object match_value)
                throws SQLException,
                       EndOfTable
Evaluate row. This version of this method can only be used if the row has exactly one column. Otherwise, an exception is thrown.
Specified by:
evaluate in interface Function
Overrides:
evaluate in class AbstractFunction
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 thrown by a column

evaluateRow

public Object[] evaluateRow(boolean aggregate)
                     throws SQLException,
                            EndOfTable
Evaluate each column of the row and return the results as an array of length equal to the value returned by getColumnCount().
Specified by:
evaluateRow in interface RowConstructor
Returns:
array of objects
Throws:
SQLException - if an error occurs
EndOfTable - if thrown by a column