Class CoherenceQueryLanguage

java.lang.Object
com.tangosol.coherence.dslquery.CoherenceQueryLanguage

public class CoherenceQueryLanguage extends Object
CoherenceQueryLanguage is a simple language for building Filters and doing simple queries that are similar in style to SQL. This class configures CohQL and contains various attributes that control CohQL execution.
Author:
djl 2009.08.31, jk 2013.12.02
  • Field Details

    • m_tokenTableForFilter

      protected TokenTable m_tokenTableForFilter
      The TokenTable for Filters.
    • m_tokenTableSQL

      protected TokenTable m_tokenTableSQL
      The TokenTable for the full language that resembles SQL.
    • m_tokenTableExtendedSQL

      protected TokenTable m_tokenTableExtendedSQL
      The extended TokenTable for the full language that resembles SQL.
    • m_mapFunctions

      protected Map<String,ParameterizedBuilder<?>> m_mapFunctions
      The map of CohQL functions. The key is the function name and the value is the function implementation.
    • m_mapOperators

      protected Map<CharSequence,BaseOperator> m_mapOperators
      The map of CohQL operators. The key is the operator name and the value is the BaseOperator implementation.
    • m_mapStatementBuilders

      protected Map<String,StatementBuilder<?>> m_mapStatementBuilders
      The map of CohQL query builders. The key is the CohQL token name that the parser produces to represent a particular query.
    • m_bldrExtractor

      protected ExtractorBuilder m_bldrExtractor
      The ExtractorBuilder that will be used to realize ValueExtractors to be used by CohQL.
  • Constructor Details

    • CoherenceQueryLanguage

      public CoherenceQueryLanguage()
      Construct a CoherenceQueryLanguage instance.
  • Method Details

    • filtersTokenTable

      public TokenTable filtersTokenTable()
      Return an initialized standard TokenTable known by this CoherenceQueryLanguage.
      Returns:
      an initialized standard TokenTable known by this CoherenceQueryLanguage
    • sqlTokenTable

      public TokenTable sqlTokenTable()
      Return an initialized extended TokenTable known by this CoherenceQueryLanguage.
      Returns:
      an initialized extended TokenTable known by this CoherenceQueryLanguage
    • extendedSqlTokenTable

      public TokenTable extendedSqlTokenTable()
      Return an initialized TokenTable for the full CoherenceQueryLanguage.
      Returns:
      a TokenTable for the CoherenceQueryLanguage
    • getSqlTokenTable

      protected TokenTable getSqlTokenTable(boolean fExtended)
      Return an initialized TokenTable for the full CoherenceQueryLanguage.
      Parameters:
      fExtended - flag that enables extended and experimental features
      Returns:
      a TokenTable for the CoherenceQueryLanguage
    • initializeFunctionMap

      protected Map<String,ParameterizedBuilder<?>> initializeFunctionMap()
      Creates the Map holding CohQL functions and populates it with the default functions available in CohQL. CohQL functions are elements such as sum(), avg(), max() etc.
      Returns:
      the function Map populated with the default functions
    • getFunction

      public ParameterizedBuilder getFunction(String sName)
      Return the function mapped to the given function name or null if no function mapping exists.
      Parameters:
      sName - the name of the function to return
      Returns:
      the function mapped to the given function name or null if no function mapping exists
    • addFunction

      public void addFunction(String sName, ParameterizedBuilder bldrFunction)
      Map the specified CohQL ParameterizedBuilder to the specified function name. If either the name of the implementation is null then no mapping will occur.
      Parameters:
      sName - the name of the function
      bldrFunction - the implementation of the function
    • removeFunction

      public ParameterizedBuilder<?> removeFunction(String sName)
      Remove the CohQL function mapping for the specified function name. The removed ParameterizedBuilder will be returned, or null if there was no mapping for the specified name.
      Parameters:
      sName - the name of the function to remove
      Returns:
      the removed ParameterizedBuilder will be returned, or null if there was no mapping for the specified name.
    • clearCustomFunctions

      public void clearCustomFunctions()
      Remove all custom function mappings that have been registered.
    • initializeOperatorMap

      protected Map<CharSequence,BaseOperator> initializeOperatorMap()
      Initialize the CohQL operators Map with all of the built-in CohQL operators and return the Map.
      Returns:
      the Map of CohQL operators
    • addOperator

      public void addOperator(BaseOperator operator)
      Add the custom operator to the CohQL language.
      Parameters:
      operator - the operator to add
    • getOperators

      public Set<CharSequence> getOperators()
      Return the set of CohQL Operators characters.
      Returns:
      the set of CohQL operators characters
    • getOperator

      public BaseOperator getOperator(String sSymbol)
      Return the BaseOperator mapped to the given symbol.
      Parameters:
      sSymbol - the symbol of the BaseOperator to get
      Returns:
      the BaseOperator mapped to the specified symbol or null if there i sno mapping for that symbol
    • getStatementBuilders

      public Map<String,StatementBuilder<?>> getStatementBuilders()
      Return the map of StatementBuilder instances. The map is keyed on the functor used to represent a particular query type in a CohQL AST.
      Returns:
      the map of StatementBuilder instances
    • createStatements

      protected Map<String,StatementBuilder<?>> createStatements()
      Create the CohQL StatementBuilder map and initialise it with the standard CohQL statements.
      Returns:
      the standard CohQL statement map
    • getStatementBuilder

      public StatementBuilder<?> getStatementBuilder(String sFunctor)
      Return the StatementBuilder for a given CohQL AST functor. The returned value may be null if no builder has been registered for a given functor.
      Parameters:
      sFunctor - the functor representing the statement who's builder should be returned
      Returns:
      the StatementBuilder for a given CohQL AST functor
    • prepareStatement

      public Statement prepareStatement(NodeTerm term, ExecutionContext context, List listBindVars, ParameterResolver namedBindVars)
      Realize an instance of the Statement that will execute the CohQL statement represented by the AST node.
      Parameters:
      term - the parsed AST node representing the CohQL statement
      context - the ExecutionContext to use to realize the command
      listBindVars - the indexed bind variables to use for the query
      namedBindVars - the named bind variables to use for the query
      Returns:
      the Statement to execute the CohQL statement
      Throws:
      CohQLException - if there is an error building the statement or there are no registered builders for the statement
    • addStatement

      public void addStatement(String sFunctor, StatementBuilder<?> builder)
      Register the given StatementBuilder to the specified functor name. The specified StatementBuilder will then be used to build any Statement instances when the given functor is present in a query AST.
      Parameters:
      sFunctor - the functor to map the StatementBuilder to
      builder - the StatementBuilder to be mapped
    • removeStatementBuilder

      public StatementBuilder<?> removeStatementBuilder(String sFunctor)
      Remove the StatementBuilder associated with the given functor.

      Note: removal of a functor may cause errors if subsequent queries refer to the functor.

      Parameters:
      sFunctor - the functor mapping to remove
      Returns:
      the removed StatementBuilder or null
    • clearCustomOperators

      public void clearCustomOperators()
      Remove all customisations that have been added to the CohQL language.
    • setExtractorBuilder

      public void setExtractorBuilder(ExtractorBuilder builder)
      Set the ExtractorBuilder that will be used by CohQL queries to build ValueExtractors.
      Parameters:
      builder - the ExtractorBuilder to use
    • getExtractorBuilder

      public ExtractorBuilder getExtractorBuilder()
      Return the ExtractorBuilder to use to build ValueExtractors.
      Returns:
      the ExtractorBuilder to use to build ValueExtractors
    • getFunctionKey

      protected String getFunctionKey(String sFunctionName)
      Returns a key value based on case-insensitivity of the token table.
      Parameters:
      sFunctionName - the function name to create a key for
      Returns:
      a key value based on case-insensitivity of the token table
      Since:
      21.06