|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--ModSQL.AbstractFunction
Abstract implementation of Function to simplify the implementation of real functions.
| Field Summary | |
protected boolean |
all_constant
Are all parameters constant? |
protected boolean |
constant_non_null
Are all of the constant parameters non-null? |
protected int[] |
evaluate_order
Order in which to evaluate parameters. |
protected ArrayList |
evaluate_order_array
Parameter ordering before optimize. |
protected boolean |
out_of_order
Are the parameters out-of-order? Used by toString(). |
protected boolean[] |
parameter_constant
Array to keep track of which parameters are constant. |
protected Object[] |
parameter_value
Array for storing parameter values (constant or otherwise). |
protected Function[] |
parameters
Array of parameters after optimize. |
protected ArrayList |
parameters_array
Array of parameters before optimize. |
| Fields inherited from interface ModSQL.Function |
MATCH_BEGINS, MATCH_EQU, MATCH_GT, MATCH_GTE, MATCH_LT, MATCH_LTE, MATCH_NE |
| Constructor Summary | |
AbstractFunction()
Default constructor. |
|
| Method Summary | |
void |
addParameter(Function item)
Adds a parameter to the list of parameters maintained by this function. |
static Object |
convertToSQLType(Object o,
int type)
Convert an Object to a compatible Object corresponding to the provided SQL type. |
Object |
evaluate(int match_op,
Object match_value)
Default implementation that simply calls evaluate(false). |
boolean |
evaluateConstantParameters()
Evaluate parameters that advertise themselves as constant. |
void |
evaluateOrder(int index,
int order)
Specify the order in which the parameters should be evaluated. |
protected boolean |
evaluateParameters(boolean aggregate)
Same as above version, but with stop_at_null set to false. |
protected boolean |
evaluateParameters(boolean aggregate,
boolean stop_at_null)
Evaluates all parameters and stores the results in the parameter_value array. |
abstract String |
functionName()
Returns the name of this function for use by the toString() method. |
static int |
getCompatableType(int t1,
int t2)
Determine a java.sql.Types type that is compatable with both of the passed parameters. |
static int |
getObjectSQLType(Object o)
Determine the SQL type of a java Object. |
Function |
getParameter(int index)
Get a particular parameter. |
int |
getParameterCount()
Get the number of parameters currently supplied to this function. |
boolean |
isAggregate()
The implementation of this method is intended to be used by non-aggregate functions. |
boolean |
isConstant()
Determine if this function returns a constant value. |
void |
optimize()
This method sets up static arrays for the parameters and their values, calls optimize() for each parameter, and initializes the evalute_order array to appropriate values (using information provided using evaluateOrder(), if any). |
String |
postfixParameters()
Optional String to insert after parameter list in toString(). |
String |
prefixParameters()
Optional String to insert before parameter list in toString(). |
void |
registerWith(Object o)
This implementation simply calls registerWith() for all parameters. |
void |
reset()
This implementation simply calls reset() for all parameters and is intended to be used by non-aggregate functions. |
String |
toString()
Outputs "functionName(parameter,...)". |
| Methods inherited from class java.lang.Object |
|
| Methods inherited from interface ModSQL.Function |
evaluate, getMaxResultSize, getSQLType |
| Field Detail |
protected ArrayList parameters_array
protected ArrayList evaluate_order_array
protected Function[] parameters
protected Object[] parameter_value
protected boolean[] parameter_constant
protected boolean all_constant
protected boolean constant_non_null
protected int[] evaluate_order
protected boolean out_of_order
| Constructor Detail |
public AbstractFunction()
| Method Detail |
public int getParameterCount()
getParameterCount in interface Functionpublic Function getParameter(int index)
getParameter in interface Functionindex - index of parameter to get
public void addParameter(Function item)
throws SQLException
addParameter in interface Functionitem - function to addSQLException - if optimize has already been called
public void evaluateOrder(int index,
int order)
throws SQLException
evaluateOrder in interface Functionindex - index of parameterorder - number indicating order in which parameter is evaluatedSQLException - if optimize has already been called
public void registerWith(Object o)
throws SQLException
registerWith in interface Functiono - object to register withSQLException - if an error occurs
public void optimize()
throws SQLException
This method sets up static arrays for the parameters and their values, calls optimize() for each parameter, and initializes the evalute_order array to appropriate values (using information provided using evaluateOrder(), if any).
The all_constant variable is initialized to true if and only if the number of parameters is 0. The constant_non_null variable is initialized to true. The parameter_constant array is not initialized. Use evaluateConstantParameters() after optimize() to initialize these variables to more useful values.
optimize in interface FunctionSQLException - if an error occurs
public boolean evaluateConstantParameters()
throws SQLException
Evaluate parameters that advertise themselves as constant. This method initializes the parameter_constant, all_constant, and constant_non_null variables to their correct values.
This method may only be used after optimize() has been called. Typically, a class that overrides optimize() will first call super.optimize() and then use this method later within their new optimize() implementation.
SQLException - if an error occurs while evaluating a parameterpublic abstract String functionName()
public String prefixParameters()
public String postfixParameters()
public String toString()
toString in class Object
public boolean isConstant()
throws SQLException
isConstant in interface FunctionSQLException - if an error occurs
public boolean isAggregate()
throws SQLException
The implementation of this method is intended to be used by non-aggregate functions. Aggregate functions should extend AbstractAggregate instead of AbstractFunction. This implementation will return true if and only if all of the function's parameters are either aggregate or constant.
isAggregate in interface FunctionSQLException - if an error occurs
protected boolean evaluateParameters(boolean aggregate,
boolean stop_at_null)
throws SQLException,
EndOfTable
aggregate - evaluate aggregatesstop_at_null - stop if a null if foundSQLException - if an error occursEndOfTable - if thrown by a parameter
protected boolean evaluateParameters(boolean aggregate)
throws SQLException,
EndOfTable
aggregate - evaluate aggregatesSQLException - if an error occursEndOfTable - if thrown by a parameter
public Object evaluate(int match_op,
Object match_value)
throws SQLException,
EndOfTable
evaluate in interface Functionmatch_op - how the value should be matchedmatch_value - desired valueSQLException - if an error occursEndOfTable - if thrown by a parameter
public void reset()
throws SQLException
reset in interface FunctionSQLException - if an error occurs
public static Object convertToSQLType(Object o,
int type)
throws SQLException
o - Object to converttype - type from java.sql.Types to convert toSQLException - if no compatible type is availablepublic static int getObjectSQLType(Object o)
o - object to check
public static int getCompatableType(int t1,
int t2)
throws SQLException
t1 - type of first valuet2 - type of second valueSQLException - if the types are incompatible
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||