Package com.tangosol.coherence.dslquery
Class CoherenceQueryLanguage
java.lang.Object
com.tangosol.coherence.dslquery.CoherenceQueryLanguage
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 Summary
Modifier and TypeFieldDescriptionprotected ExtractorBuilder
TheExtractorBuilder
that will be used to realizeValueExtractor
s to be used by CohQL.protected Map
<String, ParameterizedBuilder<?>> The map of CohQL functions.protected Map
<CharSequence, BaseOperator> The map of CohQL operators.protected Map
<String, StatementBuilder<?>> The map of CohQL query builders.protected TokenTable
The extended TokenTable for the full language that resembles SQL.protected TokenTable
The TokenTable for Filters.protected TokenTable
The TokenTable for the full language that resembles SQL. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addFunction
(String sName, ParameterizedBuilder bldrFunction) Map the specified CohQLParameterizedBuilder
to the specified function name.void
addOperator
(BaseOperator operator) Add the custom operator to the CohQL language.void
addStatement
(String sFunctor, StatementBuilder<?> builder) Register the givenStatementBuilder
to the specified functor name.void
Remove all custom function mappings that have been registered.void
Remove all customisations that have been added to the CohQL language.protected Map
<String, StatementBuilder<?>> Create the CohQLStatementBuilder
map and initialise it with the standard CohQL statements.Return an initialized TokenTable for the full CoherenceQueryLanguage.Return an initialized standardTokenTable
known by this CoherenceQueryLanguage.Return theExtractorBuilder
to use to buildValueExtractor
s.getFunction
(String sName) Return the function mapped to the given function name or null if no function mapping exists.protected String
getFunctionKey
(String sFunctionName) Returns a key value based on case-insensitivity of the token table.getOperator
(String sSymbol) Return theBaseOperator
mapped to the given symbol.Return the set of CohQL Operators characters.protected TokenTable
getSqlTokenTable
(boolean fExtended) Return an initialized TokenTable for the full CoherenceQueryLanguage.getStatementBuilder
(String sFunctor) Return theStatementBuilder
for a given CohQL AST functor.Return the map ofStatementBuilder
instances.protected Map
<String, ParameterizedBuilder<?>> Creates the Map holding CohQL functions and populates it with the default functions available in CohQL.protected Map
<CharSequence, BaseOperator> Initialize the CohQL operators Map with all of the built-in CohQL operators and return the Map.prepareStatement
(NodeTerm term, ExecutionContext context, List listBindVars, ParameterResolver namedBindVars) Realize an instance of theStatement
that will execute the CohQL statement represented by the AST node.removeFunction
(String sName) Remove the CohQL function mapping for the specified function name.removeStatementBuilder
(String sFunctor) Remove theStatementBuilder
associated with the given functor.void
setExtractorBuilder
(ExtractorBuilder builder) Set theExtractorBuilder
that will be used by CohQL queries to buildValueExtractor
s.Return an initialized extendedTokenTable
known by this CoherenceQueryLanguage.
-
Field Details
-
m_tokenTableForFilter
The TokenTable for Filters. -
m_tokenTableSQL
The TokenTable for the full language that resembles SQL. -
m_tokenTableExtendedSQL
The extended TokenTable for the full language that resembles SQL. -
m_mapFunctions
The map of CohQL functions. The key is the function name and the value is the function implementation. -
m_mapOperators
The map of CohQL operators. The key is the operator name and the value is theBaseOperator
implementation. -
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
TheExtractorBuilder
that will be used to realizeValueExtractor
s to be used by CohQL.
-
-
Constructor Details
-
CoherenceQueryLanguage
public CoherenceQueryLanguage()Construct a CoherenceQueryLanguage instance.
-
-
Method Details
-
filtersTokenTable
Return an initialized standardTokenTable
known by this CoherenceQueryLanguage.- Returns:
- an initialized standard TokenTable known by this CoherenceQueryLanguage
-
sqlTokenTable
Return an initialized extendedTokenTable
known by this CoherenceQueryLanguage.- Returns:
- an initialized extended TokenTable known by this CoherenceQueryLanguage
-
extendedSqlTokenTable
Return an initialized TokenTable for the full CoherenceQueryLanguage.- Returns:
- a TokenTable for the CoherenceQueryLanguage
-
getSqlTokenTable
Return an initialized TokenTable for the full CoherenceQueryLanguage.- Parameters:
fExtended
- flag that enables extended and experimental features- Returns:
- a TokenTable for the CoherenceQueryLanguage
-
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
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
Map the specified CohQLParameterizedBuilder
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 functionbldrFunction
- the implementation of the function
-
removeFunction
Remove the CohQL function mapping for the specified function name. The removedParameterizedBuilder
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
Initialize the CohQL operators Map with all of the built-in CohQL operators and return the Map.- Returns:
- the Map of CohQL operators
-
addOperator
Add the custom operator to the CohQL language.- Parameters:
operator
- the operator to add
-
getOperators
Return the set of CohQL Operators characters.- Returns:
- the set of CohQL operators characters
-
getOperator
Return theBaseOperator
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
Return the map ofStatementBuilder
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
Create the CohQLStatementBuilder
map and initialise it with the standard CohQL statements.- Returns:
- the standard CohQL statement map
-
getStatementBuilder
Return theStatementBuilder
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 theStatement
that will execute the CohQL statement represented by the AST node.- Parameters:
term
- the parsed AST node representing the CohQL statementcontext
- theExecutionContext
to use to realize the commandlistBindVars
- the indexed bind variables to use for the querynamedBindVars
- 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
Register the givenStatementBuilder
to the specified functor name. The specified StatementBuilder will then be used to build anyStatement
instances when the given functor is present in a query AST.- Parameters:
sFunctor
- the functor to map the StatementBuilder tobuilder
- the StatementBuilder to be mapped
-
removeStatementBuilder
Remove theStatementBuilder
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
Set theExtractorBuilder
that will be used by CohQL queries to buildValueExtractor
s.- Parameters:
builder
- the ExtractorBuilder to use
-
getExtractorBuilder
Return theExtractorBuilder
to use to buildValueExtractor
s.- Returns:
- the ExtractorBuilder to use to build ValueExtractors
-
getFunctionKey
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
-