org.apache.torque.util.functions
Class AbstractFunction

java.lang.Object
  extended by org.apache.torque.util.functions.AbstractFunction
All Implemented Interfaces:
SQLFunction
Direct Known Subclasses:
Aggregate.AgregateFunction

public abstract class AbstractFunction
extends java.lang.Object
implements SQLFunction

A default framework that implements the core SQLFunction interface requirements that can be used to build specific functions on.

Version:
$Id
Author:
Greg Monroe

Constructor Summary
protected AbstractFunction()
          Functions should only be created via the FunctionFactory class.
 
Method Summary
protected  void addArgument(java.lang.Object arg)
          Add an argument to the function argument list
abstract  java.lang.String getArgument(int i)
          Return a string representation of the function parameter at the specified index.
protected  java.util.List getArgumentList()
          Get the full list of function arguments
protected  java.lang.Object getArgumentObject(int index)
          Return the object representation of the function parameter at the specified index.
 java.lang.Object[] getArguments()
          Return all the parameters as an object array.
 java.lang.String getDBName()
          Get the name of the Torque Database associated with this function.
protected  void setArgumentList(java.util.List args)
          Set the full function argument list.
 void setDBName(java.lang.String dbName)
          Sets the Torque DB name this function is being used with.
abstract  java.lang.String toSQL()
          This should return the SQL string that can be used when constructing the query.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.torque.util.functions.SQLFunction
setArguments
 

Constructor Detail

AbstractFunction

protected AbstractFunction()
Functions should only be created via the FunctionFactory class.

Method Detail

toSQL

public abstract java.lang.String toSQL()
This should return the SQL string that can be used when constructing the query. E.g. "AVG( table.column )" or CONCAT(table.column, " foobar");

Specified by:
toSQL in interface SQLFunction
Returns:
The SQL String.

getArgument

public abstract java.lang.String getArgument(int i)
Return a string representation of the function parameter at the specified index. Should be null if parameter does not exist.

Specified by:
getArgument in interface SQLFunction
Parameters:
index - The 0 based index of the parameter to get.
Returns:
A String representation of the parameter. Null if one does not exist.

getArguments

public java.lang.Object[] getArguments()
Return all the parameters as an object array. This allow for processing of the parameters in their original format rather than just in String format. E.g. a parameter might be specified as a Date object, or a Column object.

Specified by:
getArguments in interface SQLFunction
Returns:
Should return a valid Object array and not null. E.g. implementors should return new Object[0] if there are no parameters.

getDBName

public java.lang.String getDBName()
                           throws java.lang.IllegalStateException
Get the name of the Torque Database associated with this function.

Specified by:
getDBName in interface SQLFunction
Returns:
The DB name. Should not be null (use default DB in this case).
Throws:
java.lang.IllegalStateException - If Torque has not been initialized and the default DB name can not be determined.

getArgumentObject

protected java.lang.Object getArgumentObject(int index)
Return the object representation of the function parameter at the specified index. Will be null if parameter does not exist.

Parameters:
index - The 0 based index of the parameter to get.
Returns:
The parameter object. Null if one does not exist.

addArgument

protected void addArgument(java.lang.Object arg)
Add an argument to the function argument list

Parameters:
arg - The argument object.

setArgumentList

protected void setArgumentList(java.util.List args)
Set the full function argument list.

Parameters:
args - The new argument list

getArgumentList

protected java.util.List getArgumentList()
Get the full list of function arguments

Returns:
The argument list

setDBName

public void setDBName(java.lang.String dbName)
Description copied from interface: SQLFunction
Sets the Torque DB name this function is being used with.

Specified by:
setDBName in interface SQLFunction
Parameters:
dbName - the dbName to set


Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.