Show Table of Contents
4.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.
public class ModFunctionModifier extends FunctionModifier
{
public List translate(Function function)
{
List parts = new ArrayList();
parts.add("(");
Expression[] args = function.getParameters().toArray(new Expression[0]);
parts.add(args[0]);
parts.add(" % ");
parts.add(args[1]);
parts.add(")");
return parts;
}
}
In addition to building your own FunctionModifiers, there are a number of pre-built generic function modifiers that are provided with the translator.
Table 4.2. Common Modifiers
|
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.
public class ExtendedJDBCExecutionFactory extends JDBCExecutionFactory
{
@Override
public void start()
{
super.start();
// register functions.
registerFunctionModifier("abs", new MyAbsModifier());
registerFunctionModifier("concat", new AliasModifier("concat2"));
}
}
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.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.