Class ProcedureManager


  • public class ProcedureManager
    extends java.lang.Object
    A DatabaseConnection procedure manager. This controls adding, updating, deleting and querying/calling stored procedures.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  ProcedureManager.ProcedureInternalTableInfo
      An object that models the list of procedures as table objects in a transaction.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static InternalTableInfo createInternalTableInfo​(Transaction transaction)
      Returns an InternalTableInfo object used to model the list of procedures that are accessible within the given Transaction object.
      void defineJavaProcedure​(ProcedureName procedure_name, java.lang.String java_specification, TType return_type, TType[] param_types, java.lang.String username)
      Defines a Java stored procedure.
      void deleteProcedure​(ProcedureName procedure_name)
      Deletes the procedure with the given name, or generates an error if the procedure doesn't exist.
      private Table findProcedureEntry​(DataTable table, ProcedureName procedure_name)
      Given the SYS_FUNCTION table, this returns a new table that contains the entry with the given procedure name, or an empty result if nothing found.
      private TObject invokeJavaV1Procedure​(ProcedureName procedure_name, java.lang.String location_str, TType return_type, TType[] param_types, java.lang.String owner, TObject[] param_values)
      Invokes a Java (type 1) procedure.
      TObject invokeProcedure​(ProcedureName procedure_name, TObject[] params)
      Invokes the procedure with the given name and the given parameters and returns the procedure return value.
      static java.lang.reflect.Method javaProcedureMethod​(java.lang.String location_str, TType[] param_types)
      Given a Java location_str and a list of parameter types, returns an immutable 'Method' object that can be used to invoke a Java stored procedure.
      static java.lang.String[] parseJavaLocationString​(java.lang.String str)
      Given a location string as defined for a Java stored procedure, this parses the string into the various parts.
      boolean procedureExists​(ProcedureName procedure_name)
      Returns true if the procedure with the given name exists.
      boolean procedureExists​(TableName procedure_name)
      Returns true if the procedure with the given table name exists.
      private static java.lang.String procedureInfoString​(ProcedureName name, TType ret, TType[] params)
      Formats a string that gives information about the procedure, return type and param types.
      private static java.lang.Class resolveToClass​(java.lang.String java_spec)
      Resolves a Java class specification string to a Java Class object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ProcedureManager

        ProcedureManager​(DatabaseConnection connection)
        Constructs the ProcedureManager for a DatabaseConnection.
    • Method Detail

      • findProcedureEntry

        private Table findProcedureEntry​(DataTable table,
                                         ProcedureName procedure_name)
        Given the SYS_FUNCTION table, this returns a new table that contains the entry with the given procedure name, or an empty result if nothing found. Generates an error if more than 1 entry found.
      • procedureInfoString

        private static java.lang.String procedureInfoString​(ProcedureName name,
                                                            TType ret,
                                                            TType[] params)
        Formats a string that gives information about the procedure, return type and param types.
      • parseJavaLocationString

        public static java.lang.String[] parseJavaLocationString​(java.lang.String str)
        Given a location string as defined for a Java stored procedure, this parses the string into the various parts. For example, given the string 'com.mycompany.storedprocedures.MyFunctions.minFunction()' this will parse the string out to the class called 'com.mycompany.storedprocedures.MyFunctions' and the method 'minFunction' with no arguments. This function will work event if the method name is not given, or the method name does not have an arguments specification.
      • procedureExists

        public boolean procedureExists​(ProcedureName procedure_name)
        Returns true if the procedure with the given name exists.
      • procedureExists

        public boolean procedureExists​(TableName procedure_name)
        Returns true if the procedure with the given table name exists.
      • defineJavaProcedure

        public void defineJavaProcedure​(ProcedureName procedure_name,
                                        java.lang.String java_specification,
                                        TType return_type,
                                        TType[] param_types,
                                        java.lang.String username)
                                 throws DatabaseException
        Defines a Java stored procedure. If the procedure with the name has not been defined it is defined. If the procedure has been defined then it is overwritten with this information.

        If 'return_type' is null then the procedure does not return a value.

        Throws:
        DatabaseException
      • createInternalTableInfo

        static InternalTableInfo createInternalTableInfo​(Transaction transaction)
        Returns an InternalTableInfo object used to model the list of procedures that are accessible within the given Transaction object. This is used to model all procedures that have been defined as tables.
      • invokeProcedure

        public TObject invokeProcedure​(ProcedureName procedure_name,
                                       TObject[] params)
        Invokes the procedure with the given name and the given parameters and returns the procedure return value.
      • resolveToClass

        private static java.lang.Class resolveToClass​(java.lang.String java_spec)
        Resolves a Java class specification string to a Java Class object. For example, "String" becomes 'java.lang.String.class' and "boolean[]" becomes 'boolean[].class', etc.
      • javaProcedureMethod

        public static java.lang.reflect.Method javaProcedureMethod​(java.lang.String location_str,
                                                                   TType[] param_types)
        Given a Java location_str and a list of parameter types, returns an immutable 'Method' object that can be used to invoke a Java stored procedure. The returned object can be cached if necessary. Note that this method will generate an error for the following situations: a) The invokation class or method was not found, b) there is not an invokation method with the required number of arguments or that matches the method specification.

        Returns null if the invokation method could not be found.

      • invokeJavaV1Procedure

        private TObject invokeJavaV1Procedure​(ProcedureName procedure_name,
                                              java.lang.String location_str,
                                              TType return_type,
                                              TType[] param_types,
                                              java.lang.String owner,
                                              TObject[] param_values)
        Invokes a Java (type 1) procedure. A type 1 procedure is represented by a single class with a static invokation method (called invoke). The parameters of the static 'invoke' method must be compatible class parameters defined for the procedure, and the return class must also be compatible with the procedure return type.

        If the invoke method does not contain arguments that are compatible with the parameters given an exception is generated.

        The class must only have a single public static 'invoke' method. If there are multiple 'invoke' methods a runtime exception is generated.