org.hibernate.dialect.function
Class VarArgsSQLFunction

java.lang.Object
  extended by org.hibernate.dialect.function.VarArgsSQLFunction
All Implemented Interfaces:
SQLFunction

public class VarArgsSQLFunction
extends Object
implements SQLFunction

Support for slightly more general templating than StandardSQLFunction, with an unlimited number of arguments.

Author:
Gavin King

Constructor Summary
VarArgsSQLFunction(String begin, String sep, String end)
          Constructs a VarArgsSQLFunction instance with a 'dynamic' return type.
VarArgsSQLFunction(Type type, String begin, String sep, String end)
          Constructs a VarArgsSQLFunction instance with a 'static' return type.
 
Method Summary
 Type getReturnType(Type columnType, Mapping mapping)
          The return type of the function.
 boolean hasArguments()
          Does this function have any arguments?
 boolean hasParenthesesIfNoArguments()
          If there are no arguments, are parens required?
 String render(List args, SessionFactoryImplementor factory)
          Render the function call as SQL fragment.
protected  String transformArgument(String argument)
          Called from render(java.util.List, org.hibernate.engine.SessionFactoryImplementor) to allow applying a change or transformation to each individual argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VarArgsSQLFunction

public VarArgsSQLFunction(Type type,
                          String begin,
                          String sep,
                          String end)
Constructs a VarArgsSQLFunction instance with a 'static' return type. An example of a 'static' return type would be something like an UPPER function which is always returning a SQL VARCHAR and thus a string type.

Parameters:
type - The return type.
begin - The beginning of the function templating.
sep - The separator for each individual function argument.
end - The end of the function templating.

VarArgsSQLFunction

public VarArgsSQLFunction(String begin,
                          String sep,
                          String end)
Constructs a VarArgsSQLFunction instance with a 'dynamic' return type. For a dynamic return type, the type of the arguments are used to resolve the type. An example of a function with a 'dynamic' return would be MAX or MIN which return a double or an integer etc based on the types of the arguments.

Parameters:
begin - The beginning of the function templating.
sep - The separator for each individual function argument.
end - The end of the function templating.
See Also:
Specifically, the 'columnType' argument is the 'dynamic' type.
Method Detail

getReturnType

public Type getReturnType(Type columnType,
                          Mapping mapping)
                   throws QueryException
The return type of the function. May be either a concrete type which is preset, or variable depending upon the type of the first function argument.

Specified by:
getReturnType in interface SQLFunction
Parameters:
columnType - the type of the first argument
mapping - The mapping source.
Returns:
The type to be expected as a return.
Throws:
QueryException - Indicates an issue resolving the return type.

hasArguments

public boolean hasArguments()
Does this function have any arguments?

Always returns true here.

Specified by:
hasArguments in interface SQLFunction
Returns:
True if the function expects to have parameters; false otherwise.

hasParenthesesIfNoArguments

public boolean hasParenthesesIfNoArguments()
If there are no arguments, are parens required?

Always returns true here.

Specified by:
hasParenthesesIfNoArguments in interface SQLFunction
Returns:
True if a no-arg call of this function requires parentheses.

render

public String render(List args,
                     SessionFactoryImplementor factory)
              throws QueryException
Render the function call as SQL fragment.

Specified by:
render in interface SQLFunction
Parameters:
args - The function arguments
factory - The SessionFactory
Returns:
The rendered function call
Throws:
QueryException - Indicates a problem rendering the function call.

transformArgument

protected String transformArgument(String argument)
Called from render(java.util.List, org.hibernate.engine.SessionFactoryImplementor) to allow applying a change or transformation to each individual argument.

Parameters:
argument - The argument being processed.
Returns:
The transformed argument; may be the same, though should never be null.


Copyright © 2001-2010 Red Hat, Inc. All Rights Reserved.