此内容没有您所选择的语言版本。

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.
public class ModFunctionModifier implements FunctionModifier 
{
   public List translate(Function function) 
   {
      List parts = new ArrayList();
      parts.add("(");        
      Expression[] args = function.getParameters();
      parts.add(args[0]);
      parts.add(" % "); 
      parts.add(args[1]);
      parts.add(")");    
      return parts;
   }
}
Copy to Clipboard Toggle word wrap
In addition to building your own FunctionModifiers, there are a number of pre-built generic function modifiers that are provided with the translator.
Expand
Table 7.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")); 
   }
}
Copy to Clipboard Toggle word wrap
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.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat