org.apache.torque.util.functions
Class FunctionFactory

java.lang.Object
  extended by org.apache.torque.util.functions.FunctionFactory

public class FunctionFactory
extends java.lang.Object

This class is a "Factory class" for creating SQLFunction implementation classes. It works with the DB adaptor classes to create functions that are appropriate for the specified (or default) db server type.

The generic method for doing this is the functionInstance(String, FunctionEnum, Object[]) method. However, there are a variety of convenience methods that can be used to quickly created specific functions, e.g. avg( Object ) and the like.

Version:
$Id
Author:
Greg Monroe
See Also:
SQLFunction, SummaryHelper

Method Summary
static SQLFunction avg(java.lang.Object expr1)
          Convenience method for creating a non-distinct function that uses the default DB.
static SQLFunction avg(java.lang.String dbName, java.lang.Object expr1, boolean distinct)
          Create an AVG SQL function implementation.
static SQLFunction count(java.lang.Object expr1)
          Convenience method for creating a non-distinct function that uses the default DB.
static SQLFunction count(java.lang.String dbName, java.lang.Object expr1, boolean distinct)
          Create a COUNT SQL function implementation.
static SQLFunction functionInstance(FunctionEnum function, java.lang.Object[] arguments)
           
static SQLFunction functionInstance(java.lang.String dbName, FunctionEnum function, java.lang.Object[] arguments)
          "Generic" function class creation method.
static SQLFunction max(java.lang.Object expr1)
          Convenience method for creating a non-distinct function that uses the default DB.
static SQLFunction max(java.lang.String dbName, java.lang.Object expr1, boolean distinct)
          Create a MAX SQL function implementation.
static SQLFunction min(java.lang.Object expr1)
          Convenience method for creating a non-distinct function that uses the default DB.
static SQLFunction min(java.lang.String dbName, java.lang.Object expr1, boolean distinct)
          Create a MIN SQL function implementation.
static SQLFunction sum(java.lang.Object expr1)
          Convenience method for creating a non-distinct function that uses the default DB.
static SQLFunction sum(java.lang.String dbName, java.lang.Object expr1, boolean distinct)
          Create a SUM SQL function implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

avg

public static final SQLFunction avg(java.lang.String dbName,
                                    java.lang.Object expr1,
                                    boolean distinct)
                             throws java.lang.Exception
Create an AVG SQL function implementation.

Parameters:
dbName - The name of the Torque db
expr1 - The expression to apply the function to. Generally a column name in table.column format. It is assumed that the "toString()" method of this object will be acceptable for an argument.
distinct - If true, the function expr will have be prefaced with "DISTINCT", e.g. function(DISTINCT column).
Returns:
The function object to use.
Throws:
java.lang.Exception

avg

public static final SQLFunction avg(java.lang.Object expr1)
                             throws java.lang.Exception
Convenience method for creating a non-distinct function that uses the default DB.

Parameters:
expr1 - The expression to apply the function to. Generally a column name in table.column format. It is assumed that the "toString()" method of this object will be acceptable for an argument.
Returns:
The function object to use.
Throws:
java.lang.Exception

count

public static final SQLFunction count(java.lang.String dbName,
                                      java.lang.Object expr1,
                                      boolean distinct)
                               throws java.lang.Exception
Create a COUNT SQL function implementation.

Parameters:
dbName - The name of the Torque db
expr1 - The expression to apply the function to. Generally a column name in table.column format. It is assumed that the "toString()" method of this object will be acceptable for an argument.
distinct - If true, the function expr will have be prefaced with "DISTINCT", e.g. function(DISTINCT column).
Returns:
The function object to use.
Throws:
java.lang.Exception

count

public static final SQLFunction count(java.lang.Object expr1)
                               throws java.lang.Exception
Convenience method for creating a non-distinct function that uses the default DB.

Parameters:
expr1 - The expression to apply the function to. Generally a column name in table.column format. It is assumed that the "toString()" method of this object will be acceptable for an argument.
Returns:
The function object to use.
Throws:
java.lang.Exception

max

public static final SQLFunction max(java.lang.String dbName,
                                    java.lang.Object expr1,
                                    boolean distinct)
                             throws java.lang.Exception
Create a MAX SQL function implementation.

Parameters:
dbName - The name of the Torque db
expr1 - The expression to apply the function to. Generally a column name in table.column format. It is assumed that the "toString()" method of this object will be acceptable for an argument.
distinct - If true, the function expr will have be prefaced with "DISTINCT", e.g. function(DISTINCT column).
Returns:
The function object to use.
Throws:
java.lang.Exception

max

public static final SQLFunction max(java.lang.Object expr1)
                             throws java.lang.Exception
Convenience method for creating a non-distinct function that uses the default DB.

Parameters:
expr1 - The expression to apply the function to. Generally a column name in table.column format. It is assumed that the "toString()" method of this object will be acceptable for an argument.
Returns:
The function object to use.
Throws:
java.lang.Exception

min

public static final SQLFunction min(java.lang.String dbName,
                                    java.lang.Object expr1,
                                    boolean distinct)
                             throws java.lang.Exception
Create a MIN SQL function implementation.

Parameters:
dbName - The name of the Torque db
expr1 - The expression to apply the function to. Generally a column name in table.column format. It is assumed that the "toString()" method of this object will be acceptable for an argument.
distinct - If true, the function expr will have be prefaced with "DISTINCT", e.g. function(DISTINCT column).
Returns:
The function object to use.
Throws:
java.lang.Exception

min

public static final SQLFunction min(java.lang.Object expr1)
                             throws java.lang.Exception
Convenience method for creating a non-distinct function that uses the default DB.

Parameters:
expr1 - The expression to apply the function to. Generally a column name in table.column format. It is assumed that the "toString()" method of this object will be acceptable for an argument.
Returns:
The function object to use.
Throws:
java.lang.Exception

sum

public static final SQLFunction sum(java.lang.String dbName,
                                    java.lang.Object expr1,
                                    boolean distinct)
                             throws java.lang.Exception
Create a SUM SQL function implementation.

Parameters:
dbName - The name of the Torque db
expr1 - The expression to apply the function to. Generally a column name in table.column format. It is assumed that the "toString()" method of this object will be acceptable for an argument.
distinct - If true, the function expr will have be prefaced with "DISTINCT", e.g. function(DISTINCT column).
Returns:
The function object to use.
Throws:
java.lang.Exception

sum

public static final SQLFunction sum(java.lang.Object expr1)
                             throws java.lang.Exception
Convenience method for creating a non-distinct function that uses the default DB.

Parameters:
expr1 - The expression to apply the function to. Generally a column name in table.column format. It is assumed that the "toString()" method of this object will be acceptable for an argument.
Returns:
The function object to use.
Throws:
java.lang.Exception

functionInstance

public static final SQLFunction functionInstance(java.lang.String dbName,
                                                 FunctionEnum function,
                                                 java.lang.Object[] arguments)
                                          throws java.lang.Exception
"Generic" function class creation method.

Parameters:
dbName - The name of the Torque DB this function applies to or the default Torque DB if null.
function - The function to create an object for.
arguments - The arguments required by the function object.
Returns:
A SQLFunction implementation that for the specified DB server.
Throws:
java.lang.Exception

functionInstance

public static final SQLFunction functionInstance(FunctionEnum function,
                                                 java.lang.Object[] arguments)
                                          throws java.lang.Exception
Throws:
java.lang.Exception


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