public void loadFunctions ( CatalogContext catalogContext ) { final CatalogMap < Function > catalogFunctions = catalogContext . database . getFunctions ( ) ; // Remove obsolete tokens for ( UserDefinedFunctionRunner runner : m_udfs . values ( ) ) { // The function that the current UserDefinedFunctionRunner is referring to // does not exist in the catalog anymore, we need to remove its token. if ( catalogFunctions . get ( runner . m_functionName ) == null ) { FunctionForVoltDB . deregisterUserDefinedFunction ( runner . m_functionName ) ; } } // Build new UDF runners ImmutableMap . Builder < Integer , UserDefinedFunctionRunner > builder = ImmutableMap . < Integer , UserDefinedFunctionRunner > builder ( ) ; for ( final Function catalogFunction : catalogFunctions ) { final String className = catalogFunction . getClassname ( ) ; Class < ? > funcClass = null ; try { funcClass = catalogContext . classForProcedureOrUDF ( className ) ; } catch ( final ClassNotFoundException e ) { if ( className . startsWith ( "org.voltdb." ) ) { String msg = String . format ( ORGVOLTDB_FUNCCNAME_ERROR_FMT , className ) ; VoltDB . crashLocalVoltDB ( msg , false , null ) ; } else { String msg = String . format ( UNABLETOLOAD_ERROR_FMT , className ) ; VoltDB . crashLocalVoltDB ( msg , false , null ) ; } } Object funcInstance = null ; try { funcInstance = funcClass . newInstance ( ) ; } catch ( InstantiationException | IllegalAccessException e ) { throw new RuntimeException ( String . format ( "Error instantiating function \"%s\"" , className ) , e ) ; } assert ( funcInstance != null ) ; builder . put ( catalogFunction . getFunctionid ( ) , new UserDefinedFunctionRunner ( catalogFunction , funcInstance ) ) ; } loadBuiltInJavaFunctions ( builder ) ; m_udfs = builder . build ( ) ; }
Load all the UDFs recorded in the catalog . Instantiate and register them in the system .