Top Description Inners Fields Constructors Methods
org.hibernate.dialect.function

public Class DerbyConcatFunction

extends Object
implements SQLFunction
Class Inheritance
All Implemented Interfaces
org.hibernate.dialect.function.SQLFunction
Imports
java.util.Iterator, .List, org.hibernate.QueryException, org.hibernate.engine.spi.Mapping, .SessionFactoryImplementor, org.hibernate.type.StandardBasicTypes, .Type

A specialized concat() function definition in which:
  1. we translate to use the concat operator ('||')
  2. wrap dynamic parameters in CASTs to VARCHAR

This last spec is to deal with a limitation on DB2 and variants (e.g. Derby) where dynamic parameters cannot be used in concatenation unless they are being concatenated with at least one non-dynamic operand. And even then, the rules are so convoluted as to what is allowed and when the CAST is needed and when it is not that we just go ahead and do the CASTing.

Author
Steve Ebersole

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface
private static interface

Field Summary

Modifier and TypeField and Description
private static final DerbyConcatFunction.StringTransformer
private static final DerbyConcatFunction.StringTransformer

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Type
getReturnType(Type
The type of the first argument
argumentType
,
Mapping
The mapping source.
mapping
)

Implements org.hibernate.dialect.function.SQLFunction.getReturnType.

The return type of the function.
public boolean
hasArguments()

Implements org.hibernate.dialect.function.SQLFunction.hasArguments.

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

Implements org.hibernate.dialect.function.SQLFunction.hasParenthesesIfNoArguments.

If there are no arguments, are parentheses required?
private static String
public String
render(Type
The type of the first argument
argumentType
,
List<E>
The function arguments
args
,
SessionFactoryImplementor
The SessionFactory
factory
)

Implements org.hibernate.dialect.function.SQLFunction.render.

Deprecated as a consequence of SessionFactoryImplementor being deprecated.
Render the function call as SQL fragment.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CAST_STRING_TRANSFORMERback to summary
private static final DerbyConcatFunction.StringTransformer CAST_STRING_TRANSFORMER
NO_TRANSFORM_STRING_TRANSFORMERback to summary
private static final DerbyConcatFunction.StringTransformer NO_TRANSFORM_STRING_TRANSFORMER

Constructor Detail

DerbyConcatFunctionback to summary
public DerbyConcatFunction()

Method Detail

getReturnTypeback to summary
public Type getReturnType(Type argumentType, Mapping mapping) throws QueryException

Implements org.hibernate.dialect.function.SQLFunction.getReturnType.

Doc from org.hibernate.dialect.function.SQLFunction.getReturnType.

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 render

Here we always return StandardBasicTypes#STRING.

Parameters
argumentType:Type

The type of the first argument

mapping:Mapping

The mapping source.

Returns:Type

The type to be expected as a return.

Annotations
@Override
Exceptions
QueryException:
Indicates an issue resolving the return type.
hasArgumentsback to summary
public boolean hasArguments()

Implements org.hibernate.dialect.function.SQLFunction.hasArguments.

Doc from org.hibernate.dialect.function.SQLFunction.hasArguments.

Does this function have any arguments?

Here we always return true

Returns:boolean

True if the function expects to have parameters; false otherwise.

Annotations
@Override
hasParenthesesIfNoArgumentsback to summary
public boolean hasParenthesesIfNoArguments()

Implements org.hibernate.dialect.function.SQLFunction.hasParenthesesIfNoArguments.

Doc from org.hibernate.dialect.function.SQLFunction.hasParenthesesIfNoArguments.

If there are no arguments, are parentheses required?

Here we always return true

Returns:boolean

True if a no-arg call of this function requires parentheses.

Annotations
@Override
joinback to summary
private static String join(Iterator<E> elements, DerbyConcatFunction.StringTransformer elementTransformer, DerbyConcatFunction.StringJoinTemplate template)
renderback to summary
public String render(Type argumentType, List<E> args, SessionFactoryImplementor factory) throws QueryException

Implements org.hibernate.dialect.function.SQLFunction.render.

Doc from org.hibernate.dialect.function.SQLFunction.render.

Deprecated

as a consequence of SessionFactoryImplementor being deprecated. See corresponding docs for further information.

Render the function call as SQL fragment.

Note, the 'firstArgumentType' parameter should match the one passed into getReturnType

Here's the meat.. The whole reason we have a separate impl for this for Derby is to re-define this method. The logic here says that if not all the incoming args are dynamic parameters (i.e. ?) then we simply use the Derby concat operator (||) on the unchanged arg elements. However, if all the args are dynamic parameters, then we need to wrap the individual arg elements in cast function calls, use the concatenation operator on the cast returns, and then wrap that whole thing in a call to the Derby varchar function.

Parameters
argumentType:Type

The type of the first argument

args:List<E>

The function arguments

factory:SessionFactoryImplementor

The SessionFactory

Returns:String

The rendered function call

Annotations
@Override
Exceptions
QueryException:
Indicates a problem rendering the function call.
org.hibernate.dialect.function back to summary

private Interface DerbyConcatFunction.StringJoinTemplate


Method Summary

Modifier and TypeMethod and Description
public String

Returns:

Value for property 'beginning'.
getBeginning
()

Getter for property 'beginning'.

public String

Returns:

Value for property 'ending'.
getEnding
()

Getter for property 'ending'.

public String

Returns:

Value for property 'separator'.
getSeparator
()

Getter for property 'separator'.

Method Detail

getBeginningback to summary
public String getBeginning()

Getter for property 'beginning'.

Returns:String

Value for property 'beginning'.

getEndingback to summary
public String getEnding()

Getter for property 'ending'.

Returns:String

Value for property 'ending'.

getSeparatorback to summary
public String getSeparator()

Getter for property 'separator'.

Returns:String

Value for property 'separator'.

org.hibernate.dialect.function back to summary

private Interface DerbyConcatFunction.StringTransformer


Method Summary

Modifier and TypeMethod and Description
public String

Returns:

The transformed form
transform
(String
The String to be transformed
string
)

Transform a string to another

Method Detail

transformback to summary
public String transform(String string)

Transform a string to another

Parameters
string:String

The String to be transformed

Returns:String

The transformed form