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.


Constructor Summary
VarArgsSQLFunction(String begin, String sep, String end)
          Constructs a VarArgsSQLFunction instance with a 'dynamic' return type.
VarArgsSQLFunction(Type registeredType, String begin, String sep, String end)
          Constructs a VarArgsSQLFunction instance with a 'static' return type.
 
Method Summary
 Type getReturnType(Type firstArgumentType, Mapping mapping)
          The return type of the function.
 boolean hasArguments()
          Does this function have any arguments?
 boolean hasParenthesesIfNoArguments()
          If there are no arguments, are parentheses required?
 String render(Type firstArgumentType, List arguments, SessionFactoryImplementor factory)
          Render the function call as SQL fragment.
protected  String transformArgument(String argument)
          Called from render(org.hibernate.type.Type, java.util.List, org.hibernate.engine.spi.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 registeredType,
                          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:
registeredType - 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 'firstArgumentType' argument is the 'dynamic' type.
Method Detail

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 parentheses required?

Always returns true here.

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

getReturnType

public Type getReturnType(Type firstArgumentType,
                          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.

Note, the 'firstArgumentType' parameter should match the one passed into SQLFunction.render(org.hibernate.type.Type, java.util.List, org.hibernate.engine.spi.SessionFactoryImplementor)

Specified by:
getReturnType in interface SQLFunction
Parameters:
firstArgumentType - 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.

render

public String render(Type firstArgumentType,
                     List arguments,
                     SessionFactoryImplementor factory)
Description copied from interface: SQLFunction
Render the function call as SQL fragment.

Note, the 'firstArgumentType' parameter should match the one passed into SQLFunction.getReturnType(org.hibernate.type.Type, org.hibernate.engine.spi.Mapping)

Specified by:
render in interface SQLFunction
Parameters:
firstArgumentType - The type of the first argument
arguments - The function arguments
factory - The SessionFactory
Returns:
The rendered function call

transformArgument

protected String transformArgument(String argument)
Called from render(org.hibernate.type.Type, java.util.List, org.hibernate.engine.spi.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-2012 Red Hat, Inc. All Rights Reserved.