org.apache.torque.util.functions
Class AbstractFunction

java.lang.Object
  extended by org.apache.torque.util.functions.AbstractFunction
All Implemented Interfaces:
Column, SQLFunction

public abstract class AbstractFunction
extends Object
implements SQLFunction

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

Version:
$Id: AbstractFunction.java 1448414 2013-02-20 21:06:35Z tfischer $
Author:
Greg Monroe

Constructor Summary
protected AbstractFunction()
          Functions should only be created via the FunctionFactory class.
 
Method Summary
protected  void addArgument(Object arg)
          Add an argument to the function argument list
 Object getArgument(int index)
          Return the object representation of the function parameter at the specified index.
protected  List<Object> getArgumentList()
          Get the full list of function arguments
 Object[] getArguments()
          Return all the parameters as an object array.
 Column getColumn()
          Returns the column to which this function is applied.
 String getColumnName()
          Returns the column name.
 String getFullTableName()
          Returns the table name prefixed with the schema name if it exists from the function argument(s).
 String getSchemaName()
          Returns the name of any fixed schema prefix for the column's table (if any) from the function argument(s).
abstract  String getSqlExpression()
          This should return the SQL string that can be used when constructing the query.
 String getTableName()
          Returns the name of the associated table (not prefixed by the schema name) from the function argument(s).
protected  void setArgumentList(List<Object> args)
          Set the full function argument list.
 void setArguments(Object[] args)
          Sets the function arguments.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractFunction

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

Method Detail

getSqlExpression

public abstract String getSqlExpression()
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:
getSqlExpression in interface Column
Returns:
The SQL String.

getArguments

public 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.

setArguments

public void setArguments(Object[] args)
Sets the function arguments.

Specified by:
setArguments in interface SQLFunction
Parameters:
args - the function arguments, not null.

getColumn

public Column getColumn()
Returns the column to which this function is applied.

Specified by:
getColumn in interface SQLFunction
Returns:
the column, not null.
Throws:
IllegalStateException - if the column cannot be determined.

getArgument

public Object getArgument(int index)
Return the object representation of the function parameter at the specified index. Will 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:
The parameter object. Null if one does not exist.

addArgument

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

Parameters:
arg - The argument object.

setArgumentList

protected void setArgumentList(List<Object> args)
Set the full function argument list.

Parameters:
args - The new argument list

getArgumentList

protected List<Object> getArgumentList()
Get the full list of function arguments

Returns:
The argument list

getColumnName

public String getColumnName()
Returns the column name. This implementation always return null because we do not reference a real column.

Specified by:
getColumnName in interface Column
Returns:
the column name, always null.

getTableName

public String getTableName()
Returns the name of the associated table (not prefixed by the schema name) from the function argument(s). In case that no unique table name can be determined, null is returned.

Specified by:
getTableName in interface Column
Returns:
the name of the table, may be null but not blank.

getSchemaName

public String getSchemaName()
Returns the name of any fixed schema prefix for the column's table (if any) from the function argument(s). In case that no unique schema can be determined, null is returned.

Specified by:
getSchemaName in interface Column
Returns:
the schema name, or null if the schema is not known.

getFullTableName

public String getFullTableName()
Returns the table name prefixed with the schema name if it exists from the function argument(s). I.e. if a schema name exists, the result will be schemaName.tableName, and otherwise it will just be tableName. In case that no unique full table can be determined, null is returned.

Specified by:
getFullTableName in interface Column
Returns:
the fully qualified table name may be null but not blank.


Copyright © 2000-2013 The Apache Software Foundation. All Rights Reserved.