Class FunctionFactory

  • All Implemented Interfaces:
    FunctionLookup

    public abstract class FunctionFactory
    extends java.lang.Object
    implements FunctionLookup
    A factory that generates Function objects given a function name and a set of expression's that represent parameters. A developer may create their own instance of this class and register the factory with the DatabaseSystem. When the SQL grammer comes across a function, it will try and resolve the function name against the registered function factories.
    Author:
    Tobias Downer
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected class  FunctionFactory.FF_FunctionInfo
      An implementation of FunctionInfo.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Expression[] GLOB_LIST
      Represents a function argument * for glob's such as 'count(*)'
    • Constructor Summary

      Constructors 
      Constructor Description
      FunctionFactory()
      Constructs the FunctionFactory.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addFunction​(java.lang.String fun_name, java.lang.Class fun_class)
      Adds a new static function to this factory.
      protected void addFunction​(java.lang.String fun_name, java.lang.Class fun_class, int fun_type)
      Adds a new function to this factory.
      protected boolean functionDefined​(java.lang.String fun_name)
      Returns true if the function name is defined in this factory.
      Function generateFunction​(FunctionDef function_def)
      Creates a Function object for the function with the given name with the given arguments.
      FunctionInfo[] getAllFunctionInfo()
      Returns the list of all function names that this FunctionFactory manages.
      FunctionInfo getFunctionInfo​(java.lang.String fun_name)
      Returns a FunctionInfo instance of the function with the given name that this FunctionFactory manages.
      abstract void init()
      Initializes this FunctionFactory.
      boolean isAggregate​(FunctionDef function_def)
      Returns true if the function defined by FunctionDef is an aggregate function, or false otherwise.
      protected void removeFunction​(java.lang.String fun_name)
      Removes a static function from this factory.
      • Methods inherited from class java.lang.Object

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

      • GLOB_LIST

        public static final Expression[] GLOB_LIST
        Represents a function argument * for glob's such as 'count(*)'
    • Constructor Detail

      • FunctionFactory

        public FunctionFactory()
        Constructs the FunctionFactory.
    • Method Detail

      • addFunction

        protected void addFunction​(java.lang.String fun_name,
                                   java.lang.Class fun_class,
                                   int fun_type)
        Adds a new function to this factory. Takes a function name and a class that is the Function implementation. When the 'generateFunction' method is called, it looks up the class with the function name and returns a new instance of the function.

        Parameters:
        fun_name - the name of the function (eg. 'sum', 'concat').
        fun_class - the Function class that we instantiate for this function.
        fun_type - that type of function (either FunctionInfo.STATIC, FunctionInfo.AGGREGATE, FunctionInfo.STATE_BASED).
      • addFunction

        protected void addFunction​(java.lang.String fun_name,
                                   java.lang.Class fun_class)
        Adds a new static function to this factory.
      • removeFunction

        protected void removeFunction​(java.lang.String fun_name)
        Removes a static function from this factory.
      • functionDefined

        protected boolean functionDefined​(java.lang.String fun_name)
        Returns true if the function name is defined in this factory.
      • init

        public abstract void init()
        Initializes this FunctionFactory. This is an abstract method that needs to be implemented. (It doesn't need to do anything if a developer implements their own version of 'generateFunction').
      • generateFunction

        public Function generateFunction​(FunctionDef function_def)
        Creates a Function object for the function with the given name with the given arguments. If this factory does not handle a function with the given name then it returns null.
        Specified by:
        generateFunction in interface FunctionLookup
      • isAggregate

        public boolean isAggregate​(FunctionDef function_def)
        Returns true if the function defined by FunctionDef is an aggregate function, or false otherwise.
        Specified by:
        isAggregate in interface FunctionLookup
      • getFunctionInfo

        public FunctionInfo getFunctionInfo​(java.lang.String fun_name)
        Returns a FunctionInfo instance of the function with the given name that this FunctionFactory manages. If 'generateFunction' is reimplemented then this method should be rewritten also.
      • getAllFunctionInfo

        public FunctionInfo[] getAllFunctionInfo()
        Returns the list of all function names that this FunctionFactory manages. This is used to compile information about the function factories. If 'generateFunction' is reimplemented then this method should be rewritten also.