com.metamatrix.query.function
Class FunctionLibrary

java.lang.Object
  extended by com.metamatrix.query.function.FunctionLibrary

public class FunctionLibrary
extends java.lang.Object

The function library is the primary way for the system to find out what functions are available, resolve function signatures, and invoke system and user-defined functions.


Field Summary
static java.lang.String CAST
           
static java.lang.String COALESCE
           
static java.lang.String COMMAND_PAYLOAD
           
static java.lang.String CONCAT
           
static java.lang.String CONCAT_OPERATOR
           
static java.lang.String CONCAT2
           
static java.lang.String CONTEXT
           
static java.lang.String CONVERT
           
static java.lang.String DECODEINTEGER
           
static java.lang.String DECODESTRING
           
static java.lang.String ENV
           
static java.lang.String FROM_UNIXTIME
           
static java.lang.String IFNULL
           
static java.lang.String LOOKUP
           
static java.lang.String NULLIF
           
static java.lang.String NVL
           
static java.lang.String ROWLIMIT
           
static java.lang.String ROWLIMITEXCEPTION
           
static java.lang.String SPACE
           
static java.lang.String SUBSTRING
           
static java.lang.String TIMESTAMPADD
           
static java.lang.String USER
           
static java.lang.String XPATHVALUE
           
 
Method Summary
 FunctionDescriptor copyFunctionChangeReturnType(FunctionDescriptor fd, java.lang.Class returnType)
          Return a copy of the given FunctionDescriptor with the sepcified return type.
 FunctionDescriptor[] determineNecessaryConversions(java.lang.String name, java.lang.Class<?> returnType, java.lang.Class<?>[] types, boolean hasUnknownType)
          Get the conversions that are needed to call the named function with arguments of the given type.
 FunctionDescriptor findFunction(java.lang.String name, java.lang.Class[] types)
          Find a function descriptor given a name and the types of the arguments.
 FunctionForm findFunctionForm(java.lang.String name, int numArgs)
          Find function form based on function name and # of arguments.
 FunctionDescriptor findTypedConversionFunction(java.lang.Class sourceType, java.lang.Class targetType)
          Find conversion function and set return type to proper type.
 java.util.List getFunctionCategories()
          Get all function categories, sorted in alphabetical order
 java.util.List getFunctionForms(java.lang.String category)
          Get all function forms in a category, sorted by name, then # of args, then names of args.
 java.lang.Object invokeFunction(FunctionDescriptor fd, java.lang.Object[] values)
          Invoke the function described in the function descriptor, using the values provided.
static boolean isConvert(Function function)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONVERT

public static final java.lang.String CONVERT
See Also:
Constant Field Values

CAST

public static final java.lang.String CAST
See Also:
Constant Field Values

LOOKUP

public static final java.lang.String LOOKUP
See Also:
Constant Field Values

USER

public static final java.lang.String USER
See Also:
Constant Field Values

ENV

public static final java.lang.String ENV
See Also:
Constant Field Values

XPATHVALUE

public static final java.lang.String XPATHVALUE
See Also:
Constant Field Values

CONTEXT

public static final java.lang.String CONTEXT
See Also:
Constant Field Values

ROWLIMIT

public static final java.lang.String ROWLIMIT
See Also:
Constant Field Values

ROWLIMITEXCEPTION

public static final java.lang.String ROWLIMITEXCEPTION
See Also:
Constant Field Values

DECODESTRING

public static final java.lang.String DECODESTRING
See Also:
Constant Field Values

DECODEINTEGER

public static final java.lang.String DECODEINTEGER
See Also:
Constant Field Values

COMMAND_PAYLOAD

public static final java.lang.String COMMAND_PAYLOAD
See Also:
Constant Field Values

CONCAT

public static final java.lang.String CONCAT
See Also:
Constant Field Values

CONCAT2

public static final java.lang.String CONCAT2
See Also:
Constant Field Values

CONCAT_OPERATOR

