Red Hat Training

A Red Hat training course is available for Red Hat JBoss Data Virtualization

7.5. Adding Function Support

Refer to the section on user defined functions for adding new functions to JBoss Data Virtualization. This example will show you how to declare support for the function and modify how the function is passed to the data source.
Following is a summary of all coding steps in supporting a new scalar function:
  1. Override the capabilities method to declare support for the function (REQUIRED)
  2. Implement a FunctionModifier to change how a function is translated and register it for use (OPTIONAL)
There is a capabilities method getSupportedFunctions() that declares all supported scalar functions.
An example of an extended capabilities class to add support for the "abs" absolute value function:
package my.connector;

import java.util.ArrayList;
import java.util.List;

public class ExtendedJDBCExecutionFactory extends JDBCExecutionFactory 
{
   @Override
   public List getSupportedFunctions() 
   {
      List supportedFunctions = new ArrayList();
      supportedFunctions.addAll(super.getSupportedFunctions());
      supportedFunctions.add("ABS"); 
      return supportedFunctions;
   }
}
In general, it is a good idea to call super.getSupportedFunctions() to ensure that you retain any function support provided by the translator you are extending.
This may be all that is needed to support a JBoss Data Virtualization function if the JDBC data source supports the same syntax as JBoss Data Virtualization. The built-in SQL translation will translate most functions as: "function(arg1, arg2, ...)".