Class Function


  • public class Function
    extends Object
    Methods to look up a PL/Java function and prepare it for invocation.

    This class contains, mostly, logic that was originally in Function.c and has been ported to Java for better maintainability and adaptability. Many methods here have similar or identical names to the C functions they replace.

    When a PL/Java function is called, the C call handler will call the C Function_getFunction, which will delegate to Function_create if the function has not already been called. That C function calls the create method here, which ultimately (after all parsing of the CREATE FUNCTION ... AS ... information, matching up of parameter and return types, etc.) will return an Invocable to use when invoking the function.

    This remains a hybrid approach, in which PL/Java's legacy C Type infrastructure is used for converting the parameter and return values, and a C Function_ structure kept in a C hash table holds the details needed for invocation, including the Invocable created here. The methods in this class also use some JNI calls to contribute and retrieve additional details that belong in the C structure.

    The Invocable returned here by create will have return type Object in all cases, and no formal parameters. It can contain bound references to the static s_referenceParameters and s_primitiveParameters declared in this class, and will fetch the parameters from there (where invocation code in Function.c will have put them) at the time of invocation. The parameter areas are static, but invocation takes place only on the PG thread, and the method handles created here will have fetched all of the values to push on the stack before the (potentially reentrant) target method is invoked. If the method has a primitive return type, its return value will be placed in the first slot of s_primitiveParameters and the Invocable returns null. Naturally, the (potentially reentrant) target method has already returned before that value is placed in the static slot.

    • Method Summary

      Modifier and Type Method Description
      static org.postgresql.pljava.internal.EntryPoints.Invocable<?> create​(long wrappedPtr, ResultSet procTup, String langName, String schemaName, boolean trusted, boolean calledAsTrigger, boolean forValidator, boolean checkBody)
      Parse the function specification in procTup, initializing most fields of the C Function structure, and returning an Invocable for invoking the method, or null in the case of a UDT.
      static Class<? extends SQLData> getClassIfUDT​(ResultSet procTup, String schemaName)
      Return null if the prosrc field in the provided procTup does not have the form of a UDT specification; if it does, return the associated class, loaded with the class loader for schemaName.
    • Method Detail

      • getClassIfUDT

        public static Class<? extends SQLData> getClassIfUDT​(ResultSet procTup,
                                                             String schemaName)
                                                      throws SQLException
        Return null if the prosrc field in the provided procTup does not have the form of a UDT specification; if it does, return the associated class, loaded with the class loader for schemaName.
        Throws:
        SQLException
      • create

        public static org.postgresql.pljava.internal.EntryPoints.Invocable<?> create​(long wrappedPtr,
                                                                                     ResultSet procTup,
                                                                                     String langName,
                                                                                     String schemaName,
                                                                                     boolean trusted,
                                                                                     boolean calledAsTrigger,
                                                                                     boolean forValidator,
                                                                                     boolean checkBody)
                                                                              throws SQLException
        Parse the function specification in procTup, initializing most fields of the C Function structure, and returning an Invocable for invoking the method, or null in the case of a UDT.
        Throws:
        SQLException