skip to main content
Designing and coding the IP : User defined scalar functions : Registering user defined scalar functions : In an IP developed in Java
 

In an IP developed in Java

To register user defined scalar functions In an IP developed in Java:
1. Implement the optional method ipGetScalarFunction as part of the IP class. Refer to "ipGetScalarFunction" in the OpenAccess SDK SQL Engine Programmer’s Reference for Java for information on using this method.
2. In the ipGetScalarFunctions method, create an array of type scalar_function and set one item for each scalar function you have defined.
/* Register it */
public scalar_function[] ipGetScalarFunctions()
{
scalar_function[] MyFuncs = new scalar_function[3];
MyFuncs[0] = new scalar_function("INTVAL",1,"ip_func_intval",XO_TYPE_INTEGER,1);
return MyFuncs;
}
 
/* Implementation of INTVAL scalar function
* out = INTVAL(a) – out is returned same as the input value.
*/
public long ip_func_intval(long hstmt,long pMemTree,long hValExpList)
{
long hVal;
long hValExp;
xo_int piRetCode = new xo_int(0);
Integer iObj;
/* get the input */
hValExp = jdam.dam_getFirstValExp(hValExpList);
iObj = (Integer) jdam.dam_getValueOfExp(pMemTree, hValExpList, hValExp,
XO_TYPE_INTEGER, piRetCode);
if(piRetCode.getVal() != DAM_SUCCESS)
return 0;
if(iObj == null)
{
hVal = jdam.dam_createVal(pMemTree, XO_TYPE_INTEGER, null, XO_NULL_DATA);
return hVal;
}
hVal = jdam.dam_createVal(pMemTree, XO_TYPE_INTEGER, iObj, 0);
return hVal;
}
3. Optionally, in the ipGetScalarFunctions method, create an array of type scalar_function and set one item for each scalar function with a qualifier that you have defined.
/* Register it */
public scalar_function[] ipGetScalarFunctions()
{
scalar_function[] MyFuncs = new scalar_function[2];
MyFuncs[0] = new scalar_function("INTEGER", "ADD", 1, "ip_func_Integer_add",
XO_TYPE_INTEGER, 1);
MyFuncs[1] = new scalar_function("STRING", "ADD", 1, "ip_func_String_add",
XO_TYPE_VARCHAR, 1);
return MyFuncs;
}