此内容没有您所选择的语言版本。
7.6. Using Function Modifiers
In some cases you may need to translate the function differently or even insert additional function calls above or below the function being translated. The JDBC translator provides an abstract class
FunctionModifier
for this purpose.
During the start method a modifier instance can be registered against a given function name via a call to
JDBCExecutionFactory.registerFunctionModifier
.
The FunctionModifier has a method called
translate
. Use the translate method to change the way the function is represented.
An example of overriding the translate method to change the MOD(a, b) function into an infix operator for Sybase (a % b). The translate method returns a list of strings and language objects that will be assembled by the translator into a final string. The strings will be used as is and the language objects will be further processed by the translator.
In addition to building your own FunctionModifiers, there are a number of pre-built generic function modifiers that are provided with the translator.
Modifier
|
Description
|
---|---|
AliasModifier
|
Handles renaming a function ("ucase" to "upper" for example)
|
EscapeSyntaxModifier
|
Wraps a function in the standard JDBC escape syntax for functions: {fn xxxx()}
|
To register the function modifiers for your supported functions, you must call the
ExecutionFactory.registerFunctionModifier(String name, FunctionModifier modifier)
method.
Support for the two functions being registered ("abs" and "concat") must be declared in the capabilities as well. Functions that do not have modifiers registered will be translated as usual.