Package org.apache.torque.util.functions
Class AbstractFunction
- java.lang.Object
-
- 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 1879896 2020-07-15 15:03:46Z gk $
- Author:
- Greg Monroe
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractFunction()
Functions should only be created via the FunctionFactory class.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addArgument(Object arg)
Add an argument to the function argument listObject
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 argumentsObject[]
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.
-
-
-
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 interfaceColumn
- 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 interfaceSQLFunction
- 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 interfaceSQLFunction
- Parameters:
args
- the function arguments, not null.
-
getColumn
public Column getColumn()
Returns the column to which this function is applied.- Specified by:
getColumn
in interfaceSQLFunction
- 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 interfaceSQLFunction
- 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 interfaceColumn
- 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 interfaceColumn
- 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 interfaceColumn
- 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 interfaceColumn
- Returns:
- the fully qualified table name may be null but not blank.
-
-