public static final java.lang.String CONCAT_OPERATOR
See Also:
Constant Field Values

SUBSTRING

public static final java.lang.String SUBSTRING
See Also:
Constant Field Values

NVL

public static final java.lang.String NVL
See Also:
Constant Field Values

IFNULL

public static final java.lang.String IFNULL
See Also:
Constant Field Values

FROM_UNIXTIME

public static final java.lang.String FROM_UNIXTIME
See Also:
Constant Field Values

TIMESTAMPADD

public static final java.lang.String TIMESTAMPADD
See Also:
Constant Field Values

NULLIF

public static final java.lang.String NULLIF
See Also:
Constant Field Values

COALESCE

public static final java.lang.String COALESCE
See Also:
Constant Field Values

SPACE

public static final java.lang.String SPACE
See Also:
Constant Field Values
Method Detail

getFunctionCategories

public java.util.List getFunctionCategories()
Get all function categories, sorted in alphabetical order

Returns:
List of function category names, sorted in alphabetical order

getFunctionForms

public java.util.List getFunctionForms(java.lang.String category)
Get all function forms in a category, sorted by name, then # of args, then names of args.

Parameters:
category - Category name
Returns:
List of FunctionForms in a category

findFunctionForm

public FunctionForm findFunctionForm(java.lang.String name,
                                     int numArgs)
Find function form based on function name and # of arguments.

Parameters:
name - Function name
numArgs - Number of arguments
Returns:
Corresponding form or null if not found

findFunction

public FunctionDescriptor findFunction(java.lang.String name,
                                       java.lang.Class[] types)
Find a function descriptor given a name and the types of the arguments. This method matches based on case-insensitive function name and an exact match of the number and types of parameter arguments.

Parameters:
name - Name of the function to resolve
types - Array of classes representing the types
Returns:
Descriptor if found, null if not found

determineNecessaryConversions

public FunctionDescriptor[] determineNecessaryConversions(java.lang.String name,
                                                          java.lang.Class<?> returnType,
                                                          java.lang.Class<?>[] types,
                                                          boolean hasUnknownType)
Get the conversions that are needed to call the named function with arguments of the given type. In the case of an exact match, the list will contain all nulls. In other cases the list will contain one or more non-null values where the value is a conversion function that can be used to convert to the proper types for executing the function.

Parameters:
name - Name of function
returnType -
types - Existing types passed to the function
Returns:
Null if no conversion could be found, otherwise an array of conversions to apply to each argument. The list should match 1-to-1 with the parameters. Parameters that do not need a conversion are null; parameters that do are FunctionDescriptors.
Throws:
QueryResolverException

findTypedConversionFunction

public FunctionDescriptor findTypedConversionFunction(java.lang.Class sourceType,
                                                      java.lang.Class targetType)
Find conversion function and set return type to proper type.

Parameters:
sourceType - The source type class
targetType - The target type class
Returns:
A CONVERT function descriptor or null if not possible

invokeFunction

public java.lang.Object invokeFunction(FunctionDescriptor fd,
                                       java.lang.Object[] values)
                                throws InvalidFunctionException,
                                       FunctionExecutionException
Invoke the function described in the function descriptor, using the values provided. Return the result of the function.

Parameters:
fd - Function descriptor describing the name and types of the arguments
values - Values that should match 1-to-1 with the types described in the function descriptor
Returns:
Result of invoking the function
Throws:
InvalidFunctionException
FunctionExecutionException

copyFunctionChangeReturnType

public FunctionDescriptor copyFunctionChangeReturnType(FunctionDescriptor fd,
                                                       java.lang.Class returnType)
Return a copy of the given FunctionDescriptor with the sepcified return type.

Parameters:
fd - FunctionDescriptor to be copied.
returnType - The return type to apply to the copied FunctionDescriptor.
Returns:
The copy of FunctionDescriptor.

isConvert

public static boolean isConvert(Function function)


Copyright © 2009. All Rights Reserved.